2
2
3
3
import android .annotation .SuppressLint ;
4
4
import android .annotation .TargetApi ;
5
- import android .os .Handler ;
6
- import android .os .Looper ;
7
5
8
6
import com .facebook .react .bridge .Arguments ;
9
7
import com .facebook .react .bridge .Callback ;
14
12
import com .facebook .react .bridge .WritableMap ;
15
13
import com .instabug .bug .BugReporting ;
16
14
import com .instabug .bug .invocation .Option ;
17
- import com .instabug .chat .Replies ;
18
15
import com .instabug .library .Feature ;
19
16
import com .instabug .library .OnSdkDismissCallback ;
20
17
import com .instabug .library .extendedbugreport .ExtendedBugReport ;
27
24
import com .instabug .reactlibrary .utils .MainThreadHandler ;
28
25
29
26
import java .util .ArrayList ;
30
- import java .util .Arrays ;
31
27
32
28
import javax .annotation .Nonnull ;
33
29
@@ -100,8 +96,9 @@ public void setExtendedBugReportMode(final String extendedBugReportMode) {
100
96
@ Override
101
97
public void run () {
102
98
try {
103
- BugReporting .setExtendedBugReportState (
104
- ArgsRegistry .getDeserializedValue (extendedBugReportMode , ExtendedBugReport .State .class ));
99
+ final ExtendedBugReport .State parsedState = ArgsRegistry .extendedBugReportStates .get (extendedBugReportMode );
100
+ if (parsedState == null ) return ;
101
+ BugReporting .setExtendedBugReportState (parsedState );
105
102
} catch (Exception e ) {
106
103
e .printStackTrace ();
107
104
}
@@ -142,8 +139,9 @@ public void setVideoRecordingFloatingButtonPosition(final String corner) {
142
139
@ Override
143
140
public void run () {
144
141
try {
145
- BugReporting .setVideoRecordingFloatingButtonPosition (
146
- ArgsRegistry .getDeserializedValue (corner , InstabugVideoRecordingButtonPosition .class ));
142
+ final InstabugVideoRecordingButtonPosition parsedPosition = ArgsRegistry .recordButtonPositions .get (corner );
143
+ if (parsedPosition == null ) return ;
144
+ BugReporting .setVideoRecordingFloatingButtonPosition (parsedPosition );
147
145
} catch (Exception e ) {
148
146
e .printStackTrace ();
149
147
}
@@ -183,28 +181,18 @@ public void run() {
183
181
*/
184
182
@ ReactMethod
185
183
public void setInvocationEvents (ReadableArray invocationEventValues ) {
186
-
187
- try {
188
- Object [] objectArray = ArrayUtil .toArray (invocationEventValues );
189
- String [] stringArray = Arrays .copyOf (objectArray , objectArray .length , String [].class );
190
- final ArrayList <InstabugInvocationEvent > parsedInvocationEvents = new ArrayList <>();
191
-
192
- for (String event : stringArray ) {
193
- parsedInvocationEvents .add (ArgsRegistry .getDeserializedValue (event , InstabugInvocationEvent .class ));
194
- }
195
- MainThreadHandler .runOnMainThread (new Runnable () {
196
- @ Override
197
- public void run () {
198
- try {
199
- BugReporting .setInvocationEvents (parsedInvocationEvents .toArray (new InstabugInvocationEvent [0 ]));
200
- } catch (Exception e ) {
201
- e .printStackTrace ();
202
- }
184
+ MainThreadHandler .runOnMainThread (new Runnable () {
185
+ @ Override
186
+ public void run () {
187
+ try {
188
+ final ArrayList <String > keys = ArrayUtil .parseReadableArrayOfStrings (invocationEventValues );
189
+ final ArrayList <InstabugInvocationEvent > parsedInvocationEvents = ArgsRegistry .invocationEvents .getAll (keys );
190
+ BugReporting .setInvocationEvents (parsedInvocationEvents .toArray (new InstabugInvocationEvent [0 ]));
191
+ } catch (Exception e ) {
192
+ e .printStackTrace ();
203
193
}
204
- });
205
- } catch (Exception e ) {
206
- e .printStackTrace ();
207
- }
194
+ }
195
+ });
208
196
}
209
197
210
198
/**
@@ -215,14 +203,17 @@ public void run() {
215
203
@ ReactMethod
216
204
public void setOptions (final ReadableArray optionValues ) {
217
205
MainThreadHandler .runOnMainThread (new Runnable () {
206
+ @ SuppressLint ("WrongConstant" )
218
207
@ Override
219
208
public void run () {
220
209
try {
221
- Object [] objectArray = ArrayUtil .toArray (optionValues );
222
- String [] stringArray = Arrays .copyOf (objectArray , objectArray .length , String [].class );
223
- for (String option : stringArray ) {
224
- BugReporting .setOptions ((int ) ArgsRegistry .getRawValue (option ));
210
+ final ArrayList <String > keys = ArrayUtil .parseReadableArrayOfStrings (optionValues );
211
+ final ArrayList <Integer > options = ArgsRegistry .invocationOptions .getAll (keys );
212
+
213
+ for (int i = 0 ; i < options .size (); i ++) {
214
+ BugReporting .setOptions (options .get (i ));
225
215
}
216
+
226
217
} catch (Exception e ) {
227
218
e .printStackTrace ();
228
219
}
@@ -267,11 +258,10 @@ public void setFloatingButtonEdge(final String floatingButtonEdge, final int flo
267
258
MainThreadHandler .runOnMainThread (new Runnable () {
268
259
@ Override
269
260
public void run () {
261
+ final InstabugFloatingButtonEdge parsedEdge = ArgsRegistry .floatingButtonEdges
262
+ .getOrDefault (floatingButtonEdge , InstabugFloatingButtonEdge .RIGHT );
270
263
BugReporting .setFloatingButtonOffset (floatingButtonOffset );
271
- if (floatingButtonEdge .equals ("left" ))
272
- BugReporting .setFloatingButtonEdge (InstabugFloatingButtonEdge .LEFT );
273
- else
274
- BugReporting .setFloatingButtonEdge (InstabugFloatingButtonEdge .RIGHT );
264
+ BugReporting .setFloatingButtonEdge (parsedEdge );
275
265
}
276
266
});
277
267
}
@@ -333,20 +323,22 @@ public void run() {
333
323
* @param types
334
324
* @see BugReporting.ReportType
335
325
*/
336
- @ SuppressLint ("WrongConstant" )
337
326
@ ReactMethod
338
327
public void setReportTypes (ReadableArray types ) {
339
- Object [] objectArray = ArrayUtil .toArray (types );
340
- String [] stringArray = Arrays .copyOf (objectArray , objectArray .length , String [].class );
341
- final int [] parsedReportTypes = new int [stringArray .length ];
342
- for (int i = 0 ; i < stringArray .length ; i ++) {
343
- parsedReportTypes [i ] = (int ) ArgsRegistry .getRawValue (stringArray [i ]);
344
- }
345
328
MainThreadHandler .runOnMainThread (new Runnable () {
329
+ @ SuppressLint ("WrongConstant" )
346
330
@ Override
347
331
public void run () {
348
332
try {
349
- BugReporting .setReportTypes (parsedReportTypes );
333
+ final ArrayList <String > keys = ArrayUtil .parseReadableArrayOfStrings (types );
334
+ final ArrayList <Integer > types = ArgsRegistry .reportTypes .getAll (keys );
335
+
336
+ final int [] typesInts = new int [types .size ()];
337
+ for (int i = 0 ; i < types .size (); i ++) {
338
+ typesInts [i ] = types .get (i );
339
+ }
340
+
341
+ BugReporting .setReportTypes (typesInts );
350
342
} catch (Exception e ) {
351
343
e .printStackTrace ();
352
344
}
@@ -366,10 +358,9 @@ public void show(final String reportType, final ReadableArray options) {
366
358
MainThreadHandler .runOnMainThread (new Runnable () {
367
359
@ Override
368
360
public void run () {
369
- if (ArgsRegistry .getDeserializedValue (reportType , Integer .class ) == null ) {
370
- return ;
371
- }
372
- BugReporting .show ((int ) ArgsRegistry .getRawValue (reportType ));
361
+ final Integer parsedReportType = ArgsRegistry .reportTypes .get (reportType );
362
+ if (parsedReportType == null ) return ;
363
+ BugReporting .show (parsedReportType );
373
364
setOptions (options );
374
365
}
375
366
});
0 commit comments