Skip to content

Commit a6040e7

Browse files
committed
Implementing constants bridge for andriod
- Refactoring use of strings in internal functions to use constatns - Expose string constants through `getConstants` react method.
1 parent 47bb36a commit a6040e7

File tree

1 file changed

+115
-65
lines changed

1 file changed

+115
-65
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 115 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,36 @@
2222

2323
public 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

@@ -302,7 +330,7 @@ public void disable() {
302330
}
303331

304332
/**
305-
* @return application token
333+
* @return application token
306334
*/
307335
@ReactMethod
308336
public String getAppToken() {
@@ -344,34 +372,32 @@ public int getUnreadMessagesCount() {
344372
public void changeInvocationEvent(String invocationEventValue) {
345373
InstabugInvocationEvent invocationEvent=InstabugInvocationEvent.FLOATING_BUTTON;
346374
try {
347-
//setting invocation event
348-
if(invocationEventValue.equals("button")) {
375+
//setting invocation event
376+
if(invocationEventValue.equals(INVOCATION_EVENT_FLOATING_BUTTON)) {
349377
invocationEvent=InstabugInvocationEvent.FLOATING_BUTTON;
350-
} else if(invocationEventValue.equals("swipe")) {
378+
} else if(invocationEventValue.equals(INVOCATION_EVENT_TWO_FINGERS_SWIPE)) {
351379
invocationEvent=InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
352-
353-
} else if(invocationEventValue.equals("shake")) {
380+
} else if(invocationEventValue.equals(INVOCATION_EVENT_SHAKE)) {
354381
invocationEvent=InstabugInvocationEvent.SHAKE;
355-
356-
} else if(invocationEventValue.equals("screenshot")){
382+
} else if(invocationEventValue.equals(INVOCATION_EVENT_SCREENSHOT)){
357383
invocationEvent=InstabugInvocationEvent.SCREENSHOT_GESTURE;
358-
359-
} else if(invocationEventValue.equals("none")) {
384+
} else if(invocationEventValue.equals(INVOCATION_EVENT_NONE)) {
360385
invocationEvent=InstabugInvocationEvent.NONE;
361-
}
386+
}
387+
362388
mInstabug.changeInvocationEvent(invocationEvent);
363389
} catch (Exception e) {
364390
e.printStackTrace();
365391
}
366-
392+
367393
}
368394

369395
/**
370396
* Enabled/disable chat notification
371397
*
372398
* @param isChatNotificationEnable whether chat notification is reburied or not
373399
*/
374-
@ReactMethod
400+
@ReactMethod
375401
public void setChatNotificationEnabled(boolean isChatNotificationEnable) {
376402
try {
377403
mInstabug.setChatNotificationEnabled(isChatNotificationEnable);
@@ -398,50 +424,74 @@ public void setDebugEnabled(boolean isDebugEnabled) {
398424

399425
private Locale getLocaleByKey(String instabugLocale) {
400426
String localeInLowerCase=instabugLocale.toLowerCase();
401-
switch (localeInLowerCase){
402-
case "arabic":
403-
return new Locale(InstabugLocale.ARABIC.getCode(), InstabugLocale.ARABIC.getCountry());
404-
case "english":
405-
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry());
406-
case "czech":
407-
return new Locale(InstabugLocale.CZECH.getCode(), InstabugLocale.CZECH.getCountry());
408-
case "french":
409-
return new Locale(InstabugLocale.FRENCH.getCode(), InstabugLocale.FRENCH.getCountry());
410-
case "german":
411-
return new Locale(InstabugLocale.GERMAN.getCode(), InstabugLocale.GERMAN.getCountry());
412-
case "italian":
413-
return new Locale(InstabugLocale.ITALIAN.getCode(), InstabugLocale.ITALIAN.getCountry());
414-
case "japanese":
415-
return new Locale(InstabugLocale.JAPANESE.getCode(), InstabugLocale.JAPANESE.getCountry());
416-
case "polish":
417-
return new Locale(InstabugLocale.POLISH.getCode(), InstabugLocale.POLISH.getCountry());
418-
case "russian":
419-
return new Locale(InstabugLocale.RUSSIAN.getCode(), InstabugLocale.RUSSIAN.getCountry());
420-
case "spanish":
421-
return new Locale(InstabugLocale.SPANISH.getCode(), InstabugLocale.SPANISH.getCountry());
422-
case "swedish":
423-
return new Locale(InstabugLocale.SWEDISH.getCode(), InstabugLocale.SWEDISH.getCountry());
424-
case "turkish":
425-
return new Locale(InstabugLocale.TURKISH.getCode(), InstabugLocale.TURKISH.getCountry());
426-
case "portuguesebrazil":
427-
return new Locale(InstabugLocale.PORTUGUESE_BRAZIL.getCode(), InstabugLocale.PORTUGUESE_BRAZIL.getCountry());
428-
case "chinesesimplified":
429-
return new Locale(InstabugLocale.SIMPLIFIED_CHINESE.getCode(), InstabugLocale.SIMPLIFIED_CHINESE.getCountry());
430-
case "chinesetraditional":
431-
return new Locale(InstabugLocale.TRADITIONAL_CHINESE.getCode(), InstabugLocale.TRADITIONAL_CHINESE.getCountry());
432-
case "korean":
433-
return new Locale(InstabugLocale.KOREAN.getCode(), InstabugLocale.KOREAN.getCountry());
434-
default:
435-
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry());
436-
437-
}
427+
case LOCALE_ARABIC:
428+
return new Locale(InstabugLocale.ARABIC.getCode(), InstabugLocale.ARABIC.getCountry());
429+
case LOCALE_ENGLISH:
430+
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry());
431+
case LOCALE_CZECH:
432+
return new Locale(InstabugLocale.CZECH.getCode(), InstabugLocale.CZECH.getCountry());
433+
case LOCALE_FRENCH:
434+
return new Locale(InstabugLocale.FRENCH.getCode(), InstabugLocale.FRENCH.getCountry());
435+
case LOCALE_GERMAN:
436+
return new Locale(InstabugLocale.GERMAN.getCode(), InstabugLocale.GERMAN.getCountry());
437+
case LOCALE_ITALIAN:
438+
return new Locale(InstabugLocale.ITALIAN.getCode(), InstabugLocale.ITALIAN.getCountry());
439+
case LOCALE_JAPANESE:
440+
return new Locale(InstabugLocale.JAPANESE.getCode(), InstabugLocale.JAPANESE.getCountry());
441+
case LOCALE_POLISH:
442+
return new Locale(InstabugLocale.POLISH.getCode(), InstabugLocale.POLISH.getCountry());
443+
case LOCALE_RUSSIAN:
444+
return new Locale(InstabugLocale.RUSSIAN.getCode(), InstabugLocale.RUSSIAN.getCountry());
445+
case LOCALE_SPANISH:
446+
return new Locale(InstabugLocale.SPANISH.getCode(), InstabugLocale.SPANISH.getCountry());
447+
case LOCALE_SWEDISH:
448+
return new Locale(InstabugLocale.SWEDISH.getCode(), InstabugLocale.SWEDISH.getCountry());
449+
case LOCALE_TURKISH:
450+
return new Locale(InstabugLocale.TURKISH.getCode(), InstabugLocale.TURKISH.getCountry());
451+
case LOCALE_PORTUGUESE_BRAZIL:
452+
return new Locale(InstabugLocale.PORTUGUESE_BRAZIL.getCode(), InstabugLocale.PORTUGUESE_BRAZIL.getCountry());
453+
case LOCALE_CHINESE_SIMPLIFIED:
454+
return new Locale(InstabugLocale.SIMPLIFIED_CHINESE.getCode(), InstabugLocale.SIMPLIFIED_CHINESE.getCountry());
455+
case LOCALE_CHINESE_TRADITIONAL:
456+
return new Locale(InstabugLocale.TRADITIONAL_CHINESE.getCode(), InstabugLocale.TRADITIONAL_CHINESE.getCountry());
457+
case LOCALE_KOREAN:
458+
return new Locale(InstabugLocale.KOREAN.getCode(), InstabugLocale.KOREAN.getCountry());
459+
default:
460+
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry());
438461
}
439462

440463
@Override
441464
public Map<String, Object> getConstants() {
442-
final Map<String, Object> constants = new HashMap<>();
443-
return constants;
444-
465+
final Map<String, Object> constants = new HashMap<>();
466+
constants.put("invocationEventNone", INVOCATION_EVENT_NONE);
467+
constants.put("invocationEventShake", INVOCATION_EVENT_SHAKE);
468+
constants.put("invocationEventScreenshot", INVOCATION_EVENT_SCREENSHOT);
469+
constants.put("invocationEventTwoFingersSwipe", INVOCATION_EVENT_TWO_FINGERS_SWIPE);
470+
constants.put("invocationEventFloatingButton", INVOCATION_EVENT_FLOATING_BUTTON);
471+
472+
constants.put("invocationModeNewBug", INVOCATION_MODE_NEW_BUG);
473+
constants.put("invocationModeNewFeedback", INVOCATION_MODE_NEW_FEEDBACK);
474+
constants.put("invocationModeNewChat", INVOCATION_MODE_NEW_CHAT);
475+
constants.put("invocationModeChatsList", INVOCATION_MODE_CHATS_LIST);
476+
477+
constants.put("localeArabic", LOCALE_ARABIC);
478+
constants.put("localeChineseSimplified", LOCALE_CHINESE_SIMPLIFIED);
479+
constants.put("localeChineseTraditional", LOCALE_CHINESE_TRADITIONAL);
480+
constants.put("localeCzech", LOCALE_CZECH);
481+
constants.put("localeEnglish", LOCALE_ENGLISH);
482+
constants.put("localeFrench", LOCALE_FRENCH);
483+
constants.put("localeGerman", LOCALE_FRENCH);
484+
constants.put("localeKorean", LOCALE_KOREAN);
485+
constants.put("localeItalian", LOCALE_ITALIAN);
486+
constants.put("localeJapanese", LOCALE_JAPANESE);
487+
constants.put("localePolish", LOCALE_POLISH);
488+
constants.put("localePortugueseBrazil", LOCALE_PORTUGUESE_BRAZIL);
489+
constants.put("localeRussian", LOCALE_RUSSIAN);
490+
constants.put("localeSpanish", LOCALE_SPANISH);
491+
constants.put("localeSwedish", LOCALE_SWEDISH);
492+
constants.put("localeTurkish", LOCALE_TURKISH);
493+
494+
return constants;
445495
}
446496
}
447497

0 commit comments

Comments
 (0)