Move builder to bridging file & Fix invocation event

This commit is contained in:
Hossam Hassan
2017-02-28 01:23:49 +02:00
parent e3be01e4b8
commit ddde24bedb
4 changed files with 39 additions and 87 deletions
@@ -1,6 +1,6 @@
package com.instabug.reactlibrary;
import android.app.Application;
import android.net.Uri;
import com.facebook.react.bridge.ReactApplicationContext;
@@ -25,20 +25,18 @@ import java.util.Map;
*/
public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private Instabug mInstabug;
private InstabugInvocationEvent invocationEvent;
//InvocationEvents
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
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
private final String LOCALE_ARABIC = "arabic";
private final String LOCALE_CHINESE_SIMPLIFIED = "chinesesimplified";
private final String LOCALE_CHINESE_TRADITIONAL = "chinesetraditional";
@@ -56,15 +54,19 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private final String LOCALE_SWEDISH = "swedish";
private final String LOCALE_TURKISH = "turkish";
private Application androidApplication;
private Instabug mInstabug;
private InstabugInvocationEvent invocationEvent;
/**
* Instantiates a new Rn instabug reactnative module.
*
* @param reactContext the react context
* @param mInstabug the m instabug
*/
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Instabug mInstabug) {
public RNInstabugReactnativeModule(ReactApplicationContext reactContext, Application androidApplication) {
super(reactContext);
this.mInstabug = mInstabug;
this.androidApplication = androidApplication;
}
@Override
@@ -72,6 +74,14 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
return "Instabug";
}
@ReactMethod
public void startWithToken(String androidToken, String invocationEvent) {
mInstabug = new Instabug.Builder(this.androidApplication, androidToken)
.setIntroMessageEnabled(false)
.setInvocationEvent(getInvocationEventById(invocationEvent))
.build();
}
/**
* invoke sdk manually
*/
@@ -155,7 +165,6 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
}
}
/**
* The file at filePath will be uploaded along upcoming reports with the name fileNameWithExtension
*
@@ -394,9 +403,16 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
*/
@ReactMethod
public void setInvocationEvent(String invocationEventValue) {
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
try {
//setting invocation event
mInstabug.changeInvocationEvent(getInvocationEventById(invocationEventValue));
} catch (Exception e) {
e.printStackTrace();
}
}
private InstabugInvocationEvent getInvocationEventById(String invocationEventValue) {
InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.SHAKE;
try {
if (invocationEventValue.equals(INVOCATION_EVENT_FLOATING_BUTTON)) {
invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
} else if (invocationEventValue.equals(INVOCATION_EVENT_TWO_FINGERS_SWIPE)) {
@@ -409,11 +425,11 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
invocationEvent = InstabugInvocationEvent.NONE;
}
mInstabug.changeInvocationEvent(invocationEvent);
return invocationEvent;
} catch (Exception e) {
e.printStackTrace();
return invocationEvent;
}
}
/**
@@ -1,4 +1,3 @@
package com.instabug.reactlibrary;
import android.app.Application;
@@ -10,91 +9,45 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class RNInstabugReactnativePackage implements ReactPackage {
Application androidApplication;
private Application androidApplication;
private String mAndroidApplicationToken;
private Instabug mInstabug;
private Instabug.Builder mBuilder;
private InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
public RNInstabugReactnativePackage(Instabug instabug) {
this.mInstabug = instabug;
public RNInstabugReactnativePackage(Application androidApplication) {
this.androidApplication = androidApplication;
}
@Deprecated
public RNInstabugReactnativePackage(String androidApplicationToken, Application application) {
this(androidApplicationToken, application, "button");
}
public RNInstabugReactnativePackage(String androidApplicationToken, Application application, String invocationEventValue) {
@Deprecated
public RNInstabugReactnativePackage(String androidApplicationToken, Application application
String invocationEventValue) {
this(androidApplicationToken, application, invocationEventValue, "light");
}
@Deprecated
public RNInstabugReactnativePackage(String androidApplicationToken, Application application,
String invocationEventValue, String instabugColorThemeValue) {
this.androidApplication = application;
this.mAndroidApplicationToken = androidApplicationToken;
//setting invocation event
if (invocationEventValue.equals("button")) {
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
} else if (invocationEventValue.equals("swipe")) {
this.invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
} else if (invocationEventValue.equals("shake")) {
this.invocationEvent = InstabugInvocationEvent.SHAKE;
} else if (invocationEventValue.equals("screenshot")) {
this.invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;
} else if (invocationEventValue.equals("none")) {
this.invocationEvent = InstabugInvocationEvent.NONE;
} else {
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
}
//setting instabugColorTheme
if (instabugColorThemeValue.equals("light")) {
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
} else if (instabugColorThemeValue.equals("dark")) {
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeDark;
} else {
this.instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
}
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();
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RNInstabugReactnativeModule(reactContext, this.mInstabug));
modules.add(new RNInstabugReactnativeModule(reactContext, this.androidApplication));
return modules;
}