2222
2323public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
2424
25- private Instabug mInstabug ;
26- private InstabugInvocationEvent invocationEvent ;
25+ private Instabug mInstabug ;
26+ private InstabugInvocationEvent invocationEvent ;
27+
28+ private final String INVOCATION_EVENT_NONE = "none" ;
29+ private final String INVOCATION_EVENT_SHAKE = "shake" ;
30+ private final String INVOCATION_EVENT_SCREENSHOT = "screenshot" ;
31+ private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "swipe" ;
32+ private final String INVOCATION_EVENT_FLOATING_BUTTON = "button" ;
33+
34+ private final String INVOCATION_MODE_NEW_BUG = "bug" ;
35+ private final String INVOCATION_MODE_NEW_FEEDBACK = "feedback" ;
36+ private final String INVOCATION_MODE_NEW_CHAT = "chat" ;
37+ private final String INVOCATION_MODE_CHATS_LIST = "chats" ;
38+
39+ private final String LOCALE_ARABIC = "arabic" ;
40+ private final String LOCALE_CHINESE_SIMPLIFIED = "chinesesimplified" ;
41+ private final String LOCALE_CHINESE_TRADITIONAL = "chinesetraditional" ;
42+ private final String LOCALE_CZECH = "czech" ;
43+ private final String LOCALE_ENGLISH = "english" ;
44+ private final String LOCALE_FRENCH = "french" ;
45+ private final String LOCALE_GERMAN = "german" ;
46+ private final String LOCALE_KOREAN = "korean" ;
47+ private final String LOCALE_ITALIAN = "italian" ;
48+ private final String LOCALE_JAPANESE = "japanese" ;
49+ private final String LOCALE_POLISH = "polish" ;
50+ private final String LOCALE_PORTUGUESE_BRAZIL = "portuguesebrazil" ;
51+ private final String LOCALE_RUSSIAN = "russian" ;
52+ private final String LOCALE_SPANISH = "spanish" ;
53+ private final String LOCALE_SWEDISH = "swedish" ;
54+ private final String LOCALE_TURKISH = "turkish" ;
2755
2856 public RNInstabugReactnativeModule (ReactApplicationContext reactContext ,Instabug mInstabug ) {
2957 super (reactContext );
@@ -37,7 +65,7 @@ public String getName() {
3765
3866 /**
3967 * invoke sdk manually
40- *
68+ *
4169 */
4270 @ ReactMethod
4371 public void invoke ()
@@ -50,32 +78,32 @@ public void invoke()
5078 }
5179
5280 /**
53- * invoke sdk manually with desire invocation mode
81+ * invoke sdk manually with desire invocation mode
5482 *
5583 * @param invocation mode
5684 */
5785 @ ReactMethod
5886 public void invokeWithInvocationMode (String invocationMode )
5987 {
60- InstabugInvocationMode mode = InstabugInvocationMode .PROMPT_OPTION ;
61- if (invocationMode .equals ("bug" )) {
88+ InstabugInvocationMode mode ;
89+
90+ if (invocationMode .equals (INVOCATION_MODE_NEW_BUG )) {
6291 mode = InstabugInvocationMode .NEW_BUG ;
63- } else if (invocationMode .equals ("feedback" )) {
92+ } else if (invocationMode .equals (INVOCATION_MODE_NEW_FEEDBACK )) {
6493 mode = InstabugInvocationMode .NEW_FEEDBACK ;
65- }else if (invocationMode .equals ("chat" )){
94+ }else if (invocationMode .equals (INVOCATION_MODE_NEW_CHAT )){
6695 mode = InstabugInvocationMode .NEW_CHAT ;
67- }else if (invocationMode .equals ("chats" )){
96+ }else if (invocationMode .equals (INVOCATION_MODE_CHATS_LIST )){
6897 mode = InstabugInvocationMode .CHATS_LIST ;
69- }else {
98+ } else {
7099 mode = InstabugInvocationMode .PROMPT_OPTION ;
71100 }
72-
101+
73102 try {
74103 mInstabug .invoke (mode );
75104 } catch (Exception e ) {
76105 e .printStackTrace ();
77106 }
78-
79107 }
80108
81109
@@ -319,7 +347,7 @@ public void disable() {
319347 }
320348
321349 /**
322- * @return application token
350+ * @return application token
323351 */
324352 @ ReactMethod
325353 public String getAppToken () {
@@ -361,34 +389,32 @@ public int getUnreadMessagesCount() {
361389 public void changeInvocationEvent (String invocationEventValue ) {
362390 InstabugInvocationEvent invocationEvent =InstabugInvocationEvent .FLOATING_BUTTON ;
363391 try {
364- //setting invocation event
365- if (invocationEventValue .equals ("button" )) {
392+ //setting invocation event
393+ if (invocationEventValue .equals (INVOCATION_EVENT_FLOATING_BUTTON )) {
366394 invocationEvent =InstabugInvocationEvent .FLOATING_BUTTON ;
367- } else if (invocationEventValue .equals ("swipe" )) {
395+ } else if (invocationEventValue .equals (INVOCATION_EVENT_TWO_FINGERS_SWIPE )) {
368396 invocationEvent =InstabugInvocationEvent .TWO_FINGER_SWIPE_LEFT ;
369-
370- } else if (invocationEventValue .equals ("shake" )) {
397+ } else if (invocationEventValue .equals (INVOCATION_EVENT_SHAKE )) {
371398 invocationEvent =InstabugInvocationEvent .SHAKE ;
372-
373- } else if (invocationEventValue .equals ("screenshot" )){
399+ } else if (invocationEventValue .equals (INVOCATION_EVENT_SCREENSHOT )){
374400 invocationEvent =InstabugInvocationEvent .SCREENSHOT_GESTURE ;
375-
376- } else if (invocationEventValue .equals ("none" )) {
401+ } else if (invocationEventValue .equals (INVOCATION_EVENT_NONE )) {
377402 invocationEvent =InstabugInvocationEvent .NONE ;
378- }
403+ }
404+
379405 mInstabug .changeInvocationEvent (invocationEvent );
380406 } catch (Exception e ) {
381407 e .printStackTrace ();
382408 }
383-
409+
384410 }
385411
386412 /**
387413 * Enabled/disable chat notification
388414 *
389415 * @param isChatNotificationEnable whether chat notification is reburied or not
390416 */
391- @ ReactMethod
417+ @ ReactMethod
392418 public void setChatNotificationEnabled (boolean isChatNotificationEnable ) {
393419 try {
394420 mInstabug .setChatNotificationEnabled (isChatNotificationEnable );
@@ -415,50 +441,74 @@ public void setDebugEnabled(boolean isDebugEnabled) {
415441
416442 private Locale getLocaleByKey (String instabugLocale ) {
417443 String localeInLowerCase =instabugLocale .toLowerCase ();
418- switch (localeInLowerCase ){
419- case "arabic" :
420- return new Locale (InstabugLocale .ARABIC .getCode (), InstabugLocale .ARABIC .getCountry ());
421- case "english" :
422- return new Locale (InstabugLocale .ENGLISH .getCode (), InstabugLocale .ENGLISH .getCountry ());
423- case "czech" :
424- return new Locale (InstabugLocale .CZECH .getCode (), InstabugLocale .CZECH .getCountry ());
425- case "french" :
426- return new Locale (InstabugLocale .FRENCH .getCode (), InstabugLocale .FRENCH .getCountry ());
427- case "german" :
428- return new Locale (InstabugLocale .GERMAN .getCode (), InstabugLocale .GERMAN .getCountry ());
429- case "italian" :
430- return new Locale (InstabugLocale .ITALIAN .getCode (), InstabugLocale .ITALIAN .getCountry ());
431- case "japanese" :
432- return new Locale (InstabugLocale .JAPANESE .getCode (), InstabugLocale .JAPANESE .getCountry ());
433- case "polish" :
434- return new Locale (InstabugLocale .POLISH .getCode (), InstabugLocale .POLISH .getCountry ());
435- case "russian" :
436- return new Locale (InstabugLocale .RUSSIAN .getCode (), InstabugLocale .RUSSIAN .getCountry ());
437- case "spanish" :
438- return new Locale (InstabugLocale .SPANISH .getCode (), InstabugLocale .SPANISH .getCountry ());
439- case "swedish" :
440- return new Locale (InstabugLocale .SWEDISH .getCode (), InstabugLocale .SWEDISH .getCountry ());
441- case "turkish" :
442- return new Locale (InstabugLocale .TURKISH .getCode (), InstabugLocale .TURKISH .getCountry ());
443- case "portuguesebrazil" :
444- return new Locale (InstabugLocale .PORTUGUESE_BRAZIL .getCode (), InstabugLocale .PORTUGUESE_BRAZIL .getCountry ());
445- case "chinesesimplified" :
446- return new Locale (InstabugLocale .SIMPLIFIED_CHINESE .getCode (), InstabugLocale .SIMPLIFIED_CHINESE .getCountry ());
447- case "chinesetraditional" :
448- return new Locale (InstabugLocale .TRADITIONAL_CHINESE .getCode (), InstabugLocale .TRADITIONAL_CHINESE .getCountry ());
449- case "korean" :
450- return new Locale (InstabugLocale .KOREAN .getCode (), InstabugLocale .KOREAN .getCountry ());
451- default :
452- return new Locale (InstabugLocale .ENGLISH .getCode (), InstabugLocale .ENGLISH .getCountry ());
453-
454- }
444+ case LOCALE_ARABIC :
445+ return new Locale (InstabugLocale .ARABIC .getCode (), InstabugLocale .ARABIC .getCountry ());
446+ case LOCALE_ENGLISH :
447+ return new Locale (InstabugLocale .ENGLISH .getCode (), InstabugLocale .ENGLISH .getCountry ());
448+ case LOCALE_CZECH :
449+ return new Locale (InstabugLocale .CZECH .getCode (), InstabugLocale .CZECH .getCountry ());
450+ case LOCALE_FRENCH :
451+ return new Locale (InstabugLocale .FRENCH .getCode (), InstabugLocale .FRENCH .getCountry ());
452+ case LOCALE_GERMAN :
453+ return new Locale (InstabugLocale .GERMAN .getCode (), InstabugLocale .GERMAN .getCountry ());
454+ case LOCALE_ITALIAN :
455+ return new Locale (InstabugLocale .ITALIAN .getCode (), InstabugLocale .ITALIAN .getCountry ());
456+ case LOCALE_JAPANESE :
457+ return new Locale (InstabugLocale .JAPANESE .getCode (), InstabugLocale .JAPANESE .getCountry ());
458+ case LOCALE_POLISH :
459+ return new Locale (InstabugLocale .POLISH .getCode (), InstabugLocale .POLISH .getCountry ());
460+ case LOCALE_RUSSIAN :
461+ return new Locale (InstabugLocale .RUSSIAN .getCode (), InstabugLocale .RUSSIAN .getCountry ());
462+ case LOCALE_SPANISH :
463+ return new Locale (InstabugLocale .SPANISH .getCode (), InstabugLocale .SPANISH .getCountry ());
464+ case LOCALE_SWEDISH :
465+ return new Locale (InstabugLocale .SWEDISH .getCode (), InstabugLocale .SWEDISH .getCountry ());
466+ case LOCALE_TURKISH :
467+ return new Locale (InstabugLocale .TURKISH .getCode (), InstabugLocale .TURKISH .getCountry ());
468+ case LOCALE_PORTUGUESE_BRAZIL :
469+ return new Locale (InstabugLocale .PORTUGUESE_BRAZIL .getCode (), InstabugLocale .PORTUGUESE_BRAZIL .getCountry ());
470+ case LOCALE_CHINESE_SIMPLIFIED :
471+ return new Locale (InstabugLocale .SIMPLIFIED_CHINESE .getCode (), InstabugLocale .SIMPLIFIED_CHINESE .getCountry ());
472+ case LOCALE_CHINESE_TRADITIONAL :
473+ return new Locale (InstabugLocale .TRADITIONAL_CHINESE .getCode (), InstabugLocale .TRADITIONAL_CHINESE .getCountry ());
474+ case LOCALE_KOREAN :
475+ return new Locale (InstabugLocale .KOREAN .getCode (), InstabugLocale .KOREAN .getCountry ());
476+ default :
477+ return new Locale (InstabugLocale .ENGLISH .getCode (), InstabugLocale .ENGLISH .getCountry ());
455478 }
456479
457480 @ Override
458481 public Map <String , Object > getConstants () {
459- final Map <String , Object > constants = new HashMap <>();
460- return constants ;
461-
482+ final Map <String , Object > constants = new HashMap <>();
483+ constants .put ("invocationEventNone" , INVOCATION_EVENT_NONE );
484+ constants .put ("invocationEventShake" , INVOCATION_EVENT_SHAKE );
485+ constants .put ("invocationEventScreenshot" , INVOCATION_EVENT_SCREENSHOT );
486+ constants .put ("invocationEventTwoFingersSwipe" , INVOCATION_EVENT_TWO_FINGERS_SWIPE );
487+ constants .put ("invocationEventFloatingButton" , INVOCATION_EVENT_FLOATING_BUTTON );
488+
489+ constants .put ("invocationModeNewBug" , INVOCATION_MODE_NEW_BUG );
490+ constants .put ("invocationModeNewFeedback" , INVOCATION_MODE_NEW_FEEDBACK );
491+ constants .put ("invocationModeNewChat" , INVOCATION_MODE_NEW_CHAT );
492+ constants .put ("invocationModeChatsList" , INVOCATION_MODE_CHATS_LIST );
493+
494+ constants .put ("localeArabic" , LOCALE_ARABIC );
495+ constants .put ("localeChineseSimplified" , LOCALE_CHINESE_SIMPLIFIED );
496+ constants .put ("localeChineseTraditional" , LOCALE_CHINESE_TRADITIONAL );
497+ constants .put ("localeCzech" , LOCALE_CZECH );
498+ constants .put ("localeEnglish" , LOCALE_ENGLISH );
499+ constants .put ("localeFrench" , LOCALE_FRENCH );
500+ constants .put ("localeGerman" , LOCALE_FRENCH );
501+ constants .put ("localeKorean" , LOCALE_KOREAN );
502+ constants .put ("localeItalian" , LOCALE_ITALIAN );
503+ constants .put ("localeJapanese" , LOCALE_JAPANESE );
504+ constants .put ("localePolish" , LOCALE_POLISH );
505+ constants .put ("localePortugueseBrazil" , LOCALE_PORTUGUESE_BRAZIL );
506+ constants .put ("localeRussian" , LOCALE_RUSSIAN );
507+ constants .put ("localeSpanish" , LOCALE_SPANISH );
508+ constants .put ("localeSwedish" , LOCALE_SWEDISH );
509+ constants .put ("localeTurkish" , LOCALE_TURKISH );
510+
511+ return constants ;
462512 }
463513}
464514
0 commit comments