Skip to content

Commit e7a5003

Browse files
SalmaAliSalmaAli
authored andcommitted
✨ add sdk initialization with multiple invocation events for android
1 parent 1b4574b commit e7a5003

File tree

1 file changed

+57
-43
lines changed

1 file changed

+57
-43
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativePackage.java

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,37 @@
1414
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
1515
import com.instabug.library.visualusersteps.State;
1616
import android.graphics.Color;
17+
import android.util.Log;
1718

1819
import java.util.ArrayList;
20+
import java.util.Arrays;
1921
import java.util.Collections;
2022
import java.util.List;
2123

2224
public class RNInstabugReactnativePackage implements ReactPackage {
2325

26+
private static final String TAG = RNInstabugReactnativePackage.class.getSimpleName();
27+
2428
private Application androidApplication;
2529
private String mAndroidApplicationToken;
2630
private Instabug mInstabug;
2731
private Instabug.Builder mBuilder;
28-
private InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
32+
private ArrayList<InstabugInvocationEvent> invocationEvents = new ArrayList<>();
2933
private InstabugColorTheme instabugColorTheme = InstabugColorTheme.InstabugColorThemeLight;
3034

3135
public RNInstabugReactnativePackage(String androidApplicationToken, Application androidApplication,
32-
String invocationEventValue, String primaryColor,
36+
String[] invocationEventValues, String primaryColor,
3337
InstabugFloatingButtonEdge floatingButtonEdge, int offset) {
3438
this.androidApplication = androidApplication;
3539
this.mAndroidApplicationToken = androidApplicationToken;
3640

37-
//setting invocation event
38-
if (invocationEventValue.equals("button")) {
39-
this.invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;
40-
} else if (invocationEventValue.equals("swipe")) {
41-
this.invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
42-
43-
} else if (invocationEventValue.equals("shake")) {
44-
this.invocationEvent = InstabugInvocationEvent.SHAKE;
45-
46-
} else if (invocationEventValue.equals("screenshot")) {
47-
this.invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;
48-
49-
} else if (invocationEventValue.equals("none")) {
50-
this.invocationEvent = InstabugInvocationEvent.NONE;
51-
52-
} else {
53-
this.invocationEvent = InstabugInvocationEvent.SHAKE;
54-
}
41+
Log.d(TAG, "ARRAY: " + Arrays.toString(invocationEventValues));
5542

43+
//setting invocation event
44+
this.parseInvocationEvent(invocationEventValues);
5645

5746
mInstabug = new Instabug.Builder(this.androidApplication, this.mAndroidApplicationToken)
58-
.setInvocationEvent(this.invocationEvent)
47+
.setInvocationEvents(this.invocationEvents.toArray(new InstabugInvocationEvent[0]))
5948
.setCrashReportingState(Feature.State.ENABLED)
6049
.setReproStepsState(State.DISABLED)
6150
.build();
@@ -67,19 +56,60 @@ public RNInstabugReactnativePackage(String androidApplicationToken, Application
6756
}
6857

6958
public RNInstabugReactnativePackage(String androidApplicationToken, Application androidApplication,
70-
String invocationEventValue, String primaryColor) {
71-
new RNInstabugReactnativePackage(androidApplicationToken,androidApplication,invocationEventValue,primaryColor,
59+
String[] invocationEventValues, String primaryColor) {
60+
new RNInstabugReactnativePackage(androidApplicationToken,androidApplication,invocationEventValues,primaryColor,
7261
InstabugFloatingButtonEdge.LEFT,250);
7362
}
7463

64+
private void parseInvocationEvent(String[] invocationEventValues) {
65+
66+
for (int i = 0; i < invocationEventValues.length; i++) {
67+
if (invocationEventValues[i].equals("button")) {
68+
this.invocationEvents.add(InstabugInvocationEvent.FLOATING_BUTTON);
69+
} else if (invocationEventValues[i].equals("swipe")) {
70+
this.invocationEvents.add(InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT);
71+
72+
} else if (invocationEventValues[i].equals("shake")) {
73+
this.invocationEvents.add(InstabugInvocationEvent.SHAKE);
74+
75+
} else if (invocationEventValues[i].equals("screenshot")) {
76+
this.invocationEvents.add(InstabugInvocationEvent.SCREENSHOT_GESTURE);
77+
78+
} else if (invocationEventValues[i].equals("none")) {
79+
this.invocationEvents.add(InstabugInvocationEvent.NONE);
80+
}
81+
}
82+
83+
if (invocationEvents.isEmpty()) {
84+
invocationEvents.add(InstabugInvocationEvent.SHAKE);
85+
}
86+
}
87+
88+
@Override
89+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
90+
List<NativeModule> modules = new ArrayList<>();
91+
modules.add(new RNInstabugReactnativeModule(reactContext, this.androidApplication, this.mInstabug));
92+
return modules;
93+
}
94+
95+
public List<Class<? extends JavaScriptModule>> createJSModules() {
96+
return Collections.emptyList();
97+
}
98+
99+
@Override
100+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
101+
return Collections.emptyList();
102+
}
103+
104+
75105
public static class Builder {
76106
//FloatingButtonEdge
77107
private final String FLOATING_BUTTON_EDGE_RIGHT = "right";
78108
private final String FLOATING_BUTTON_EDGE_LEFT = "left";
79109

80110
String androidApplicationToken;
81111
Application application;
82-
String invocationEvent;
112+
String[] invocationEvents;
83113
String primaryColor;
84114
InstabugFloatingButtonEdge floatingButtonEdge;
85115
int offset;
@@ -89,8 +119,8 @@ public Builder(String androidApplicationToken, Application application) {
89119
this.application = application;
90120
}
91121

92-
public Builder setInvocationEvent(String invocationEvent) {
93-
this.invocationEvent = invocationEvent;
122+
public Builder setInvocationEvent(String... invocationEvents) {
123+
this.invocationEvents = invocationEvents;
94124
return this;
95125
}
96126

@@ -110,7 +140,7 @@ public Builder setFloatingButtonOffsetFromTop(int offset) {
110140
}
111141

112142
public RNInstabugReactnativePackage build() {
113-
return new RNInstabugReactnativePackage(androidApplicationToken,application,invocationEvent,primaryColor,floatingButtonEdge,offset);
143+
return new RNInstabugReactnativePackage(androidApplicationToken,application,invocationEvents,primaryColor,floatingButtonEdge,offset);
114144
}
115145

116146
private InstabugFloatingButtonEdge getFloatingButtonEdge(String floatingButtonEdgeValue) {
@@ -130,20 +160,4 @@ private InstabugFloatingButtonEdge getFloatingButtonEdge(String floatingButtonEd
130160
}
131161
}
132162

133-
@Override
134-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
135-
List<NativeModule> modules = new ArrayList<>();
136-
modules.add(new RNInstabugReactnativeModule(reactContext, this.androidApplication, this.mInstabug));
137-
return modules;
138-
}
139-
140-
public List<Class<? extends JavaScriptModule>> createJSModules() {
141-
return Collections.emptyList();
142-
}
143-
144-
@Override
145-
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
146-
return Collections.emptyList();
147-
}
148-
149163
}

0 commit comments

Comments
 (0)