Skip to content

Commit a059f5c

Browse files
Enable CustomStrings APIs in android
1 parent 712016c commit a059f5c

File tree

2 files changed

+127
-3
lines changed

2 files changed

+127
-3
lines changed

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

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.instabug.library.InstabugColorTheme;
1717
import com.instabug.library.logging.InstabugLog;
1818
import com.instabug.library.bugreporting.model.ReportCategory;
19+
import com.instabug.library.InstabugCustomTextPlaceHolder;
1920

2021
import java.util.ArrayList;
2122
import java.util.HashMap;
@@ -61,9 +62,52 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
6162
private final String COLOR_THEME_LIGHT = "light";
6263
private final String COLOR_THEME_DARK = "dark";
6364

65+
edgeSwipeStartHint:Instabug.edgeSwipeStartHint,
66+
67+
startAlertText:Instabug.startAlertText,
68+
69+
70+
microphonePermissionAlertSettingsButtonText:Instabug
71+
.microphonePermissionAlertSettingsButtonText,
72+
73+
conversationsHeaderTitle:Instabug.conversationsHeaderTitle,
74+
75+
screenshotHeaderTitle:Instabug.screenshotHeaderTitle,
76+
77+
//CustomTextPlaceHolders
78+
private final String SHAKE_HINT = "shakeHint";
79+
private final String SWIPE_HINT = "swipeHint";
80+
private final String INVALID_EMAIL_MESSAGE = "invalidEmailMessage";
81+
private final String INVALID_COMMENT_MESSAGE = "invalidCommentMessage";
82+
private final String EMAIL_FIELD_HINT = "emailFieldHint";
83+
private final String COMMENT_FIELD_HINT_FOR_BUG_REPORT = "commentFieldHintForBugReport";
84+
private final String COMMENT_FIELD_HINT_FOR_FEEDBACK = "commentFieldHintForFeedback";
85+
86+
private final String INVOCATION_HEADER = "invocationHeader";
87+
private final String START_CHATS = "talkToUs";
88+
private final String REPORT_BUG = "reportBug";
89+
private final String REPORT_FEEDBACK = "reportFeedback";
90+
91+
private final String CONVERSATIONS_LIST_TITLE = "conversationsHeaderTitle";
92+
93+
private final String ADD_VOICE_MESSAGE = "addVoiceMessage";
94+
private final String ADD_IMAGE_FROM_GALLERY = "addImageFromGallery";
95+
private final String ADD_EXTRA_SCREENSHOT = "addExtraScreenshot";
96+
private final String ADD_VIDEO = "addVideoMessage";
97+
98+
private final String AUDIO_RECORDING_PERMISSION_DENIED =
99+
"audioRecordingPermissionDeniedMessage";
100+
101+
private final String VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD = "recordingMessageToHoldText";
102+
private final String VOICE_MESSAGE_RELEASE_TO_ATTACH = "recordingMessageToReleaseText";
103+
104+
private final String REPORT_SUCCESSFULLY_SENT = "thankYouText";
105+
private final String VIDEO_PLAYER_TITLE = "video";
106+
64107
private Application androidApplication;
65108
private Instabug mInstabug;
66109
private InstabugInvocationEvent invocationEvent;
110+
private InstabugCustomTextPlaceHolder placeHolders;
67111

68112
/**
69113
* Instantiates a new Rn instabug reactnative module.
@@ -88,6 +132,9 @@ public void startWithToken(String androidToken, String invocationEvent) {
88132
.setIntroMessageEnabled(false)
89133
.setInvocationEvent(getInvocationEventById(invocationEvent))
90134
.build();
135+
//init placHolders
136+
placeHolders = new InstabugCustomTextPlaceHolder();
137+
91138
}
92139

93140
/**
@@ -701,7 +748,11 @@ public void setReportCategories(ReadableArray categoriesTitles) {
701748
*/
702749
@ReactMethod
703750
public void setEmailFieldRequired(boolean isEmailFieldRequired) {
704-
mInstabug.setEmailFieldRequired(isEmailFieldRequired);
751+
try {
752+
mInstabug.setEmailFieldRequired(isEmailFieldRequired);
753+
} catch (java.lang.Exception exception) {
754+
exception.printStackTrace();
755+
}
705756
}
706757

