Skip to content

Commit 1f76c2f

Browse files
SalmaAliSalmaAli
authored andcommitted
✨ add invocationModeWithOptions mapping
1 parent e781422 commit 1f76c2f

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

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

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.os.Handler;
66
import android.os.Looper;
77
import android.support.annotation.Nullable;
8+
import android.util.Log;
89

910
import com.facebook.react.bridge.Arguments;
1011
import com.facebook.react.bridge.ReactApplicationContext;
@@ -20,8 +21,11 @@
2021

2122
import com.facebook.react.modules.core.DeviceEventManagerModule;
2223
import com.instabug.bug.BugReporting;
24+
import com.instabug.bug.PromptOption;
25+
import com.instabug.bug.invocation.InvocationMode;
2326
import com.instabug.bug.invocation.InvocationOption;
2427
import com.instabug.chat.InstabugChat;
28+
import com.instabug.crash.CrashReporting;
2529
import com.instabug.featuresrequest.FeatureRequests;
2630
import com.instabug.library.ActionType;
2731
import com.instabug.library.Feature;
@@ -54,6 +58,7 @@
5458
import org.json.JSONException;
5559
import org.json.JSONObject;
5660

61+
import java.lang.reflect.Array;
5762
import java.lang.reflect.InvocationTargetException;
5863
import java.lang.reflect.Method;
5964
import java.util.ArrayList;
@@ -194,19 +199,10 @@ public String getName() {
194199
return "Instabug";
195200
}
196201

197-
@ReactMethod
198-
public void startWithToken(String androidToken, String invocationEvent) {
199-
mInstabug = new Instabug.Builder(this.androidApplication, androidToken)
200-
.setIntroMessageEnabled(false)
201-
.setInvocationEvent(getInvocationEventById(invocationEvent))
202-
.build();
203-
//init placHolders
204-
placeHolders = new InstabugCustomTextPlaceHolder();
205-
206-
}
207-
208202
/**
209-
* invoke sdk manually
203+
* invoke sdk manually with mode and options
204+
*
205+
* @param
210206
*/
211207
@ReactMethod
212208
public void invoke() {
@@ -227,25 +223,54 @@ public void run() {
227223
* invoke sdk manually with desire invocation mode
228224
*
229225
* @param invocationMode the invocation mode
226+
* @param invocationOptions the array of invocation options
230227
*/
231228
@ReactMethod
232-
public void invokeWithInvocationMode(String invocationMode) {
233-
InstabugInvocationMode mode;
229+
public void invokeWithInvocationMode(String invocationMode, ReadableArray invocationOptions) {
230+
InvocationMode mode;
231+
234232

235233
if (invocationMode.equals(INVOCATION_MODE_NEW_BUG)) {
236-
mode = InstabugInvocationMode.NEW_BUG;
234+
mode = InvocationMode.NEW_BUG;
237235
} else if (invocationMode.equals(INVOCATION_MODE_NEW_FEEDBACK)) {
238-
mode = InstabugInvocationMode.NEW_FEEDBACK;
236+
mode = InvocationMode.NEW_FEEDBACK;
239237
} else if (invocationMode.equals(INVOCATION_MODE_NEW_CHAT)) {
240-
mode = InstabugInvocationMode.NEW_CHAT;
238+
mode = InvocationMode.NEW_CHAT;
241239
} else if (invocationMode.equals(INVOCATION_MODE_CHATS_LIST)) {
242-
mode = InstabugInvocationMode.CHATS_LIST;
240+
mode = InvocationMode.CHATS_LIST;
243241
} else {
244-
mode = InstabugInvocationMode.PROMPT_OPTION;
242+
mode = InvocationMode.PROMPT_OPTION;
243+
}
244+
245+
Log.d("where is", invocationMode + " " + mode);
246+
247+
Object[] objectArray = ArrayUtil.toArray(invocationOptions);
248+
String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
249+
250+
int[] arrayOfParsedOptions = new int[stringArray.length];
251+
int i = 0;
252+
for (String option : stringArray) {
253+
switch (option) {
254+
case EMAIL_FIELD_HIDDEN:
255+
arrayOfParsedOptions[i++] = InvocationOption.EMAIL_FIELD_HIDDEN;
256+
break;
257+
case EMAIL_FIELD_OPTIONAL:
258+
arrayOfParsedOptions[i++] = InvocationOption.EMAIL_FIELD_OPTIONAL;
259+
break;
260+
case COMMENT_FIELD_REQUIRED:
261+
arrayOfParsedOptions[i++] = InvocationOption.COMMENT_FIELD_REQUIRED;
262+
break;
263+
case DISABLE_POST_SENDING_DIALOG:
264+
arrayOfParsedOptions[i++] = InvocationOption.DISABLE_POST_SENDING_DIALOG;
265+
break;
266+
default:
267+
break;
268+
}
245269
}
270+
Log.d("where is", Arrays.toString(stringArray) + " " + Arrays.toString(arrayOfParsedOptions));
246271

247272
try {
248-
mInstabug.invoke(mode);
273+
BugReporting.invoke(mode, arrayOfParsedOptions);
249274
} catch (Exception e) {
250275
e.printStackTrace();
251276
}

0 commit comments

Comments
 (0)