Files
instabug-reactnative/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java
T

952 lines
33 KiB
Java
Raw Normal View History

2016-10-04 11:41:36 +02:00
package com.instabug.reactlibrary;
import android.app.Application;
2017-01-23 16:58:39 +02:00
import android.net.Uri;
2016-10-04 11:41:36 +02:00
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
2017-05-11 18:48:08 +02:00
2016-10-04 11:41:36 +02:00
import com.instabug.library.Instabug;
2016-10-18 11:09:06 +02:00
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.invocation.InstabugInvocationMode;
2017-06-19 16:05:12 +02:00
import com.instabug.library.InstabugColorTheme;
2017-02-03 18:22:08 +02:00
import com.instabug.library.logging.InstabugLog;
2017-05-11 18:48:08 +02:00
import com.instabug.library.bugreporting.model.ReportCategory;
2017-06-20 03:51:55 +02:00
import com.instabug.library.InstabugCustomTextPlaceHolder;
2017-01-23 16:58:39 +02:00
2016-11-03 18:09:58 +02:00
import java.util.ArrayList;
2016-10-20 16:24:17 +02:00
import java.util.HashMap;
2016-11-03 18:09:58 +02:00
import java.util.Locale;
2016-10-20 16:24:17 +02:00
import java.util.Map;
2016-10-04 11:41:36 +02:00
2017-02-03 18:22:08 +02:00
/**
* The type Rn instabug reactnative module.
*/
2016-10-04 11:41:36 +02:00
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
//InvocationEvents
2017-01-10 13:25:09 -08:00
private final String INVOCATION_EVENT_NONE = "none";
private final String INVOCATION_EVENT_SHAKE = "shake";
private final String INVOCATION_EVENT_SCREENSHOT = "screenshot";
private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "swipe";
private final String INVOCATION_EVENT_FLOATING_BUTTON = "button";
//InvocationModes
2017-01-10 13:25:09 -08:00
private final String INVOCATION_MODE_NEW_BUG = "bug";
private final String INVOCATION_MODE_NEW_FEEDBACK = "feedback";
private final String INVOCATION_MODE_NEW_CHAT = "chat";
private final String INVOCATION_MODE_CHATS_LIST = "chats";
//locales
2017-01-10 13:25:09 -08:00
private final String LOCALE_ARABIC = "arabic";
private final String LOCALE_CHINESE_SIMPLIFIED = "chinesesimplified";
private final String LOCALE_CHINESE_TRADITIONAL = "chinesetraditional";
private final String LOCALE_CZECH = "czech";
private final String LOCALE_ENGLISH = "english";
private final String LOCALE_FRENCH = "french";
private final String LOCALE_GERMAN = "german";
private final String LOCALE_KOREAN = "korean";
private final String LOCALE_ITALIAN = "italian";
private final String LOCALE_JAPANESE = "japanese";
private final String LOCALE_POLISH = "polish";
private final String LOCALE_PORTUGUESE_BRAZIL = "portuguesebrazil";
private final String LOCALE_RUSSIAN = "russian";
private final String LOCALE_SPANISH = "spanish";
private final String LOCALE_SWEDISH = "swedish";
private final String LOCALE_TURKISH = "turkish";
2016-10-04 11:41:36 +02:00
2017-06-19 16:05:12 +02:00
//Theme colors
private final String COLOR_THEME_LIGHT = "light";
private final String COLOR_THEME_DARK = "dark";
2017-06-20 03:51:55 +02:00
//CustomTextPlaceHolders
private final String SHAKE_HINT = "shakeHint";
private final String SWIPE_HINT = "swipeHint";
private final String INVALID_EMAIL_MESSAGE = "invalidEmailMessage";
private final String INVALID_COMMENT_MESSAGE = "invalidCommentMessage";
private final String EMAIL_FIELD_HINT = "emailFieldHint";
private final String COMMENT_FIELD_HINT_FOR_BUG_REPORT = "commentFieldHintForBugReport";
private final String COMMENT_FIELD_HINT_FOR_FEEDBACK = "commentFieldHintForFeedback";
private final String INVOCATION_HEADER = "invocationHeader";
private final String START_CHATS = "talkToUs";
private final String REPORT_BUG = "reportBug";
private final String REPORT_FEEDBACK = "reportFeedback";
private final String CONVERSATIONS_LIST_TITLE = "conversationsHeaderTitle";
private final String ADD_VOICE_MESSAGE = "addVoiceMessage";
private final String ADD_IMAGE_FROM_GALLERY = "addImageFromGallery";
private final String ADD_EXTRA_SCREENSHOT = "addExtraScreenshot";
private final String ADD_VIDEO = "addVideoMessage";
private final String AUDIO_RECORDING_PERMISSION_DENIED =
"audioRecordingPermissionDeniedMessage";
private final String VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD = "recordingMessageToHoldText";
private final String VOICE_MESSAGE_RELEASE_TO_ATTACH = "recordingMessageToReleaseText";
private final String REPORT_SUCCESSFULLY_SENT = "thankYouText";
private final String VIDEO_PLAYER_TITLE = "video";
2017-06-21 01:04:59 +02:00
private final String CONVERSATION_TEXT_FIELD_HINT = "conversationTextFieldHint";
private Application androidApplication;
private Instabug mInstabug;
private InstabugInvocationEvent invocationEvent;
2017-06-20 03:51:55 +02:00
private InstabugCustomTextPlaceHolder placeHolders;
2017-02-03 18:22:08 +02:00
/**
* Instantiates a new Rn instabug reactnative module.
*
* @param reactContext the react context
* @param mInstabug the m instabug
*/
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application
androidApplication) {
2017-01-23 16:58:39 +02:00
super(reactContext);
this.androidApplication = androidApplication;
2017-01-23 16:58:39 +02:00
}
2016-10-04 11:41:36 +02:00
2017-01-23 16:58:39 +02:00
@Override
public String getName() {
return "Instabug";
}
2016-10-04 11:41:36 +02:00
@ReactMethod
public void startWithToken(String androidToken, String invocationEvent) {
mInstabug = new Instabug.Builder(this.androidApplication, androidToken)
.setIntroMessageEnabled(false)
.setInvocationEvent(getInvocationEventById(invocationEvent))
.build();
2017-06-20 03:51:55 +02:00
//init placHolders
placeHolders = new InstabugCustomTextPlaceHolder();
}
2017-01-23 16:58:39 +02:00
/**
2016-11-02 15:12:42 +02:00
* invoke sdk manually
2016-10-17 19:58:43 +02:00
*/
@ReactMethod
2017-01-23 16:58:39 +02:00
public void invoke() {
2016-11-03 18:09:58 +02:00
try {
2017-01-23 16:58:39 +02:00
mInstabug.invoke();
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
}
2017-01-23 16:58:39 +02:00
/**
2017-01-10 13:25:09 -08:00
* invoke sdk manually with desire invocation mode
2016-11-03 18:09:58 +02:00
*
2017-02-03 18:22:08 +02:00
* @param invocationMode the invocation mode
2016-11-03 18:09:58 +02:00
*/
@ReactMethod
2017-01-23 16:58:39 +02:00
public void invokeWithInvocationMode(String invocationMode) {
2017-01-10 13:25:09 -08:00
InstabugInvocationMode mode;
if (invocationMode.equals(INVOCATION_MODE_NEW_BUG)) {
2016-11-03 18:09:58 +02:00
mode = InstabugInvocationMode.NEW_BUG;
2017-01-10 13:25:09 -08:00
} else if (invocationMode.equals(INVOCATION_MODE_NEW_FEEDBACK)) {
2016-11-03 18:09:58 +02:00
mode = InstabugInvocationMode.NEW_FEEDBACK;
2017-01-23 16:58:39 +02:00
} else if (invocationMode.equals(INVOCATION_MODE_NEW_CHAT)) {
2016-11-03 18:09:58 +02:00
mode = InstabugInvocationMode.NEW_CHAT;
2017-01-23 16:58:39 +02:00
} else if (invocationMode.equals(INVOCATION_MODE_CHATS_LIST)) {
2016-11-03 18:09:58 +02:00
mode = InstabugInvocationMode.CHATS_LIST;
2017-01-10 13:25:09 -08:00
} else {
2016-11-03 18:09:58 +02:00
mode = InstabugInvocationMode.PROMPT_OPTION;
}
2017-01-10 13:25:09 -08:00
2017-01-23 16:58:39 +02:00
try {
mInstabug.invoke(mode);
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
}
2017-01-23 16:58:39 +02:00
/**
2016-11-03 18:09:58 +02:00
* Dismisses all visible Instabug views
*/
@ReactMethod
2017-01-23 16:58:39 +02:00
public void dismiss() {
2016-11-03 18:09:58 +02:00
try {
2017-01-23 16:58:39 +02:00
mInstabug.dismiss();
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
2016-10-17 19:58:43 +02:00
}
2017-01-23 16:58:39 +02:00
/**
2016-10-04 11:41:36 +02:00
* Adds tag(s) to issues before sending them
*
* @param tags
*/
@ReactMethod
2017-06-20 00:03:22 +02:00
public void appendTags(String tags) {
2016-10-04 11:41:36 +02:00
try {
String[] result = tags.split(",");
mInstabug.addTags(result);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Change Locale of Instabug UI elements(defaults to English)
*
2017-01-09 17:11:33 +02:00
* @param String instabugLocale
2016-10-04 11:41:36 +02:00
*/
@ReactMethod
2017-01-09 17:11:33 +02:00
public void changeLocale(String instabugLocale) {
2016-10-04 11:41:36 +02:00
try {
2017-01-09 17:11:33 +02:00
mInstabug.changeLocale(getLocaleByKey(instabugLocale));
2016-10-04 11:41:36 +02:00
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* The file at filePath will be uploaded along upcoming reports with the name
* fileNameWithExtension
2016-10-04 11:41:36 +02:00
*
2017-02-03 18:22:08 +02:00
* @param fileUri the file uri
* @param fileNameWithExtension the file name with extension
2016-10-04 11:41:36 +02:00
*/
@ReactMethod
public void setFileAttachment(String fileUri, String fileNameWithExtension) {
try {
Uri uri = Uri.parse(fileUri);
mInstabug.setFileAttachment(uri, fileNameWithExtension);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* If your app already acquires the user's email address and you provide it to this method,
* Instabug will pre-fill the user email in reports.
*
2017-02-03 18:22:08 +02:00
* @param userEmail the user email
2016-10-04 11:41:36 +02:00
*/
@ReactMethod
public void setUserEmail(String userEmail) {
try {
mInstabug.setUserEmail(userEmail);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets the user name that is used in the dashboard's contacts.
*
2017-02-03 18:22:08 +02:00
* @param username the username
2016-10-04 11:41:36 +02:00
*/
@ReactMethod
2017-05-07 05:05:36 +02:00
public void setUserName(String username) {
2016-10-04 11:41:36 +02:00
try {
2017-05-11 20:10:37 +02:00
mInstabug.setUsername(username);
2016-10-04 11:41:36 +02:00
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Adds specific user data that you need to be added to the reports
*
* @param userData
*/
@ReactMethod
public void setUserData(String userData) {
try {
mInstabug.setUserData(userData);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Call this method to display the discovery dialog explaining the shake gesture or the two
* finger swipe gesture, if you've enabled it.
* i.e: This method is automatically called on first run of the application
*/
@ReactMethod
public void showIntroMessage() {
try {
mInstabug.showIntroMessage();
} catch (Exception e) {
e.printStackTrace();
}
}
2016-10-20 16:24:17 +02:00
2017-01-23 16:58:39 +02:00
/**
* Set the primary color that the SDK will use to tint certain UI elements in the SDK
2016-11-03 18:09:58 +02:00
*
* @param primaryColorValue The value of the primary color ,
* whatever this color was parsed from a resource color or hex color
* or RGB color values
2016-11-03 18:09:58 +02:00
*/
@ReactMethod
public void setPrimaryColor(int primaryColor) {
2017-01-23 16:58:39 +02:00
try {
2016-11-03 18:09:58 +02:00
mInstabug.setPrimaryColor(primaryColor);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets whether attachments in bug reporting and in-app messaging are enabled or not.
2017-01-23 16:58:39 +02:00
*
* @param {boolean} screenShot A boolean to enable or disable screenshot attachments.
* @param {boolean} extraScreenShot A boolean to enable or disable extra screenshot attachments.
* @param {boolean} galleryImage A boolean to enable or disable gallery image attachments.
* @param {boolean} voiceNote A boolean to enable or disable voice note attachments.
* @param {boolean} screenRecording A boolean to enable or disable screen recording attachments.
*/
@ReactMethod
public void setAttachmentTypesEnabled(boolean screenshot, boolean extraScreenshot, boolean
galleryImage, boolean voiceNote, boolean screenRecording) {
try {
mInstabug.setAttachmentTypesEnabled(screenshot, extraScreenshot, galleryImage,
voiceNote, screenRecording);
} catch (Exception e) {
e.printStackTrace();
}
}
2016-11-03 18:09:58 +02:00
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report. All log messages are timestamped
* <br/>
* Logs aren't cleared per single application run. If you wish to reset the logs, use
* {@link #clearLog()}
2016-11-03 18:09:58 +02:00
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param message log message
*/
@ReactMethod
2017-01-19 14:42:39 +02:00
public void IBGLog(String message) {
2016-11-03 18:09:58 +02:00
try {
mInstabug.log(message);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
2017-02-03 18:22:08 +02:00
* Gets tags.
*
2016-11-03 18:09:58 +02:00
* @return all tags added using {@link #addTags(String...)}
* @see #resetTags()
*/
@ReactMethod
public ArrayList<String> getTags() {
2017-01-23 16:58:39 +02:00
ArrayList<String> tags = new ArrayList<String>();
2016-11-03 18:09:58 +02:00
try {
2017-01-23 16:58:39 +02:00
tags = mInstabug.getTags();
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
return tags;
}
2017-06-20 00:12:26 +02:00
/**
* Set the user identity.
* Instabug will pre-fill the user email in reports.
*
* @param username Username.
* @param email User's default email
*/
@ReactMethod
public void identifyUser(String userName, String userEmail) {
try {
mInstabug.identifyUser(userName, userEmail);
} catch (Exception e) {
e.printStackTrace();
}
}
2016-11-03 18:09:58 +02:00
/**
* Reset ALL tags added using {@link #addTags(String...)}
*/
@ReactMethod
public void resetTags() {
try {
mInstabug.resetTags();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
2017-02-03 18:22:08 +02:00
* Is enabled boolean.
*
2016-11-03 18:09:58 +02:00
* @return {@code true} if Instabug is enabled, {@code false} if it's disabled
* @see #enable()
* @see #disable()
*/
@ReactMethod
public boolean isEnabled() {
2017-01-23 16:58:39 +02:00
boolean isEnabled = false;
2016-11-03 18:09:58 +02:00
try {
2017-01-23 16:58:39 +02:00
isEnabled = mInstabug.isEnabled();
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
return isEnabled;
}
/**
* Enables all Instabug functionality
*/
@ReactMethod
public void enable() {
try {
mInstabug.enable();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Disables all Instabug functionality
*/
@ReactMethod
public void disable() {
try {
mInstabug.disable();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
2017-01-10 13:25:09 -08:00
* @return application token
2016-11-03 18:09:58 +02:00
*/
@ReactMethod
public String getAppToken() {
2017-01-23 16:58:39 +02:00
String appToken = "";
2016-11-03 18:09:58 +02:00
try {
2017-01-23 16:58:39 +02:00
appToken = mInstabug.getAppToken();
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
return appToken;
}
/**
* Get current unread count of messages for this user
*
* @return number of messages that are unread for this user
*/
@ReactMethod
public int getUnreadMessagesCount() {
2017-01-23 16:58:39 +02:00
int unreadMessages = 0;
2016-11-03 18:09:58 +02:00
try {
2017-01-23 16:58:39 +02:00
unreadMessages = mInstabug.getUnreadMessagesCount();
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
return unreadMessages;
}
/**
* Sets the event used to invoke Instabug SDK
2016-11-03 18:09:58 +02:00
*
2017-02-03 18:22:08 +02:00
* @param invocationEventValue the invocation event value
2016-11-03 18:09:58 +02:00
* @see InstabugInvocationEvent
*/
@ReactMethod
public void setInvocationEvent(String invocationEventValue) {
2016-11-03 18:09:58 +02:00
try {
mInstabug.changeInvocationEvent(getInvocationEventById(invocationEventValue));
} catch (Exception e) {
e.printStackTrace();
}
}
private InstabugInvocationEvent getInvocationEventById(String invocationEventValue) {
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.SHAKE;
try {
2017-01-23 16:58:39 +02:00
if (invocationEventValue.equals(INVOCATION_EVENT_FLOATING_BUTTON)) {
invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
} else if (invocationEventValue.equals(INVOCATION_EVENT_TWO_FINGERS_SWIPE)) {
invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
} else if (invocationEventValue.equals(INVOCATION_EVENT_SHAKE)) {
invocationEvent = InstabugInvocationEvent.SHAKE;
} else if (invocationEventValue.equals(INVOCATION_EVENT_SCREENSHOT)) {
invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;
} else if (invocationEventValue.equals(INVOCATION_EVENT_NONE)) {
invocationEvent = InstabugInvocationEvent.NONE;
2017-01-10 13:25:09 -08:00
}
return invocationEvent;
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
return invocationEvent;
2016-11-03 18:09:58 +02:00
}
}
/**
* Enabled/disable chat notification
*
* @param isChatNotificationEnable whether chat notification is reburied or not
*/
2017-01-10 13:25:09 -08:00
@ReactMethod
2016-11-03 18:09:58 +02:00
public void setChatNotificationEnabled(boolean isChatNotificationEnable) {
try {
2017-01-23 16:58:39 +02:00
mInstabug.setChatNotificationEnabled(isChatNotificationEnable);
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Enable/Disable debug logs from Instabug SDK
* Default state: disabled
*
* @param isDebugEnabled whether debug logs should be printed or not into LogCat
*/
@ReactMethod
public void setDebugEnabled(boolean isDebugEnabled) {
try {
2017-01-23 16:58:39 +02:00
mInstabug.setDebugEnabled(isDebugEnabled);
2016-11-03 18:09:58 +02:00
} catch (Exception e) {
e.printStackTrace();
}
}
2017-01-09 17:11:33 +02:00
2017-01-31 19:49:56 +02:00
/**
* Report a caught exception to Instabug dashboard
*
* @param throwable the exception to be reported
*/
@ReactMethod
public void reportJsException(ReadableArray stack, String message, String errorIdentifier) {
2017-01-31 19:49:56 +02:00
try {
int size = stack != null ? stack.size() : 0;
StackTraceElement[] stackTraceElements = new StackTraceElement[size];
for (int i = 0; i < size; i++) {
ReadableMap frame = stack.getMap(i);
String methodName = frame.getString("methodName");
String fileName = frame.getString("file");
int lineNumber = frame.getInt("lineNumber");
stackTraceElements[i] = new StackTraceElement(fileName, methodName, fileName,
lineNumber);
2017-01-31 19:49:56 +02:00
}
Throwable throwable = new Throwable(message);
throwable.setStackTrace(stackTraceElements);
2017-01-31 19:49:56 +02:00
if (errorIdentifier != null)
mInstabug.reportException(throwable);
else
mInstabug.reportException(throwable, errorIdentifier);
} catch (Exception e) {
e.printStackTrace();
}
}
2017-02-03 18:22:08 +02:00
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report.
* All log messages are timestamped <br/>
* Logs aren't cleared per single application run. If you wish to reset the logs,
* use {@link #clearLogs()} ()}
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param logMessage The message you would like logged
* @param level the level
* @param message the message
*/
@ReactMethod
public void log(String level, String message) {
try {
switch (level) {
case "v":
InstabugLog.v(message);
break;
case "i":
InstabugLog.i(message);
break;
case "d":
InstabugLog.d(message);
break;
case "e":
InstabugLog.e(message);
break;
case "w":
InstabugLog.w(message);
break;
case "wtf":
InstabugLog.wtf(message);
break;
default:
InstabugLog.d(message);
}
} catch (Exception e) {
e.printStackTrace();
}
}
2017-02-03 18:28:14 +02:00
/**
* Clears Instabug internal log
*/
@ReactMethod
public void clearLogs() {
try {
InstabugLog.clearLogs();
} catch (Exception e) {
e.printStackTrace();
}
}
2017-02-03 19:47:26 +02:00
/**
* Sets user attribute to overwrite it's value or create a new one if it doesn't exist.
*
* @param key the attribute
* @param value the value
*/
@ReactMethod
2017-02-04 06:10:26 +02:00
public void setUserAttribute(String key, String value) {
2017-02-03 19:47:26 +02:00
try {
mInstabug.setUserAttribute(key, value);
} catch (Exception e) {
e.printStackTrace();
}
}
2017-02-03 20:33:00 +02:00
/**
* Gets specific user attribute.
*
* @param key the attribute key as string
* @return the desired user attribute
*/
@ReactMethod
2017-02-04 06:10:26 +02:00
public String getUserAttribute(String key) {
2017-02-03 20:33:00 +02:00
try {
return mInstabug.getUserAttribute(key);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
2017-02-04 06:10:26 +02:00
/**
* Removes user attribute if exists.
*
* @param key the attribute key as string
* @see #setUserAttribute(String, String)
*/
@ReactMethod
public void removeUserAttribute(String key) {
try {
mInstabug.removeUserAttribute(key);
} catch (Exception e) {
e.printStackTrace();
}
}
2017-02-04 06:16:04 +02:00
/**
* Gets all saved user attributes.
*
* @return all user attributes as HashMap<String, String>
*/
@ReactMethod
public HashMap<String, String> getAllUserAttributes() {
return mInstabug.getAllUserAttributes();
}
2017-02-04 06:19:30 +02:00
/**
* Clears all user attributes if exists.
*/
@ReactMethod
public void clearAllUserAttributes() {
try {
mInstabug.clearAllUserAttributes();
} catch (Exception e) {
e.printStackTrace();
}
}
2017-06-19 16:05:12 +02:00
/**
* Sets InstabugSDK theme color.
*
* @param theme which is a constant String "light" or "dark"
*/
@ReactMethod
public void setColorTheme(String theme) {
try {
if (theme.equals(COLOR_THEME_LIGHT)) {
mInstabug.setTheme(InstabugColorTheme.InstabugColorThemeLight);
} else if (theme.equals(COLOR_THEME_DARK)) {
mInstabug.setTheme(InstabugColorTheme.InstabugColorThemeDark);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Allows you to show a predefined set of categories for users to choose
* from when reporting a bug or sending feedback. Selected category
* shows up on your Instabug dashboard as a tag to make filtering
* through issues easier.
*
* @param reportCategories the report categories list which is a list of ReportCategory model
*/
@ReactMethod
2017-05-15 04:16:45 +02:00
public void setReportCategories(ReadableArray categoriesTitles) {
2017-05-11 18:48:08 +02:00
try {
ArrayList<ReportCategory> bugCategories = new ArrayList<>();
2017-05-15 04:16:45 +02:00
int size = categoriesTitles != null ? categoriesTitles.size() : 0;
if (size == 0) return;
for (int i = 0; i < size; i++) {
2017-06-19 16:05:12 +02:00
bugCategories.add(ReportCategory.getInstance().withLabel(categoriesTitles
.getString(i)));
2017-05-11 18:48:08 +02:00
}
Instabug.setReportCategories(bugCategories);
} catch (Exception e) {
e.printStackTrace();
}
}
2017-06-19 16:38:23 +02:00
/**
* Sets whether users are required to enter an email address or not when
* sending reports.
* Defaults to YES.
*
* @param {boolean} isEmailFieldRequired A boolean to indicate whether email
* field is required or not.
*/
@ReactMethod
public void setEmailFieldRequired(boolean isEmailFieldRequired) {
2017-06-20 03:51:55 +02:00
try {
mInstabug.setEmailFieldRequired(isEmailFieldRequired);
} catch (java.lang.Exception exception) {
exception.printStackTrace();
}
2017-06-19 16:38:23 +02:00
}
/**
* Sets whether users are required to enter a comment or not when sending reports.
* Defaults to NO.
2017-06-20 00:03:22 +02:00
*
* @param {boolean} isCommentFieldRequired A boolean to indicate whether comment
2017-06-20 00:03:22 +02:00
* field is required or not.
*/
@ReactMethod
public void setCommentFieldRequired(boolean isCommentFieldRequired) {
2017-06-20 03:51:55 +02:00
try {
mInstabug.setCommentFieldRequired(isCommentFieldRequired);
} catch (java.lang.Exception exception) {
exception.printStackTrace();
}
}
/**
* Overrides any of the strings shown in the SDK with custom ones.
* Allows you to customize any of the strings shown to users in the SDK.
*
* @param {string} string String value to override the default one.
* @param {strings} key Key of string to override.
*/
@ReactMethod
public void setStringToKey(String string, String key) {
try {
placeHolders.set(getStringToKeyConstant(key), string);
Instabug.setCustomTextPlaceHolders(placeHolders);
} catch (java.lang.Exception exception) {
exception.printStackTrace();
}
}
2017-06-21 00:45:09 +02:00
private InstabugCustomTextPlaceHolder.Key getStringToKeyConstant(String key) {
2017-06-20 03:51:55 +02:00
String keyInLowerCase = key.toLowerCase();
2017-06-21 00:45:09 +02:00
switch (keyInLowerCase) {
2017-06-20 03:51:55 +02:00
case SHAKE_HINT:
return InstabugCustomTextPlaceHolder.Key.SHAKE_HINT;
case SWIPE_HINT:
return InstabugCustomTextPlaceHolder.Key.SWIPE_HINT;
case INVALID_EMAIL_MESSAGE:
return InstabugCustomTextPlaceHolder.Key.INVALID_EMAIL_MESSAGE;
case INVALID_COMMENT_MESSAGE:
return InstabugCustomTextPlaceHolder.Key.INVALID_COMMENT_MESSAGE;
case EMAIL_FIELD_HINT:
return InstabugCustomTextPlaceHolder.Key.EMAIL_FIELD_HINT;
case COMMENT_FIELD_HINT_FOR_BUG_REPORT:
return InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_BUG_REPORT;
case COMMENT_FIELD_HINT_FOR_FEEDBACK:
return InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_FEEDBACK;
case INVOCATION_HEADER:
return InstabugCustomTextPlaceHolder.Key.INVOCATION_HEADER;
case START_CHATS:
return InstabugCustomTextPlaceHolder.Key.START_CHATS;
case REPORT_BUG:
return InstabugCustomTextPlaceHolder.Key.REPORT_BUG;
case REPORT_FEEDBACK:
return InstabugCustomTextPlaceHolder.Key.REPORT_FEEDBACK;
case CONVERSATIONS_LIST_TITLE:
return InstabugCustomTextPlaceHolder.Key.CONVERSATIONS_LIST_TITLE;
case ADD_VOICE_MESSAGE:
return InstabugCustomTextPlaceHolder.Key.ADD_VOICE_MESSAGE;
case ADD_IMAGE_FROM_GALLERY:
return InstabugCustomTextPlaceHolder.Key.ADD_IMAGE_FROM_GALLERY;
case ADD_EXTRA_SCREENSHOT:
return InstabugCustomTextPlaceHolder.Key.ADD_EXTRA_SCREENSHOT;
case ADD_VIDEO:
return InstabugCustomTextPlaceHolder.Key.ADD_VIDEO;
case AUDIO_RECORDING_PERMISSION_DENIED:
return InstabugCustomTextPlaceHolder.Key.AUDIO_RECORDING_PERMISSION_DENIED;
case VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD:
return InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD;
case VOICE_MESSAGE_RELEASE_TO_ATTACH:
return InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_RELEASE_TO_ATTACH;
case CONVERSATION_TEXT_FIELD_HINT:
return InstabugCustomTextPlaceHolder.Key.CONVERSATION_TEXT_FIELD_HINT;
case REPORT_SUCCESSFULLY_SENT:
return InstabugCustomTextPlaceHolder.Key.REPORT_SUCCESSFULLY_SENT;
case VIDEO_PLAYER_TITLE:
return InstabugCustomTextPlaceHolder.Key.VIDEO_PLAYER_TITLE;
default:
return null;
}
}
2017-01-09 17:11:33 +02:00
private Locale getLocaleByKey(String instabugLocale) {
2017-01-23 16:58:39 +02:00
String localeInLowerCase = instabugLocale.toLowerCase();
2017-01-30 19:29:36 +02:00
switch (localeInLowerCase) {
case LOCALE_ARABIC:
return new Locale(InstabugLocale.ARABIC.getCode(), InstabugLocale.ARABIC
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_ENGLISH:
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_CZECH:
return new Locale(InstabugLocale.CZECH.getCode(), InstabugLocale.CZECH.getCountry
());
2017-01-30 19:29:36 +02:00
case LOCALE_FRENCH:
return new Locale(InstabugLocale.FRENCH.getCode(), InstabugLocale.FRENCH
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_GERMAN:
return new Locale(InstabugLocale.GERMAN.getCode(), InstabugLocale.GERMAN
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_ITALIAN:
return new Locale(InstabugLocale.ITALIAN.getCode(), InstabugLocale.ITALIAN
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_JAPANESE:
return new Locale(InstabugLocale.JAPANESE.getCode(), InstabugLocale.JAPANESE
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_POLISH:
return new Locale(InstabugLocale.POLISH.getCode(), InstabugLocale.POLISH
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_RUSSIAN:
return new Locale(InstabugLocale.RUSSIAN.getCode(), InstabugLocale.RUSSIAN
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_SPANISH:
return new Locale(InstabugLocale.SPANISH.getCode(), InstabugLocale.SPANISH
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_SWEDISH:
return new Locale(InstabugLocale.SWEDISH.getCode(), InstabugLocale.SWEDISH
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_TURKISH:
return new Locale(InstabugLocale.TURKISH.getCode(), InstabugLocale.TURKISH
.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_PORTUGUESE_BRAZIL:
return new Locale(InstabugLocale.PORTUGUESE_BRAZIL.getCode(), InstabugLocale
.PORTUGUESE_BRAZIL.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_CHINESE_SIMPLIFIED:
return new Locale(InstabugLocale.SIMPLIFIED_CHINESE.getCode(), InstabugLocale
.SIMPLIFIED_CHINESE.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_CHINESE_TRADITIONAL:
return new Locale(InstabugLocale.TRADITIONAL_CHINESE.getCode(), InstabugLocale
.TRADITIONAL_CHINESE.getCountry());
2017-01-30 19:29:36 +02:00
case LOCALE_KOREAN:
return new Locale(InstabugLocale.KOREAN.getCode(), InstabugLocale.KOREAN
.getCountry());
2017-01-30 19:29:36 +02:00
default:
return new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH
.getCountry());
2017-01-30 19:29:36 +02:00
}
2017-01-09 17:11:33 +02:00
}
2016-11-03 18:09:58 +02:00
2016-10-20 16:24:17 +02:00
@Override
public Map<String, Object> getConstants() {
2017-01-10 13:25:09 -08:00
final Map<String, Object> constants = new HashMap<>();
constants.put("invocationEventNone", INVOCATION_EVENT_NONE);
constants.put("invocationEventShake", INVOCATION_EVENT_SHAKE);
constants.put("invocationEventScreenshot", INVOCATION_EVENT_SCREENSHOT);
constants.put("invocationEventTwoFingersSwipe", INVOCATION_EVENT_TWO_FINGERS_SWIPE);
constants.put("invocationEventFloatingButton", INVOCATION_EVENT_FLOATING_BUTTON);
2017-06-19 16:05:12 +02:00
constants.put("colorThemeLight", COLOR_THEME_LIGHT);
constants.put("colorThemeDark", COLOR_THEME_DARK);
2017-01-10 13:25:09 -08:00
constants.put("invocationModeNewBug", INVOCATION_MODE_NEW_BUG);
constants.put("invocationModeNewFeedback", INVOCATION_MODE_NEW_FEEDBACK);
constants.put("invocationModeNewChat", INVOCATION_MODE_NEW_CHAT);
constants.put("invocationModeChatsList", INVOCATION_MODE_CHATS_LIST);
constants.put("localeArabic", LOCALE_ARABIC);
constants.put("localeChineseSimplified", LOCALE_CHINESE_SIMPLIFIED);
constants.put("localeChineseTraditional", LOCALE_CHINESE_TRADITIONAL);
constants.put("localeCzech", LOCALE_CZECH);
constants.put("localeEnglish", LOCALE_ENGLISH);
constants.put("localeFrench", LOCALE_FRENCH);
constants.put("localeGerman", LOCALE_FRENCH);
constants.put("localeKorean", LOCALE_KOREAN);
constants.put("localeItalian", LOCALE_ITALIAN);
constants.put("localeJapanese", LOCALE_JAPANESE);
constants.put("localePolish", LOCALE_POLISH);
constants.put("localePortugueseBrazil", LOCALE_PORTUGUESE_BRAZIL);
constants.put("localeRussian", LOCALE_RUSSIAN);
constants.put("localeSpanish", LOCALE_SPANISH);
constants.put("localeSwedish", LOCALE_SWEDISH);
constants.put("localeTurkish", LOCALE_TURKISH);
2017-06-21 01:04:59 +02:00
constants.put("shakeHint", SHAKE_HINT);
constants.put("swipeHint", SWIPE_HINT);
constants.put("invalidEmailMessage", INVALID_EMAIL_MESSAGE);
constants.put("invalidCommentMessage", INVALID_COMMENT_MESSAGE);
constants.put("emailFieldHint", EMAIL_FIELD_HINT);
constants.put("commentFieldHintForBugReport", COMMENT_FIELD_HINT_FOR_BUG_REPORT);
constants.put("commentFieldHintForFeedback", COMMENT_FIELD_HINT_FOR_FEEDBACK);
constants.put("invocationHeader", INVOCATION_HEADER);
constants.put("talkToUs", START_CHATS);
constants.put("reportBug", REPORT_BUG);
constants.put("reportFeedback", REPORT_FEEDBACK);
constants.put("conversationsHeaderTitle", CONVERSATIONS_LIST_TITLE);
constants.put("addVoiceMessage", ADD_VOICE_MESSAGE);
constants.put("addImageFromGallery", ADD_IMAGE_FROM_GALLERY);
constants.put("addExtraScreenshot", ADD_EXTRA_SCREENSHOT);
constants.put("addVideoMessage", ADD_VIDEO);
constants.put("audioRecordingPermissionDeniedMessage", AUDIO_RECORDING_PERMISSION_DENIED);
constants.put("recordingMessageToHoldText", VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD);
constants.put("recordingMessageToReleaseText", VOICE_MESSAGE_RELEASE_TO_ATTACH);
constants.put("thankYouText", REPORT_SUCCESSFULLY_SENT);
constants.put("video", VIDEO_PLAYER_TITLE);
constants.put("conversationTextFieldHint", CONVERSATION_TEXT_FIELD_HINT);
2017-06-20 03:51:55 +02:00
2017-01-10 13:25:09 -08:00
return constants;
2017-01-09 17:11:33 +02:00
}
}