707758
/**
@@ -713,7 +764,80 @@ public void setEmailFieldRequired(boolean isEmailFieldRequired) {
713764
*/
714765
@ReactMethod
715766
public void setCommentFieldRequired(boolean isCommentFieldRequired) {
716-
mInstabug.setCommentFieldRequired(isCommentFieldRequired);
767+
try {
768+
mInstabug.setCommentFieldRequired(isCommentFieldRequired);
769+
} catch (java.lang.Exception exception) {
770+
exception.printStackTrace();
771+
}
772+
}
773+
774+
/**
775+
* Overrides any of the strings shown in the SDK with custom ones.
776+
* Allows you to customize any of the strings shown to users in the SDK.
777+
*
778+
* @param {string} string String value to override the default one.
779+
* @param {strings} key Key of string to override.
780+
*/
781+
@ReactMethod
782+
public void setStringToKey(String string, String key) {
783+
try {
784+
placeHolders.set(getStringToKeyConstant(key), string);
785+
Instabug.setCustomTextPlaceHolders(placeHolders);
786+
} catch (java.lang.Exception exception) {
787+
exception.printStackTrace();
788+
}
789+
}
790+
791+
private String getStringToKeyConstant(String key) {
792+
String keyInLowerCase = key.toLowerCase();
793+
switch (localeInLowerCase) {
794+
case SHAKE_HINT:
795+
return InstabugCustomTextPlaceHolder.Key.SHAKE_HINT;
796+
case SWIPE_HINT:
797+
return InstabugCustomTextPlaceHolder.Key.SWIPE_HINT;
798+
case INVALID_EMAIL_MESSAGE:
799+
return InstabugCustomTextPlaceHolder.Key.INVALID_EMAIL_MESSAGE;
800+
case INVALID_COMMENT_MESSAGE:
801+
return InstabugCustomTextPlaceHolder.Key.INVALID_COMMENT_MESSAGE;
802+
case EMAIL_FIELD_HINT:
803+
return InstabugCustomTextPlaceHolder.Key.EMAIL_FIELD_HINT;
804+
case COMMENT_FIELD_HINT_FOR_BUG_REPORT:
805+
return InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_BUG_REPORT;
806+
case COMMENT_FIELD_HINT_FOR_FEEDBACK:
807+
return InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_FEEDBACK;
808+
case INVOCATION_HEADER:
809+
return InstabugCustomTextPlaceHolder.Key.INVOCATION_HEADER;
810+
case START_CHATS:
811+
return InstabugCustomTextPlaceHolder.Key.START_CHATS;
812+
case REPORT_BUG:
813+
return InstabugCustomTextPlaceHolder.Key.REPORT_BUG;
814+
case REPORT_FEEDBACK:
815+
return InstabugCustomTextPlaceHolder.Key.REPORT_FEEDBACK;
816+
case CONVERSATIONS_LIST_TITLE:
817+
return InstabugCustomTextPlaceHolder.Key.CONVERSATIONS_LIST_TITLE;
818+
case ADD_VOICE_MESSAGE:
819+
return InstabugCustomTextPlaceHolder.Key.ADD_VOICE_MESSAGE;
820+
case ADD_IMAGE_FROM_GALLERY:
821+
return InstabugCustomTextPlaceHolder.Key.ADD_IMAGE_FROM_GALLERY;
822+
case ADD_EXTRA_SCREENSHOT:
823+
return InstabugCustomTextPlaceHolder.Key.ADD_EXTRA_SCREENSHOT;
824+
case ADD_VIDEO:
825+
return InstabugCustomTextPlaceHolder.Key.ADD_VIDEO;
826+
case AUDIO_RECORDING_PERMISSION_DENIED:
827+
return InstabugCustomTextPlaceHolder.Key.AUDIO_RECORDING_PERMISSION_DENIED;
828+
case VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD:
829+
return InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD;
830+
case VOICE_MESSAGE_RELEASE_TO_ATTACH:
831+
return InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_RELEASE_TO_ATTACH;
832+
case CONVERSATION_TEXT_FIELD_HINT:
833+
return InstabugCustomTextPlaceHolder.Key.CONVERSATION_TEXT_FIELD_HINT;
834+
case REPORT_SUCCESSFULLY_SENT:
835+
return InstabugCustomTextPlaceHolder.Key.REPORT_SUCCESSFULLY_SENT;
836+
case VIDEO_PLAYER_TITLE:
837+
return InstabugCustomTextPlaceHolder.Key.VIDEO_PLAYER_TITLE;
838+
default:
839+
return null;
840+
}
717841
}
718842

719843
private Locale getLocaleByKey(String instabugLocale) {
@@ -807,6 +931,7 @@ public Map<String, Object> getConstants() {
807931
constants.put("localeSwedish", LOCALE_SWEDISH);
808932
constants.put("localeTurkish", LOCALE_TURKISH);
809933

934+
810935
return constants;
811936
}
812937
}

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ module.exports = {
364364
* @param {strings} key Key of string to override.
365365
*/
366366
setStringToKey: function (string, key) {
367-
if (Platform.OS === 'ios')
368367
Instabug.setString(string, key);
369368
},
370369

0 commit comments

Comments
 (0)