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

189 lines
5.1 KiB
Java
Raw Normal View History

2016-10-04 11:41:36 +02:00
package com.instabug.reactlibrary;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
2016-10-18 12:15:36 +02:00
import android.app.Application;
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.InstabugColorTheme;
import com.instabug.library.InstabugTrackingDelegate;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.invocation.InstabugInvocationMode;
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
2016-10-04 11:41:36 +02:00
import java.util.Locale;
2016-10-20 16:24:17 +02:00
import java.util.HashMap;
2016-10-04 11:41:36 +02:00
import android.net.Uri;
2016-10-20 16:24:17 +02:00
import java.util.Map;
2016-10-04 11:41:36 +02:00
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private Instabug mInstabug;
2016-11-02 15:12:42 +02:00
private InstabugInvocationEvent invocationEvent;
2016-10-04 11:41:36 +02:00
2016-11-02 15:12:42 +02:00
public RNInstabugReactnativeModule(ReactApplicationContext reactContext,Instabug mInstabug) {
2016-10-04 11:41:36 +02:00
super(reactContext);
2016-11-02 15:12:42 +02:00
this.mInstabug = mInstabug;
2016-10-04 11:41:36 +02:00
}
@Override
public String getName() {
2016-10-20 16:24:17 +02:00
return "Instabug";
2016-10-04 11:41:36 +02:00
}
2016-11-02 15:12:42 +02:00
/**
* invoke sdk manually
*
* @param tags
2016-10-17 19:58:43 +02:00
*/
@ReactMethod
2016-11-02 15:12:42 +02:00
public void invoke()
2016-10-17 19:58:43 +02:00
{
2016-11-02 15:12:42 +02:00
mInstabug.invoke();
2016-10-17 19:58:43 +02:00
}
2016-10-04 11:41:36 +02:00
/**
* Adds tag(s) to issues before sending them
*
* @param tags
*/
@ReactMethod
public void addTags(String tags) {
try {
String[] result = tags.split(",");
mInstabug.resetTags(); //clear last commit tags
mInstabug.addTags(result);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Change Locale of Instabug UI elements(defaults to English)
*
* @param languageTag
*/
@ReactMethod
public void changeLocale(String languageTag) {
try {
switch (languageTag) {
case "CHINA":
case "CHINESE":
case "PRC":
case "SIMPLIFIED_CHINESE":
mInstabug.changeLocale(Locale.CHINESE);
break;
case "TAIWAN":
case "TRADITIONAL_CHINESE":
mInstabug.changeLocale(Locale.TAIWAN);
break;
case "ENGLISH":
mInstabug.changeLocale(Locale.ENGLISH);
break;
case "UK":
mInstabug.changeLocale(Locale.UK);
break;
case "US":
mInstabug.changeLocale(Locale.US);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
@ReactMethod
public void report(String value) {
2016-10-17 20:43:28 +02:00
InstabugInvocationMode mode = InstabugInvocationMode.PROMPT_OPTION;
2016-10-04 11:41:36 +02:00
if (value.equals("bug")) {
2016-10-17 20:43:28 +02:00
mode = InstabugInvocationMode.NEW_BUG;
2016-10-04 11:41:36 +02:00
} else if (value.equals("feedback")) {
2016-10-17 20:43:28 +02:00
mode = InstabugInvocationMode.NEW_FEEDBACK;
2016-10-04 11:41:36 +02:00
}
mInstabug.invoke(mode);
}
/**
* The file at filePath will be uploaded along upcoming reports with the name fileNameWithExtension
*
* @param fileUri
* @param fileNameWithExtension
*/
@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.
*
* @param userEmail
*/
@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.
*
* @param username
*/
@ReactMethod
public void setUsername(String username) {
try {
mInstabug.setUsername(username);
} 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
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
return constants;
}
2016-10-04 11:41:36 +02:00
}