88
99package it .near .sdk .reactnative .rnnearitsdk ;
1010
11+ import android .annotation .SuppressLint ;
1112import android .app .Activity ;
1213import android .content .BroadcastReceiver ;
1314import android .content .Context ;
3839import it .near .sdk .NearItManager ;
3940import it .near .sdk .communication .OptOutNotifier ;
4041import it .near .sdk .operation .NearItUserProfile ;
42+ import it .near .sdk .operation .values .NearMultipleChoiceDataPoint ;
4143import it .near .sdk .reactions .couponplugin .CouponListener ;
4244import it .near .sdk .reactions .couponplugin .model .Coupon ;
4345import it .near .sdk .reactions .feedbackplugin .FeedbackEvent ;
4446import it .near .sdk .reactions .feedbackplugin .model .Feedback ;
4547import it .near .sdk .recipes .NearITEventHandler ;
46- import it .near .sdk .recipes .RecipeRefreshListener ;
4748import it .near .sdk .recipes .foreground .ProximityListener ;
4849import it .near .sdk .recipes .models .Recipe ;
4950import it .near .sdk .trackings .TrackingInfo ;
@@ -60,6 +61,7 @@ public class RNNearItModule extends ReactContextBaseJavaModule implements Lifecy
6061 static final String NATIVE_EVENTS_TOPIC = "RNNearItEvent" ;
6162 private static final String NATIVE_PERMISSIONS_TOPIC = "RNNearItPermissions" ;
6263
64+ @ SuppressWarnings ("WeakerAccess" )
6365 // Local Events topic (used by LocalBroadcastReceiver to handle foreground notifications)
6466 static final String LOCAL_EVENTS_TOPIC = "RNNearItLocalEvents" ;
6567
@@ -93,7 +95,6 @@ public class RNNearItModule extends ReactContextBaseJavaModule implements Lifecy
9395 private static final String PERMISSION_LOCATION_DENIED = "NearIt.Permissions.Location.Denied" ;
9496
9597 // Error codes
96- private static final String E_REFRESH_CONFIG_ERROR = "E_REFRESH_CONFIG_ERROR" ;
9798 private static final String E_START_RADAR_ERROR = "E_START_RADAR_ERROR" ;
9899 private static final String E_STOP_RADAR_ERROR = "E_STOP_RADAR_ERROR" ;
99100 private static final String E_SEND_TRACKING_ERROR = "E_SEND_TRACKING_ERROR" ;
@@ -106,7 +107,7 @@ public class RNNearItModule extends ReactContextBaseJavaModule implements Lifecy
106107 private static final String E_COUPONS_RETRIEVAL_ERROR = "E_COUPONS_RETRIEVAL_ERROR" ;
107108 private static final String E_OPT_OUT_ERROR = "E_OPT_OUT_ERROR" ;
108109
109-
110+ @ SuppressWarnings ( "WeakerAccess" )
110111 public RNNearItModule (ReactApplicationContext reactContext ) {
111112 super (reactContext );
112113
@@ -174,8 +175,8 @@ private Map<String, Object> getEventContentConstants() {
174175 private Map <String , Object > getStatusConstants () {
175176 return Collections .unmodifiableMap (new HashMap <String , Object >() {
176177 {
177- put ("notified" , Recipe .NOTIFIED_STATUS );
178- put ("engaged" , Recipe .ENGAGED_STATUS );
178+ put ("notified" , Recipe .RECEIVED );
179+ put ("engaged" , Recipe .OPENED );
179180 }
180181 });
181182 }
@@ -191,6 +192,7 @@ private Map<String, Object> getPermissionStatusConstants() {
191192 });
192193 }
193194
195+ @ SuppressWarnings ("unused" )
194196 public static void onPostCreate (Context context , Intent intent ) {
195197 if (NearUtils .carriesNearItContent (intent )) {
196198 NearUtils .parseContents (intent , new RNNearItCoreContentsListener (context , null , true ));
@@ -227,6 +229,7 @@ public void onNewIntent(Intent intent) {
227229 }
228230
229231 // ReactNative listeners management
232+ @ SuppressWarnings ("unused" )
230233 @ ReactMethod
231234 public void listenerRegistered (final Promise promise ) {
232235 final int listenersCount = RNNearItPersistedQueue .defaultQueue ().registerListener ();
@@ -235,6 +238,7 @@ public void listenerRegistered(final Promise promise) {
235238 promise .resolve (true );
236239 }
237240
241+ @ SuppressWarnings ("unused" )
238242 @ ReactMethod
239243 public void listenerUnregistered (final Promise promise ) {
240244 final int listenersCount = RNNearItPersistedQueue .defaultQueue ().unregisterListener ();
@@ -248,23 +252,9 @@ public void foregroundEvent(Parcelable parcelable, TrackingInfo trackingInfo) {
248252 NearUtils .parseContents (parcelable , trackingInfo , new RNNearItCoreContentsListener (getReactApplicationContext (), getRCTDeviceEventEmitter (), false ));
249253 }
250254
251- // NearIT Config
252- @ ReactMethod
253- public void refreshConfig (final Promise promise ) {
254- NearItManager .getInstance ().refreshConfigs (new RecipeRefreshListener () {
255- @ Override
256- public void onRecipesRefresh () {
257- promise .resolve (null );
258- }
259-
260- @ Override
261- public void onRecipesRefreshFail () {
262- promise .reject (E_REFRESH_CONFIG_ERROR , "refreshConfig failed" );
263- }
264- });
265- }
266-
267255 // NearIT Radar
256+ @ SuppressWarnings ("unused" )
257+ @ SuppressLint ("MissingPermission" )
268258 @ ReactMethod
269259 public void startRadar (final Promise promise ) {
270260 try {
@@ -275,6 +265,7 @@ public void startRadar(final Promise promise) {
275265 }
276266 }
277267
268+ @ SuppressWarnings ("unused" )
278269 @ ReactMethod
279270 public void stopRadar (final Promise promise ) {
280271 try {
@@ -286,6 +277,7 @@ public void stopRadar(final Promise promise) {
286277 }
287278
288279 // NearIT Trackings
280+ @ SuppressWarnings ("unused" )
289281 @ ReactMethod
290282 public void sendTracking (final String trackinInfoData , final String status , final Promise promise ) {
291283 try {
@@ -299,6 +291,7 @@ public void sendTracking(final String trackinInfoData, final String status, fina
299291 }
300292
301293 // NearIT Feedback
294+ @ SuppressWarnings ("unused" )
302295 @ ReactMethod
303296 public void sendFeedback (final String feedbackB64 , final int rating , final String comment , final Promise promise ) {
304297 final Feedback feedback ;
@@ -322,6 +315,7 @@ public void onFail(int errorCode, String errorMessage) {
322315 }
323316
324317 // NearIT UserProfiling
318+ @ SuppressWarnings ("unused" )
325319 @ ReactMethod
326320 public void getUserProfileId (final Promise promise ) {
327321 NearItManager .getInstance ().getProfileId (new NearItUserProfile .ProfileFetchListener () {
@@ -337,6 +331,7 @@ public void onError(String error) {
337331 });
338332 }
339333
334+ @ SuppressWarnings ("unused" )
340335 @ ReactMethod
341336 public void setUserProfileId (final String profileId , final Promise promise ) {
342337 try {
@@ -347,6 +342,7 @@ public void setUserProfileId(final String profileId, final Promise promise) {
347342 }
348343 }
349344
345+ @ SuppressWarnings ("unused" )
350346 @ ReactMethod
351347 public void resetUserProfile (final Promise promise ) {
352348 NearItManager .getInstance ().resetProfileId (new NearItUserProfile .ProfileFetchListener () {
@@ -362,6 +358,7 @@ public void onError(String error) {
362358 });
363359 }
364360
361+ @ SuppressWarnings ("unused" )
365362 @ ReactMethod
366363 public void setUserData (final ReadableMap userData , final Promise promise ) {
367364 try {
@@ -374,6 +371,44 @@ public void setUserData(final ReadableMap userData, final Promise promise) {
374371 }
375372 }
376373
374+ @ SuppressWarnings ("unused" )
375+ @ ReactMethod
376+ public void setUserData (final String key , final String value , final Promise promise ) {
377+ try {
378+ Log .d ("RNNearItModule" , "setting user data: " +key +", " +value );
379+ NearItManager .getInstance ().setUserData (key , value );
380+ promise .resolve (null );
381+ } catch (Exception e ) {
382+ promise .reject (E_USER_PROFILE_DATA_ERROR , "Error while setting userData" );
383+ }
384+ }
385+
386+ @ SuppressWarnings ("unused" )
387+ @ ReactMethod
388+ public void setMultiChoiceUserData (final String key , final ReadableMap userData , final Promise promise ) {
389+ try {
390+ NearMultipleChoiceDataPoint multiChoiceData = null ;
391+ HashMap <String , Boolean > data = new HashMap <>();
392+ if (userData != null ) {
393+ for (Map .Entry <String , Object > entry : userData .toHashMap ().entrySet ()) {
394+ if (entry .getValue () instanceof Boolean ){
395+ data .put (entry .getKey (), (Boolean ) entry .getValue ());
396+ }
397+ }
398+ }
399+ if (!data .isEmpty ()) {
400+ multiChoiceData = new NearMultipleChoiceDataPoint (data );
401+ }
402+
403+ Log .d ("RNNearItModule" , "setting user data: " +key +", " +data );
404+ NearItManager .getInstance ().setUserData (key , multiChoiceData );
405+ promise .resolve (null );
406+ } catch (Exception e ) {
407+ promise .reject (E_USER_PROFILE_DATA_ERROR , "Error while setting userData" );
408+ }
409+ }
410+
411+ @ SuppressWarnings ("unused" )
377412 @ ReactMethod
378413 public void optOut (final Promise promise ) {
379414 NearItManager .getInstance ().optOut (new OptOutNotifier () {
@@ -391,38 +426,43 @@ public void onFailure(String error) {
391426
392427 // NearIT Permissions request
393428
429+ @ SuppressWarnings ("unused" )
394430 @ ReactMethod
395431 public void checkNotificationPermission (final Promise promise ) {
396432 promise .resolve (true );
397433 }
398434
435+ @ SuppressWarnings ("unused" )
399436 @ ReactMethod
400437 public void requestNotificationPermission (final Promise promise ) {
401438 promise .resolve (true );
402439 }
403440
441+ @ SuppressWarnings ("unused" )
404442 @ ReactMethod
405443 public void checkLocationPermission (final Promise promise ) {
406444 promise .resolve (true );
407445 }
408446
447+ @ SuppressWarnings ("unused" )
409448 @ ReactMethod
410449 public void requestLocationPermission (final Promise promise ) {
411450 promise .resolve (true );
412451 }
413452
414453 // NearIT Custom Trigger
415454
455+ @ SuppressWarnings ("unused" )
416456 @ ReactMethod
417457 public void triggerEvent (final String eventKey , final Promise promise ) {
418458 // Trigger Custom Event Key
419- NearItManager .getInstance ().processCustomTrigger (eventKey );
459+ NearItManager .getInstance ().triggerInAppEvent (eventKey );
420460 // Resolve null, if a Recipe is triggered then the normal notification flow will run
421461 promise .resolve (null );
422462 }
423463
424464 // NearIT Coupons
425-
465+ @ SuppressWarnings ( "unused" )
426466 @ ReactMethod
427467 public void getCoupons (final Promise promise ) {
428468 NearItManager .getInstance ().getCoupons (new CouponListener () {
@@ -467,6 +507,7 @@ private DeviceEventManagerModule.RCTDeviceEventEmitter getRCTDeviceEventEmitter(
467507 .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class );
468508 }
469509
510+ @ SuppressWarnings ("unused" )
470511 private void sendEventWithLocationPermissionStatus (final String permissionStatus ) {
471512 try {
472513 // Create Event map to send to JS
0 commit comments