3
3
import android .content .Intent ;
4
4
import android .graphics .Color ;
5
5
import android .net .Uri ;
6
+ import android .util .Log ;
6
7
7
8
import com .instabug .library .Instabug ;
8
9
import com .instabug .library .invocation .InstabugInvocationEvent ;
18
19
19
20
import java .io .File ;
20
21
import java .lang .Integer ;
22
+ import java .util .HashMap ;
21
23
22
24
/**
23
25
* This plugin initializes Instabug.
@@ -133,7 +135,19 @@ public boolean execute(final String action, JSONArray args, final CallbackContex
133
135
} else if ("removeUserAttribute" .equals (action )) {
134
136
removeUserAttribute (callbackContext , args .optString (0 ));
135
137
136
- } else {
138
+ } else if ("identifyUserWithEmail" .equals (action )) {
139
+ identifyUserWithEmail (callbackContext , args .optString (0 ), args .optString (1 ));
140
+
141
+ } else if ("logOut" .equals (action )) {
142
+ logOut (callbackContext );
143
+
144
+ } else if ("getAllUserAttributes" .equals (action )) {
145
+ getAllUserAttributes (callbackContext );
146
+
147
+ } else if ("getUserAttribute" .equals (action )) {
148
+ getUserAttribute (callbackContext , args .optString (0 ));
149
+
150
+ } else {
137
151
// Method not found.
138
152
return false ;
139
153
}
@@ -234,6 +248,7 @@ private void setPrimaryColor(final CallbackContext callbackContext, String color
234
248
* @param email
235
249
* User's default email
236
250
*/
251
+ @ Deprecated
237
252
private void setUserEmail (final CallbackContext callbackContext , String email ) {
238
253
if (email != null && email .length () > 0 ) {
239
254
try {
@@ -253,6 +268,7 @@ private void setUserEmail(final CallbackContext callbackContext, String email) {
253
268
* @param name
254
269
* User's name
255
270
*/
271
+ @ Deprecated
256
272
private void setUserName (final CallbackContext callbackContext , String name ) {
257
273
if (name != null && name .length () > 0 ) {
258
274
try {
@@ -264,6 +280,45 @@ private void setUserName(final CallbackContext callbackContext, String name) {
264
280
} else callbackContext .error ("A name must be provided." );
265
281
}
266
282
283
+ /**
284
+ * Set the user identity.
285
+ * Instabug will pre-fill the user email in reports.
286
+ *
287
+ * @param callbackContext
288
+ * Used when calling back into JavaScript
289
+ * @param email
290
+ * User's default email
291
+ * @param name
292
+ * Username
293
+ *
294
+ */
295
+ private void identifyUserWithEmail (final CallbackContext callbackContext , String email , String name ) {
296
+ if (name != null && name .length () > 0 && email != null && email .length () > 0 ) {
297
+ try {
298
+ Instabug .identifyUser (name , email );
299
+ callbackContext .success ();
300
+ } catch (IllegalStateException e ) {
301
+ callbackContext .error (errorMsg );
302
+ }
303
+ } else callbackContext .error ("A name and email must be provided." );
304
+ }
305
+
306
+
307
+ /**
308
+ * Logout User
309
+ *
310
+ * @param callbackContext
311
+ * Used when calling back into JavaScript
312
+ */
313
+ private void logOut (final CallbackContext callbackContext ) {
314
+ try {
315
+ Instabug .logoutUser ();
316
+ callbackContext .success ();
317
+ } catch (IllegalStateException e ) {
318
+ callbackContext .error (errorMsg );
319
+ }
320
+ }
321
+
267
322
/**
268
323
* Adds specific user data that you need to reports.
269
324
*
@@ -454,11 +509,9 @@ private void setDebugEnabled(final CallbackContext callbackContext, boolean isDe
454
509
* Used when calling back into JavaScript
455
510
* @param key the attribute
456
511
* @param value the value
457
- * @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
458
512
*
459
513
*/
460
-
461
- private void setUserAttribute (final CallbackContext callbackContext , String key , String value ) {
514
+ private void setUserAttribute (final CallbackContext callbackContext , String key , String value ) {
462
515
try {
463
516
Instabug .setUserAttribute (key ,value );
464
517
callbackContext .success ();
@@ -473,10 +526,8 @@ private void setUserAttribute(final CallbackContext callbackContext, String key,
473
526
* @param callbackContext
474
527
* Used when calling back into JavaScript
475
528
* @param key the attribute key as string
476
- * @throws IllegalStateException if Instabug object wasn't built using {@link Builder#build()} before this method was called
477
529
*
478
530
*/
479
-
480
531
private void removeUserAttribute (final CallbackContext callbackContext , String key ) {
481
532
try {
482
533
Instabug .removeUserAttribute (key );
@@ -486,6 +537,41 @@ private void removeUserAttribute(final CallbackContext callbackContext, String k
486
537
}
487
538
}
488
539
540
+
541
+ /**
542
+ * Gets all saved user attributes.
543
+ *
544
+ * @param callbackContext
545
+ * Used when calling back into JavaScript
546
+ */
547
+ private void getAllUserAttributes (final CallbackContext callbackContext ) {
548
+ try {
549
+ HashMap userAttributes = Instabug .getAllUserAttributes ();
550
+ JSONObject jsonUserAttributes = new JSONObject (userAttributes );
551
+ callbackContext .success (jsonUserAttributes );
552
+ } catch (IllegalStateException e ) {
553
+ callbackContext .error (errorMsg );
554
+ }
555
+ }
556
+
557
+ /**
558
+ * Gets specific user attribute.
559
+ *
560
+ * @param callbackContext
561
+ * Used when calling back into JavaScript
562
+ * @param key
563
+ * the attribute key as string
564
+ *
565
+ */
566
+ private void getUserAttribute (final CallbackContext callbackContext , String key ) {
567
+ try {
568
+ String userAttribute = Instabug .getUserAttribute (key );
569
+ callbackContext .success (userAttribute );
570
+ } catch (IllegalStateException e ) {
571
+ callbackContext .error (errorMsg );
572
+ }
573
+ }
574
+
489
575
/**
490
576
* Adds intent extras for all options passed to activate().
491
577
*/
0 commit comments