8
8
9
9
package it .near .sdk .reactnative .rnnearitsdk ;
10
10
11
+ import android .annotation .SuppressLint ;
11
12
import android .app .Activity ;
12
13
import android .content .BroadcastReceiver ;
13
14
import android .content .Context ;
38
39
import it .near .sdk .NearItManager ;
39
40
import it .near .sdk .communication .OptOutNotifier ;
40
41
import it .near .sdk .operation .NearItUserProfile ;
42
+ import it .near .sdk .operation .values .NearMultipleChoiceDataPoint ;
41
43
import it .near .sdk .reactions .couponplugin .CouponListener ;
42
44
import it .near .sdk .reactions .couponplugin .model .Coupon ;
43
45
import it .near .sdk .reactions .feedbackplugin .FeedbackEvent ;
44
46
import it .near .sdk .reactions .feedbackplugin .model .Feedback ;
45
47
import it .near .sdk .recipes .NearITEventHandler ;
46
- import it .near .sdk .recipes .RecipeRefreshListener ;
47
48
import it .near .sdk .recipes .foreground .ProximityListener ;
48
49
import it .near .sdk .recipes .models .Recipe ;
49
50
import it .near .sdk .trackings .TrackingInfo ;
@@ -60,6 +61,7 @@ public class RNNearItModule extends ReactContextBaseJavaModule implements Lifecy
60
61
static final String NATIVE_EVENTS_TOPIC = "RNNearItEvent" ;
61
62
private static final String NATIVE_PERMISSIONS_TOPIC = "RNNearItPermissions" ;
62
63
64
+ @ SuppressWarnings ("WeakerAccess" )
63
65
// Local Events topic (used by LocalBroadcastReceiver to handle foreground notifications)
64
66
static final String LOCAL_EVENTS_TOPIC = "RNNearItLocalEvents" ;
65
67
@@ -93,7 +95,6 @@ public class RNNearItModule extends ReactContextBaseJavaModule implements Lifecy
93
95
private static final String PERMISSION_LOCATION_DENIED = "NearIt.Permissions.Location.Denied" ;
94
96
95
97
// Error codes
96
- private static final String E_REFRESH_CONFIG_ERROR = "E_REFRESH_CONFIG_ERROR" ;
97
98
private static final String E_START_RADAR_ERROR = "E_START_RADAR_ERROR" ;
98
99
private static final String E_STOP_RADAR_ERROR = "E_STOP_RADAR_ERROR" ;
99
100
private static final String E_SEND_TRACKING_ERROR = "E_SEND_TRACKING_ERROR" ;
@@ -106,7 +107,7 @@ public class RNNearItModule extends ReactContextBaseJavaModule implements Lifecy
106
107
private static final String E_COUPONS_RETRIEVAL_ERROR = "E_COUPONS_RETRIEVAL_ERROR" ;
107
108
private static final String E_OPT_OUT_ERROR = "E_OPT_OUT_ERROR" ;
108
109
109
-
110
+ @ SuppressWarnings ( "WeakerAccess" )
110
111
public RNNearItModule (ReactApplicationContext reactContext ) {
111
112
super (reactContext );
112
113
@@ -174,8 +175,8 @@ private Map<String, Object> getEventContentConstants() {
174
175
private Map <String , Object > getStatusConstants () {
175
176
return Collections .unmodifiableMap (new HashMap <String , Object >() {
176
177
{
177
- put ("notified" , Recipe .NOTIFIED_STATUS );
178
- put ("engaged" , Recipe .ENGAGED_STATUS );
178
+ put ("notified" , Recipe .RECEIVED );
179
+ put ("engaged" , Recipe .OPENED );
179
180
}
180
181
});
181
182
}
@@ -191,6 +192,7 @@ private Map<String, Object> getPermissionStatusConstants() {
191
192
});
192
193
}
193
194
195
+ @ SuppressWarnings ("unused" )
194
196
public static void onPostCreate (Context context , Intent intent ) {
195
197
if (NearUtils .carriesNearItContent (intent )) {
196
198
NearUtils .parseContents (intent , new RNNearItCoreContentsListener (context , null , true ));
@@ -227,6 +229,7 @@ public void onNewIntent(Intent intent) {
227
229
}
228
230
229
231
// ReactNative listeners management
232
+ @ SuppressWarnings ("unused" )
230
233
@ ReactMethod
231
234
public void listenerRegistered (final Promise promise ) {
232
235
final int listenersCount = RNNearItPersistedQueue .defaultQueue ().registerListener ();
@@ -235,6 +238,7 @@ public void listenerRegistered(final Promise promise) {
235
238
promise .resolve (true );
236
239
}
237
240
241
+ @ SuppressWarnings ("unused" )
238
242
@ ReactMethod
239
243
public void listenerUnregistered (final Promise promise ) {
240
244
final int listenersCount = RNNearItPersistedQueue .defaultQueue ().unregisterListener ();
@@ -248,23 +252,9 @@ public void foregroundEvent(Parcelable parcelable, TrackingInfo trackingInfo) {
248
252
NearUtils .parseContents (parcelable , trackingInfo , new RNNearItCoreContentsListener (getReactApplicationContext (), getRCTDeviceEventEmitter (), false ));
249
253
}
250
254
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
-
267
255
// NearIT Radar
256
+ @ SuppressWarnings ("unused" )
257
+ @ SuppressLint ("MissingPermission" )
268
258
@ ReactMethod
269
259
public void startRadar (final Promise promise ) {
270
260
try {
@@ -275,6 +265,7 @@ public void startRadar(final Promise promise) {
275
265
}
276
266
}
277
267
268
+ @ SuppressWarnings ("unused" )
278
269
@ ReactMethod
279
270
public void stopRadar (final Promise promise ) {
280
271
try {
@@ -286,6 +277,7 @@ public void stopRadar(final Promise promise) {
286
277
}
287
278
288
279
// NearIT Trackings
280
+ @ SuppressWarnings ("unused" )
289
281
@ ReactMethod
290
282
public void sendTracking (final String trackinInfoData , final String status , final Promise promise ) {
291
283
try {
@@ -299,6 +291,7 @@ public void sendTracking(final String trackinInfoData, final String status, fina
299
291
}
300
292
301
293
// NearIT Feedback
294
+ @ SuppressWarnings ("unused" )
302
295
@ ReactMethod
303
296
public void sendFeedback (final String feedbackB64 , final int rating , final String comment , final Promise promise ) {
304
297
final Feedback feedback ;
@@ -322,6 +315,7 @@ public void onFail(int errorCode, String errorMessage) {
322
315
}
323
316
324
317
// NearIT UserProfiling
318
+ @ SuppressWarnings ("unused" )
325
319
@ ReactMethod
326
320
public void getUserProfileId (final Promise promise ) {
327
321
NearItManager .getInstance ().getProfileId (new NearItUserProfile .ProfileFetchListener () {
@@ -337,6 +331,7 @@ public void onError(String error) {
337
331
});
338
332
}
339
333
334
+ @ SuppressWarnings ("unused" )
340
335
@ ReactMethod
341
336
public void setUserProfileId (final String profileId , final Promise promise ) {
342
337
try {
@@ -347,6 +342,7 @@ public void setUserProfileId(final String profileId, final Promise promise) {
347
342
}
348
343
}
349
344
345
+ @ SuppressWarnings ("unused" )
350
346
@ ReactMethod
351
347
public void resetUserProfile (final Promise promise ) {
352
348
NearItManager .getInstance ().resetProfileId (new NearItUserProfile .ProfileFetchListener () {
@@ -362,6 +358,7 @@ public void onError(String error) {
362
358
});
363
359
}
364
360
361
+ @ SuppressWarnings ("unused" )
365
362
@ ReactMethod
366
363
public void setUserData (final ReadableMap userData , final Promise promise ) {
367
364
try {
@@ -374,6 +371,44 @@ public void setUserData(final ReadableMap userData, final Promise promise) {
374
371
}
375
372
}
376
373
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" )
377
412
@ ReactMethod
378
413
public void optOut (final Promise promise ) {
379
414
NearItManager .getInstance ().optOut (new OptOutNotifier () {
@@ -391,38 +426,43 @@ public void onFailure(String error) {
391
426
392
427
// NearIT Permissions request
393
428
429
+ @ SuppressWarnings ("unused" )
394
430
@ ReactMethod
395
431
public void checkNotificationPermission (final Promise promise ) {
396
432
promise .resolve (true );
397
433
}
398
434
435
+ @ SuppressWarnings ("unused" )
399
436
@ ReactMethod
400
437
public void requestNotificationPermission (final Promise promise ) {
401
438
promise .resolve (true );
402
439
}
403
440
441
+ @ SuppressWarnings ("unused" )
404
442
@ ReactMethod
405
443
public void checkLocationPermission (final Promise promise ) {
406
444
promise .resolve (true );
407
445
}
408
446
447
+ @ SuppressWarnings ("unused" )
409
448
@ ReactMethod
410
449
public void requestLocationPermission (final Promise promise ) {
411
450
promise .resolve (true );
412
451
}
413
452
414
453
// NearIT Custom Trigger
415
454
455
+ @ SuppressWarnings ("unused" )
416
456
@ ReactMethod
417
457
public void triggerEvent (final String eventKey , final Promise promise ) {
418
458
// Trigger Custom Event Key
419
- NearItManager .getInstance ().processCustomTrigger (eventKey );
459
+ NearItManager .getInstance ().triggerInAppEvent (eventKey );
420
460
// Resolve null, if a Recipe is triggered then the normal notification flow will run
421
461
promise .resolve (null );
422
462
}
423
463
424
464
// NearIT Coupons
425
-
465
+ @ SuppressWarnings ( "unused" )
426
466
@ ReactMethod
427
467
public void getCoupons (final Promise promise ) {
428
468
NearItManager .getInstance ().getCoupons (new CouponListener () {
@@ -467,6 +507,7 @@ private DeviceEventManagerModule.RCTDeviceEventEmitter getRCTDeviceEventEmitter(
467
507
.getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class );
468
508
}
469
509
510
+ @ SuppressWarnings ("unused" )
470
511
private void sendEventWithLocationPermissionStatus (final String permissionStatus ) {
471
512
try {
472
513
// Create Event map to send to JS
0 commit comments