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

111 lines
4.5 KiB
Java
Raw Normal View History

2016-10-04 11:41:36 +02:00
package com.instabug.reactlibrary;
import android.app.Application;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
2017-01-23 16:58:39 +02:00
import com.facebook.react.bridge.NativeModule;
2016-12-07 20:10:44 +02:00
import com.facebook.react.bridge.ReactApplicationContext;
2017-01-23 16:58:39 +02:00
import com.facebook.react.uimanager.ViewManager;
2016-11-02 15:12:42 +02:00
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
2016-12-07 20:10:44 +02:00
import com.instabug.library.internal.module.InstabugLocale;
2016-11-02 15:12:42 +02:00
import com.instabug.library.invocation.InstabugInvocationEvent;
2016-12-07 20:10:44 +02:00
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
2016-10-04 11:41:36 +02:00
public class RNInstabugReactnativePackage implements ReactPackage {
2016-10-18 14:10:19 +02:00
Application androidApplication;
2016-11-02 15:12:42 +02:00
private String mAndroidApplicationToken;
private Instabug mInstabug;
private Instabug.Builder mBuilder;
2017-01-23 16:58:39 +02:00
private InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
2016-11-02 15:12:42 +02:00
public RNInstabugReactnativePackage(Instabug instabug) {
this.mInstabug = instabug;
}
2017-01-23 16:58:39 +02:00
public RNInstabugReactnativePackage(String androidApplicationToken, Application application) {
this(androidApplicationToken, application, "button");
2016-11-02 15:12:42 +02:00
}
2017-01-23 16:58:39 +02:00
public RNInstabugReactnativePackage(String androidApplicationToken, Application application, String invocationEventValue) {
this(androidApplicationToken, application, invocationEventValue, "light");
}
2017-01-23 16:58:39 +02:00
public RNInstabugReactnativePackage(String androidApplicationToken, Application application,
String invocationEventValue, String instabugColorThemeValue) {
this.androidApplication = application;
this.mAndroidApplicationToken = androidApplicationToken;
2017-01-23 16:58:39 +02:00
//setting invocation event
if (invocationEventValue.equals("button")) {
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
} else if (invocationEventValue.equals("swipe")) {
this.invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
} else if (invocationEventValue.equals("shake")) {
this.invocationEvent = InstabugInvocationEvent.SHAKE;
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
} else if (invocationEventValue.equals("screenshot")) {
this.invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
} else if (invocationEventValue.equals("none")) {
this.invocationEvent = InstabugInvocationEvent.NONE;
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
} else {
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
}
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
//setting instabugColorTheme
if (instabugColorThemeValue.equals("light")) {
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
} else if (instabugColorThemeValue.equals("dark")) {
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeDark;
} else {
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
}
2016-11-02 15:12:42 +02:00
2017-01-23 16:58:39 +02:00
mInstabug = new Instabug.Builder(this.androidApplication, this.mAndroidApplicationToken)
.setFloatingButtonOffsetFromTop(400)
.setTheme(this.instabugColorTheme)
.setInvocationEvent(this.invocationEvent)
.setIntroMessageEnabled(false)
.setAttachmentTypesEnabled(true, true, true, true, true)
.setShouldPlayConversationSounds(true)
.setEnableInAppNotificationSound(true)
.setEnableSystemNotificationSound(false)
.setPromptOptionsEnabled(true, true, true)
.setWillSkipScreenshotAnnotation(false)
.setFloatingButtonEdge(InstabugFloatingButtonEdge.LEFT)
.setLocale(new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry()))
.build();
2016-10-18 14:10:19 +02:00
}
2016-10-04 11:41:36 +02:00
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
2016-11-02 15:12:42 +02:00
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstabug));
2016-10-04 11:41:36 +02:00
return modules;
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
2017-01-23 16:58:39 +02:00
return Collections.emptyList();
2016-10-04 11:41:36 +02:00
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
2017-01-23 16:58:39 +02:00
return Collections.emptyList();
2016-10-04 11:41:36 +02:00
}
2016-10-20 16:24:17 +02:00
2016-10-04 11:41:36 +02:00
}