Skip to content

Commit d2f679e

Browse files
authored
[MOB 2943] Flutter API: setValueForStringWithKey (#43)
* ✨ Add tests for mapped android enums for InstabugCustomTextPlaceHolder.Key * ✨ Add android enums for IBGCustomTextPlaceHolderKey * ✨ add ios enums for IBGCustomTextPlaceHolderKey * ✨ add dart enums for IBGCustomTextPlaceHolderKey * ✨ add android map for setValueForStringWithKey * ✨ add ios map for setValueForStringWithKey * ✨ add dart API for setValueForStringWithKey * ✨ Add setValueForStringWithKey to the example app * ✨ add setValueForStringWithKey test * 📝 change the module name from InstabugFlutter to Instabug * 🎨 some changes to remove some lint warnings * 📚 update doc * 📝 add duplicate test to include all keys for future use
1 parent 96ceafd commit d2f679e

File tree

8 files changed

+373
-76
lines changed

8 files changed

+373
-76
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ The table below contains a list of APIs we're planning to implement for our 1.0
2626

2727
| API Method | Native Equivalent (Android/iOS) |
2828
|------------|-----------------------------------------------------------------------------------------------------------------------------------------|
29-
| `start(String token, List<InvocationEvent> invocationEvents)` | `new Instabug.Builder(this, "APP_TOKEN").build()`<br>`+ [Instabug startWithToken:invocationEvents:]` |
30-
|`showWelcomeMessageWithMode(WelcomeMessageMode welcomeMessageMode)`| `Instabug.showWelcomeMessage(WelcomeMessage.State state)`<br>`+ [Instabug showWelcomeMessageWithMode:]` |
31-
|`identifyUserWithEmail(String email, [String name])`| `Instabug.identifyUser(String username, String email)`<br>`+ [Instabug identifyUserWithEmail:name:]` |
32-
|`logOut()`| `Instabug.logoutUser()`<br>`+ [Instabug logOut]` |
33-
|`setLocale(Locale locale)`| `Instabug.setLocale(Locale locale)`<br>`+ [Instabug setLocale:]` |
34-
|`InstabugFlutter.setColorTheme(ColorTheme colorTheme)`| `Instabug.setColorTheme(InstabugColorTheme theme)`<br>`+ [Instabug setColorTheme:]` |
35-
|`InstabugFlutter.appendTags(List<String> tags)`| `Instabug.addTags(String... tags)`<br>`+ [Instabug appendTags:]` |
36-
|`InstabugFlutter.resetTags()`| `Instabug.resetTags()`<br>`+ [Instabug resetTags]` |
37-
|`InstabugFlutter.getTags()`| `Instabug.getTags()`<br>`+ [Instabug getTags]` |
38-
| | `Instabug.setCustomTextPlaceHolders(InstabugCustomTextPlaceHolder placeholder)`<br>`+ [Instabug setValue:forStringWithKey:]` |
39-
|`InstabugFlutter.setUserAttributeWithKey(String value, String key)`| `Instabug.setUserAttribute(String key, String value)`<br>`+ [Instabug setUserAttribute:withKey:]` |
40-
|`Instabugflutter.getUserAttributeForKey(Sring Key)`| `Instabug.getUserAttribute(String key)`<br>`+ [Instabug userAttributeForKey:]` |
41-
|`InstabugFlutter.removeUserAttributeForKey(String key)`| `Instabug.removeUserAttribute(String key)`<br>`+ [Instabug removeUserAttributeForKey:]` |
42-
|`InstabugFlutter.getUserAttributes()`| `Instabug.getAllUserAttributes()`<br>`+ [Instabug userAttributes:]` |
43-
|`logUserEventWithName(String name)`| `Instabug.logUserEvent(String name)`<br>`+ [Instabug logUserEventWithName:]` |
44-
|`show()`| `Instabug.show()`<br>`+ [Instabug show]` |
45-
|`invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions])`| `BugReporting.invoke(InvocationMode mode, @InvocationOption int... options)`<br>`+ [IBGBugReporting invokeWithMode:options:]` |
46-
|`logDebug(String message)`| `InstabugLog.d(String message)`<br>`+ [IBGLog logDebug:]` |
47-
|`logVerbose(String message)`| `InstabugLog.v(String message)`<br>`+ [IBGLog logVerbose:]` |
48-
|`logInfo(String message)`| `InstabugLog.i(String message)`<br>`+ [IBGLog logInfo:]` |
49-
|`logWarn(String message)`| `InstabugLog.w(String message)`<br>`+ [IBGLog logWarn:]` |
50-
|`logError(String message)`| `InstabugLog.e(String message)`<br>`+ [IBGLog logError:]` |
51-
|`clearAllLogs(String message)`| `Instabug.clearLogs()`<br>`+ [IBGLog clearAllLogs:]` |
29+
| `Instabug.start(String token, List<InvocationEvent> invocationEvents)` | `new Instabug.Builder(this, "APP_TOKEN").build()`<br>`+ [Instabug startWithToken:invocationEvents:]` |
30+
|`Instabug.showWelcomeMessageWithMode(WelcomeMessageMode welcomeMessageMode)`| `Instabug.showWelcomeMessage(WelcomeMessage.State state)`<br>`+ [Instabug showWelcomeMessageWithMode:]` |
31+
|`Instabug.identifyUserWithEmail(String email, [String name])`| `Instabug.identifyUser(String username, String email)`<br>`+ [Instabug identifyUserWithEmail:name:]` |
32+
|`Instabug.logOut()`| `Instabug.logoutUser()`<br>`+ [Instabug logOut]` |
33+
|`Instabug.setLocale(Locale locale)`| `Instabug.setLocale(Locale locale)`<br>`+ [Instabug setLocale:]` |
34+
|`Instabug.setColorTheme(ColorTheme colorTheme)`| `Instabug.setColorTheme(InstabugColorTheme theme)`<br>`+ [Instabug setColorTheme:]` |
35+
|`Instabug.appendTags(List<String> tags)`| `Instabug.addTags(String... tags)`<br>`+ [Instabug appendTags:]` |
36+
|`Instabug.resetTags()`| `Instabug.resetTags()`<br>`+ [Instabug resetTags]` |
37+
|`Instabug.getTags()`| `Instabug.getTags()`<br>`+ [Instabug getTags]` |
38+
|`Instabug.setStringForKey(String value, String key)`| `Instabug.setCustomTextPlaceHolders(InstabugCustomTextPlaceHolder placeholder)`<br>`+ [Instabug setValue:forStringWithKey:]` |
39+
|`Instabug.setUserAttributeWithKey(String value, String key)`| `Instabug.setUserAttribute(String key, String value)`<br>`+ [Instabug setUserAttribute:withKey:]` |
40+
|`Instabug.getUserAttributeForKey(Sring Key)`| `Instabug.getUserAttribute(String key)`<br>`+ [Instabug userAttributeForKey:]` |
41+
|`Instabug.removeUserAttributeForKey(String key)`| `Instabug.removeUserAttribute(String key)`<br>`+ [Instabug removeUserAttributeForKey:]` |
42+
|`Instabug.getUserAttributes()`| `Instabug.getAllUserAttributes()`<br>`+ [Instabug userAttributes:]` |
43+
|`Instabug.logUserEventWithName(String name)`| `Instabug.logUserEvent(String name)`<br>`+ [Instabug logUserEventWithName:]` |
44+
|`Instabug.show()`| `Instabug.show()`<br>`+ [Instabug show]` |
45+
|`Instabug.invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions])`| `BugReporting.invoke(InvocationMode mode, @InvocationOption int... options)`<br>`+ [IBGBugReporting invokeWithMode:options:]` |
46+
|`Instabug.logDebug(String message)`| `InstabugLog.d(String message)`<br>`+ [IBGLog logDebug:]` |
47+
|`Instabug.logVerbose(String message)`| `InstabugLog.v(String message)`<br>`+ [IBGLog logVerbose:]` |
48+
|`Instabug.logInfo(String message)`| `InstabugLog.i(String message)`<br>`+ [IBGLog logInfo:]` |
49+
|`Instabug.logWarn(String message)`| `InstabugLog.w(String message)`<br>`+ [IBGLog logWarn:]` |
50+
|`Instabug.logError(String message)`| `InstabugLog.e(String message)`<br>`+ [IBGLog logError:]` |
51+
|`Instabug.clearAllLogs(String message)`| `Instabug.clearLogs()`<br>`+ [IBGLog clearAllLogs:]` |
5252

5353
## Integration
5454

android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.instabug.bug.BugReporting;
77
import com.instabug.bug.invocation.Option;
88
import com.instabug.library.InstabugColorTheme;
9+
import com.instabug.library.InstabugCustomTextPlaceHolder;
910

1011
import java.util.HashMap;
1112
import java.util.Locale;
@@ -55,6 +56,7 @@ final class ArgsRegistry {
5556
registerLocaleArgs(ARGS);
5657
registerInvocationModeArgs(ARGS);
5758
registerInvocationOptionsArgs(ARGS);
59+
registerCustomTextPlaceHolderKeysArgs(ARGS);
5860
}
5961

6062
/**
@@ -160,4 +162,40 @@ static void registerLocaleArgs(Map<String, Object> args) {
160162
args.put("Locale.Slovak", new Locale(SLOVAK.getCode(), SLOVAK.getCountry()));
161163
args.put("Locale.Czech", new Locale(CZECH.getCode(), CZECH.getCountry()));
162164
}
165+
166+
@VisibleForTesting
167+
static void registerCustomTextPlaceHolderKeysArgs(Map<String, Object> args) {
168+
args.put("IBGCustomTextPlaceHolderKey.SHAKE_HINT", InstabugCustomTextPlaceHolder.Key.SHAKE_HINT);
169+
args.put("IBGCustomTextPlaceHolderKey.SWIPE_HINT", InstabugCustomTextPlaceHolder.Key.SWIPE_HINT);
170+
args.put("IBGCustomTextPlaceHolderKey.INVALID_EMAIL_MESSAGE", InstabugCustomTextPlaceHolder.Key.INVALID_EMAIL_MESSAGE);
171+
args.put("IBGCustomTextPlaceHolderKey.INVALID_COMMENT_MESSAGE", InstabugCustomTextPlaceHolder.Key.INVALID_COMMENT_MESSAGE);
172+
args.put("IBGCustomTextPlaceHolderKey.INVOCATION_HEADER", InstabugCustomTextPlaceHolder.Key.INVOCATION_HEADER);
173+
args.put("IBGCustomTextPlaceHolderKey.START_CHATS", InstabugCustomTextPlaceHolder.Key.START_CHATS);
174+
args.put("IBGCustomTextPlaceHolderKey.REPORT_BUG", InstabugCustomTextPlaceHolder.Key.REPORT_BUG);
175+
args.put("IBGCustomTextPlaceHolderKey.REPORT_FEEDBACK", InstabugCustomTextPlaceHolder.Key.REPORT_FEEDBACK);
176+
args.put("IBGCustomTextPlaceHolderKey.EMAIL_FIELD_HINT", InstabugCustomTextPlaceHolder.Key.EMAIL_FIELD_HINT);
177+
args.put("IBGCustomTextPlaceHolderKey.COMMENT_FIELD_HINT_FOR_BUG_REPORT", InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_BUG_REPORT);
178+
args.put("IBGCustomTextPlaceHolderKey.COMMENT_FIELD_HINT_FOR_FEEDBACK", InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_FEEDBACK);
179+
args.put("IBGCustomTextPlaceHolderKey.ADD_VOICE_MESSAGE", InstabugCustomTextPlaceHolder.Key.ADD_VOICE_MESSAGE);
180+
args.put("IBGCustomTextPlaceHolderKey.ADD_IMAGE_FROM_GALLERY", InstabugCustomTextPlaceHolder.Key.ADD_IMAGE_FROM_GALLERY);
181+
args.put("IBGCustomTextPlaceHolderKey.ADD_EXTRA_SCREENSHOT", InstabugCustomTextPlaceHolder.Key.ADD_EXTRA_SCREENSHOT);
182+
args.put("IBGCustomTextPlaceHolderKey.CONVERSATIONS_LIST_TITLE", InstabugCustomTextPlaceHolder.Key.CONVERSATIONS_LIST_TITLE);
183+
args.put("IBGCustomTextPlaceHolderKey.AUDIO_RECORDING_PERMISSION_DENIED", InstabugCustomTextPlaceHolder.Key.AUDIO_RECORDING_PERMISSION_DENIED);
184+
args.put("IBGCustomTextPlaceHolderKey.CONVERSATION_TEXT_FIELD_HINT", InstabugCustomTextPlaceHolder.Key.CONVERSATION_TEXT_FIELD_HINT);
185+
args.put("IBGCustomTextPlaceHolderKey.BUG_REPORT_HEADER", InstabugCustomTextPlaceHolder.Key.BUG_REPORT_HEADER);
186+
args.put("IBGCustomTextPlaceHolderKey.FEEDBACK_REPORT_HEADER", InstabugCustomTextPlaceHolder.Key.FEEDBACK_REPORT_HEADER);
187+
args.put("IBGCustomTextPlaceHolderKey.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD", InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD);
188+
args.put("IBGCustomTextPlaceHolderKey.VOICE_MESSAGE_RELEASE_TO_ATTACH", InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_RELEASE_TO_ATTACH);
189+
args.put("IBGCustomTextPlaceHolderKey.REPORT_SUCCESSFULLY_SENT", InstabugCustomTextPlaceHolder.Key.REPORT_SUCCESSFULLY_SENT);
190+
args.put("IBGCustomTextPlaceHolderKey.SUCCESS_DIALOG_HEADER", InstabugCustomTextPlaceHolder.Key.SUCCESS_DIALOG_HEADER);
191+
args.put("IBGCustomTextPlaceHolderKey.ADD_VIDEO", InstabugCustomTextPlaceHolder.Key.ADD_VIDEO);
192+
args.put("IBGCustomTextPlaceHolderKey.BETA_WELCOME_MESSAGE_WELCOME_STEP_TITLE", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_WELCOME_STEP_TITLE);
193+
args.put("IBGCustomTextPlaceHolderKey.BETA_WELCOME_MESSAGE_WELCOME_STEP_CONTENT", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_WELCOME_STEP_CONTENT);
194+
args.put("IBGCustomTextPlaceHolderKey.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_TITLE", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_TITLE);
195+
args.put("IBGCustomTextPlaceHolderKey.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_CONTENT", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_CONTENT);
196+
args.put("IBGCustomTextPlaceHolderKey.BETA_WELCOME_MESSAGE_FINISH_STEP_TITLE", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_FINISH_STEP_TITLE);
197+
args.put("IBGCustomTextPlaceHolderKey.BETA_WELCOME_MESSAGE_FINISH_STEP_CONTENT", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_FINISH_STEP_CONTENT);
198+
args.put("IBGCustomTextPlaceHolderKey.LIVE_WELCOME_MESSAGE_TITLE", InstabugCustomTextPlaceHolder.Key.LIVE_WELCOME_MESSAGE_TITLE);
199+
args.put("IBGCustomTextPlaceHolderKey.LIVE_WELCOME_MESSAGE_CONTENT", InstabugCustomTextPlaceHolder.Key.LIVE_WELCOME_MESSAGE_CONTENT);
200+
}
163201
}

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.instabug.chat.Replies;
1212
import com.instabug.library.Instabug;
1313
import com.instabug.library.InstabugColorTheme;
14+
import com.instabug.library.InstabugCustomTextPlaceHolder;
1415
import com.instabug.library.invocation.InstabugInvocationEvent;
1516
import com.instabug.library.logging.InstabugLog;
1617
import com.instabug.library.ui.onboarding.WelcomeMessage;
@@ -40,6 +41,8 @@ public class InstabugFlutterPlugin implements MethodCallHandler {
4041
final public static String INVOCATION_EVENT_FLOATING_BUTTON = "InvocationEvent.floatingButton";
4142
final public static String INVOCATION_EVENT_SHAKE = "InvocationEvent.shake";
4243

44+
private InstabugCustomTextPlaceHolder placeHolder = new InstabugCustomTextPlaceHolder();
45+
4346
/**
4447
* Plugin registration.
4548
*/
@@ -323,5 +326,17 @@ public void invokeWithMode(String invocationMode, List<String> invocationOptions
323326
*/
324327
public void logUserEventWithName(String name) {
325328
Instabug.logUserEvent(name);
326-
}
329+
}
330+
331+
332+
/**
333+
* Overrides any of the strings shown in the SDK with custom ones.
334+
* @param value String value to override the default one.
335+
* @param forStringWithKey Key of string to override.
336+
*/
337+
public void setValue(String value, String forStringWithKey) {
338+
InstabugCustomTextPlaceHolder.Key key = ArgsRegistry.getDeserializedValue(forStringWithKey, InstabugCustomTextPlaceHolder.Key.class);
339+
placeHolder.set(key, value);
340+
Instabug.setCustomTextPlaceHolders(placeHolder);
341+
}
327342
}

0 commit comments

Comments
 (0)