|
| 1 | +package com.instabug.reactlibrary; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Locale; |
| 5 | +import java.util.Map; |
| 6 | + |
| 7 | +import com.instabug.bug.BugReporting; |
| 8 | +import com.instabug.bug.invocation.Option; |
| 9 | +import com.instabug.library.ActionType; |
| 10 | +import com.instabug.library.InstabugColorTheme; |
| 11 | +import com.instabug.library.InstabugCustomTextPlaceHolder; |
| 12 | +import com.instabug.library.extendedbugreport.ExtendedBugReport; |
| 13 | +import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition; |
| 14 | + |
| 15 | +import static com.instabug.library.internal.module.InstabugLocale.ARABIC; |
| 16 | +import static com.instabug.library.internal.module.InstabugLocale.CZECH; |
| 17 | +import static com.instabug.library.internal.module.InstabugLocale.DANISH; |
| 18 | +import static com.instabug.library.internal.module.InstabugLocale.ENGLISH; |
| 19 | +import static com.instabug.library.internal.module.InstabugLocale.FRENCH; |
| 20 | +import static com.instabug.library.internal.module.InstabugLocale.GERMAN; |
| 21 | +import static com.instabug.library.internal.module.InstabugLocale.INDONESIAN; |
| 22 | +import static com.instabug.library.internal.module.InstabugLocale.ITALIAN; |
| 23 | +import static com.instabug.library.internal.module.InstabugLocale.JAPANESE; |
| 24 | +import static com.instabug.library.internal.module.InstabugLocale.KOREAN; |
| 25 | +import static com.instabug.library.internal.module.InstabugLocale.NETHERLANDS; |
| 26 | +import static com.instabug.library.internal.module.InstabugLocale.NORWEGIAN; |
| 27 | +import static com.instabug.library.internal.module.InstabugLocale.POLISH; |
| 28 | +import static com.instabug.library.internal.module.InstabugLocale.PORTUGUESE_BRAZIL; |
| 29 | +import static com.instabug.library.internal.module.InstabugLocale.PORTUGUESE_PORTUGAL; |
| 30 | +import static com.instabug.library.internal.module.InstabugLocale.RUSSIAN; |
| 31 | +import static com.instabug.library.internal.module.InstabugLocale.SIMPLIFIED_CHINESE; |
| 32 | +import static com.instabug.library.internal.module.InstabugLocale.SLOVAK; |
| 33 | +import static com.instabug.library.internal.module.InstabugLocale.SPANISH; |
| 34 | +import static com.instabug.library.internal.module.InstabugLocale.SWEDISH; |
| 35 | +import static com.instabug.library.internal.module.InstabugLocale.TRADITIONAL_CHINESE; |
| 36 | +import static com.instabug.library.internal.module.InstabugLocale.TURKISH; |
| 37 | +import static com.instabug.library.invocation.InstabugInvocationEvent.FLOATING_BUTTON; |
| 38 | +import static com.instabug.library.invocation.InstabugInvocationEvent.NONE; |
| 39 | +import static com.instabug.library.invocation.InstabugInvocationEvent.SCREENSHOT; |
| 40 | +import static com.instabug.library.invocation.InstabugInvocationEvent.SHAKE; |
| 41 | +import static com.instabug.library.invocation.InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT; |
| 42 | +import static com.instabug.library.ui.onboarding.WelcomeMessage.State.BETA; |
| 43 | +import static com.instabug.library.ui.onboarding.WelcomeMessage.State.DISABLED; |
| 44 | +import static com.instabug.library.ui.onboarding.WelcomeMessage.State.LIVE; |
| 45 | + |
| 46 | +@SuppressWarnings({"SameParameterValue", "unchecked"}) |
| 47 | +final class ArgsRegistry { |
| 48 | + |
| 49 | + static final Map<String, Object> ARGS = new HashMap<>(); |
| 50 | + |
| 51 | + static { |
| 52 | + registerInstabugInvocationEventsArgs(ARGS); |
| 53 | + registerWelcomeMessageArgs(ARGS); |
| 54 | + registerColorThemeArgs(ARGS); |
| 55 | + registerLocaleArgs(ARGS); |
| 56 | + registerInvocationModeArgs(ARGS); |
| 57 | + registerInvocationOptionsArgs(ARGS); |
| 58 | + registerCustomTextPlaceHolderKeysArgs(ARGS); |
| 59 | + registerInstabugReportTypesArgs(ARGS); |
| 60 | + registerInstabugExtendedBugReportModeArgs(ARGS); |
| 61 | + registerInstabugActionTypesArgs(ARGS); |
| 62 | + registerInstabugVideoRecordingFloatingButtonPositionArgs(ARGS); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * This acts as a safe get() method. |
| 67 | + * It returns the queried value after deserialization if AND ONLY IF it passed the following assertions: |
| 68 | + * - {@code key} is not null |
| 69 | + * - {@code key} does exist in the registry |
| 70 | + * - The value assigned to the {@code key} is not null |
| 71 | + * - The value assigned to the {@code key} is assignable from and can be casted to {@code clazz} |
| 72 | + * (i.e. Foo value = getDeserializedValue("key", Foo.class)) |
| 73 | + * |
| 74 | + * @param key the key whose associated value is to be returned |
| 75 | + * @param clazz the type in which the value should be deserialized to |
| 76 | + * @return the value deserialized if all the assertions were successful, null otherwise |
| 77 | + */ |
| 78 | + static <T> T getDeserializedValue(String key, Class<T> clazz) { |
| 79 | + if (key != null && ARGS.containsKey(key)) { |
| 80 | + Object constant = ARGS.get(key); |
| 81 | + if (constant != null && constant.getClass().isAssignableFrom(clazz)) { |
| 82 | + return (T) constant; |
| 83 | + } |
| 84 | + } |
| 85 | + return null; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * This acts as a safe get() method. |
| 90 | + * It returns the queried raw value if AND ONLY IF it passed the following assertions: |
| 91 | + * - {@code key} is not null |
| 92 | + * - {@code key} does exist in the registry |
| 93 | + * (i.e. Object value = getRawValue("key") |
| 94 | + * |
| 95 | + * @param key the key whose associated value is to be returned |
| 96 | + * @return the value if all the assertions were successful, null otherwise |
| 97 | + */ |
| 98 | + static Object getRawValue(String key) { |
| 99 | + if (key != null) { |
| 100 | + return ARGS.get(key); |
| 101 | + } |
| 102 | + return null; |
| 103 | + } |
| 104 | + |
| 105 | + static void registerInstabugInvocationEventsArgs(Map<String, Object> args) { |
| 106 | + args.put("invocationEventTwoFingersSwipe", TWO_FINGER_SWIPE_LEFT); |
| 107 | + args.put("invocationEventFloatingButton", FLOATING_BUTTON); |
| 108 | + args.put("invocationEventScreenshot", SCREENSHOT); |
| 109 | + args.put("invocationEventShake", SHAKE); |
| 110 | + args.put("invocationEventNone", NONE); |
| 111 | + } |
| 112 | + |
| 113 | + static void registerWelcomeMessageArgs(Map<String, Object> args) { |
| 114 | + args.put("WelcomeMessageMode.disabled", DISABLED); |
| 115 | + args.put("WelcomeMessageMode.live", LIVE); |
| 116 | + args.put("WelcomeMessageMode.beta", BETA); |
| 117 | + } |
| 118 | + |
| 119 | + static void registerColorThemeArgs(Map<String, Object> args) { |
| 120 | + args.put("colorThemeLight", InstabugColorTheme.InstabugColorThemeLight); |
| 121 | + args.put("colorThemeDark", InstabugColorTheme.InstabugColorThemeDark); |
| 122 | + } |
| 123 | + |
| 124 | + static void registerInvocationModeArgs(Map<String, Object> args) { |
| 125 | + args.put("invocationModeNewBug", BugReporting.ReportType.BUG); |
| 126 | + args.put("invocationModeNewFeedback", BugReporting.ReportType.FEEDBACK); |
| 127 | + } |
| 128 | + |
| 129 | + static void registerInvocationOptionsArgs(Map<String, Object> args) { |
| 130 | + args.put("commentFieldRequired", Option.COMMENT_FIELD_REQUIRED); |
| 131 | + args.put("disablePostSendingDialog", Option.DISABLE_POST_SENDING_DIALOG); |
| 132 | + args.put("emailFieldHidden", Option.EMAIL_FIELD_HIDDEN); |
| 133 | + args.put("emailFieldOptional", Option.EMAIL_FIELD_OPTIONAL); |
| 134 | + } |
| 135 | + |
| 136 | + static void registerLocaleArgs(Map<String, Object> args) { |
| 137 | + args.put("IBGLocale.chineseTraditional", new Locale(TRADITIONAL_CHINESE.getCode(), TRADITIONAL_CHINESE.getCountry())); |
| 138 | + args.put("IBGLocale.portuguesePortugal", new Locale(PORTUGUESE_PORTUGAL.getCode(), PORTUGUESE_PORTUGAL.getCountry())); |
| 139 | + args.put("IBGLocale.chineseSimplified", new Locale(SIMPLIFIED_CHINESE.getCode(), SIMPLIFIED_CHINESE.getCountry())); |
| 140 | + args.put("IBGLocale.portugueseBrazil", new Locale(PORTUGUESE_BRAZIL.getCode(), PORTUGUESE_BRAZIL.getCountry())); |
| 141 | + args.put("IBGLocale.indonesian", new Locale(INDONESIAN.getCode(), INDONESIAN.getCountry())); |
| 142 | + args.put("IBGLocale.dutch", new Locale(NETHERLANDS.getCode(), NETHERLANDS.getCountry())); |
| 143 | + args.put("IBGLocale.norwegian", new Locale(NORWEGIAN.getCode(), NORWEGIAN.getCountry())); |
| 144 | + args.put("IBGLocale.japanese", new Locale(JAPANESE.getCode(), JAPANESE.getCountry())); |
| 145 | + args.put("IBGLocale.english", new Locale(ENGLISH.getCode(), ENGLISH.getCountry())); |
| 146 | + args.put("IBGLocale.italian", new Locale(ITALIAN.getCode(), ITALIAN.getCountry())); |
| 147 | + args.put("IBGLocale.russian", new Locale(RUSSIAN.getCode(), RUSSIAN.getCountry())); |
| 148 | + args.put("IBGLocale.spanish", new Locale(SPANISH.getCode(), SPANISH.getCountry())); |
| 149 | + args.put("IBGLocale.swedish", new Locale(SWEDISH.getCode(), SWEDISH.getCountry())); |
| 150 | + args.put("IBGLocale.turkish", new Locale(TURKISH.getCode(), TURKISH.getCountry())); |
| 151 | + args.put("IBGLocale.arabic", new Locale(ARABIC.getCode(), ARABIC.getCountry())); |
| 152 | + args.put("IBGLocale.danish", new Locale(DANISH.getCode(), DANISH.getCountry())); |
| 153 | + args.put("IBGLocale.french", new Locale(FRENCH.getCode(), FRENCH.getCountry())); |
| 154 | + args.put("IBGLocale.german", new Locale(GERMAN.getCode(), GERMAN.getCountry())); |
| 155 | + args.put("IBGLocale.korean", new Locale(KOREAN.getCode(), KOREAN.getCountry())); |
| 156 | + args.put("IBGLocale.polish", new Locale(POLISH.getCode(), POLISH.getCountry())); |
| 157 | + args.put("IBGLocale.slovak", new Locale(SLOVAK.getCode(), SLOVAK.getCountry())); |
| 158 | + args.put("IBGLocale.czech", new Locale(CZECH.getCode(), CZECH.getCountry())); |
| 159 | + } |
| 160 | + |
| 161 | + static void registerCustomTextPlaceHolderKeysArgs(Map<String, Object> args) { |
| 162 | + args.put("CustomTextPlaceHolderKey.shakeHint", InstabugCustomTextPlaceHolder.Key.SHAKE_HINT); |
| 163 | + args.put("CustomTextPlaceHolderKey.swipeHint", InstabugCustomTextPlaceHolder.Key.SWIPE_HINT); |
| 164 | + args.put("CustomTextPlaceHolderKey.invalidEmailMessage", InstabugCustomTextPlaceHolder.Key.INVALID_EMAIL_MESSAGE); |
| 165 | + args.put("CustomTextPlaceHolderKey.invalidCommentMessage", InstabugCustomTextPlaceHolder.Key.INVALID_COMMENT_MESSAGE); |
| 166 | + args.put("CustomTextPlaceHolderKey.invocationHeader", InstabugCustomTextPlaceHolder.Key.INVOCATION_HEADER); |
| 167 | + args.put("CustomTextPlaceHolderKey.startChats", InstabugCustomTextPlaceHolder.Key.START_CHATS); |
| 168 | + args.put("CustomTextPlaceHolderKey.reportBug", InstabugCustomTextPlaceHolder.Key.REPORT_BUG); |
| 169 | + args.put("CustomTextPlaceHolderKey.reportFeedback", InstabugCustomTextPlaceHolder.Key.REPORT_FEEDBACK); |
| 170 | + args.put("CustomTextPlaceHolderKey.emailFieldHint", InstabugCustomTextPlaceHolder.Key.EMAIL_FIELD_HINT); |
| 171 | + args.put("CustomTextPlaceHolderKey.commentFieldHintForBugReport", InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_BUG_REPORT); |
| 172 | + args.put("CustomTextPlaceHolderKey.commentFieldHintForFeedback", InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_FEEDBACK); |
| 173 | + args.put("CustomTextPlaceHolderKey.addVoiceMessage", InstabugCustomTextPlaceHolder.Key.ADD_VOICE_MESSAGE); |
| 174 | + args.put("CustomTextPlaceHolderKey.addImageFromGallery", InstabugCustomTextPlaceHolder.Key.ADD_IMAGE_FROM_GALLERY); |
| 175 | + args.put("CustomTextPlaceHolderKey.addExtraScreenshot", InstabugCustomTextPlaceHolder.Key.ADD_EXTRA_SCREENSHOT); |
| 176 | + args.put("CustomTextPlaceHolderKey.conversationsListTitle", InstabugCustomTextPlaceHolder.Key.CONVERSATIONS_LIST_TITLE); |
| 177 | + args.put("CustomTextPlaceHolderKey.audioRecordingPermissionDenied", InstabugCustomTextPlaceHolder.Key.AUDIO_RECORDING_PERMISSION_DENIED); |
| 178 | + args.put("CustomTextPlaceHolderKey.conversationTextFieldHint", InstabugCustomTextPlaceHolder.Key.CONVERSATION_TEXT_FIELD_HINT); |
| 179 | + args.put("CustomTextPlaceHolderKey.bugReportHeader", InstabugCustomTextPlaceHolder.Key.BUG_REPORT_HEADER); |
| 180 | + args.put("CustomTextPlaceHolderKey.feedbackReportHeader", InstabugCustomTextPlaceHolder.Key.FEEDBACK_REPORT_HEADER); |
| 181 | + args.put("CustomTextPlaceHolderKey.voiceMessagePressAndHoldToRecord", InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD); |
| 182 | + args.put("CustomTextPlaceHolderKey.voiceMessageReleaseToAttach", InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_RELEASE_TO_ATTACH); |
| 183 | + args.put("CustomTextPlaceHolderKey.reportSuccessfullySent", InstabugCustomTextPlaceHolder.Key.REPORT_SUCCESSFULLY_SENT); |
| 184 | + args.put("CustomTextPlaceHolderKey.successDialogHeader", InstabugCustomTextPlaceHolder.Key.SUCCESS_DIALOG_HEADER); |
| 185 | + args.put("CustomTextPlaceHolderKey.addVideo", InstabugCustomTextPlaceHolder.Key.ADD_VIDEO); |
| 186 | + args.put("CustomTextPlaceHolderKey.betaWelcomeMessageWelcomeStepTitle", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_WELCOME_STEP_TITLE); |
| 187 | + args.put("CustomTextPlaceHolderKey.betaWelcomeMessageWelcomeStepContent", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_WELCOME_STEP_CONTENT); |
| 188 | + args.put("CustomTextPlaceHolderKey.betaWelcomeMessageHowToReportStepTitle", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_TITLE); |
| 189 | + args.put("CustomTextPlaceHolderKey.betaWelcomeMessageHowToReportStepContent", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_CONTENT); |
| 190 | + args.put("CustomTextPlaceHolderKey.betaWelcomeMessageFinishStepTitle", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_FINISH_STEP_TITLE); |
| 191 | + args.put("CustomTextPlaceHolderKey.betaWelcomeMessageFinishStepContent", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_FINISH_STEP_CONTENT); |
| 192 | + args.put("CustomTextPlaceHolderKey.liveWelcomeMessageTitle", InstabugCustomTextPlaceHolder.Key.LIVE_WELCOME_MESSAGE_TITLE); |
| 193 | + args.put("CustomTextPlaceHolderKey.liveWelcomeMessageContent", InstabugCustomTextPlaceHolder.Key.LIVE_WELCOME_MESSAGE_CONTENT); |
| 194 | + } |
| 195 | + |
| 196 | + static void registerInstabugReportTypesArgs(Map<String, Object> args) { |
| 197 | + args.put("bugReportingReportTypeBug", BugReporting.ReportType.BUG); |
| 198 | + args.put("bugReportingReportTypeFeedback", BugReporting.ReportType.FEEDBACK); |
| 199 | + } |
| 200 | + |
| 201 | + static void registerInstabugExtendedBugReportModeArgs(Map<String, Object> args) { |
| 202 | + args.put("enabledWithRequiredFields", ExtendedBugReport.State.ENABLED_WITH_REQUIRED_FIELDS); |
| 203 | + args.put("enabledWithOptionalFields", ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS); |
| 204 | + args.put("disabled", ExtendedBugReport.State.DISABLED); |
| 205 | + } |
| 206 | + |
| 207 | + static void registerInstabugActionTypesArgs(Map<String, Object> args) { |
| 208 | + args.put("ActionType.allActions", ActionType.ALL_ACTIONS); |
| 209 | + args.put("ActionType.reportBug", ActionType.REPORT_BUG); |
| 210 | + args.put("ActionType.requestNewFeature", ActionType.REQUEST_NEW_FEATURE); |
| 211 | + args.put("ActionType.addCommentToFeature", ActionType.ADD_COMMENT_TO_FEATURE); |
| 212 | + } |
| 213 | + |
| 214 | + static void registerInstabugVideoRecordingFloatingButtonPositionArgs(Map<String, Object> args) { |
| 215 | + args.put("topRight", InstabugVideoRecordingButtonPosition.TOP_RIGHT); |
| 216 | + args.put("topLeft", InstabugVideoRecordingButtonPosition.TOP_LEFT); |
| 217 | + args.put("bottomRight", InstabugVideoRecordingButtonPosition.BOTTOM_RIGHT); |
| 218 | + args.put("bottomLeft", InstabugVideoRecordingButtonPosition.BOTTOM_LEFT); |
| 219 | + } |
| 220 | +} |
0 commit comments