14
14
import com .facebook .react .bridge .WritableMap ;
15
15
import com .instabug .bug .BugReporting ;
16
16
import com .instabug .bug .invocation .Option ;
17
+ import com .instabug .chat .Replies ;
17
18
import com .instabug .library .Feature ;
18
19
import com .instabug .library .OnSdkDismissCallback ;
19
20
import com .instabug .library .extendedbugreport .ExtendedBugReport ;
23
24
import com .instabug .library .invocation .util .InstabugVideoRecordingButtonPosition ;
24
25
import com .instabug .reactlibrary .utils .ArrayUtil ;
25
26
import com .instabug .reactlibrary .utils .InstabugUtil ;
27
+ import com .instabug .reactlibrary .utils .MainThreadHandler ;
26
28
27
29
import java .util .ArrayList ;
28
30
import java .util .Arrays ;
@@ -47,7 +49,7 @@ public String getName() {
47
49
*/
48
50
@ ReactMethod
49
51
public void setEnabled (final boolean isEnabled ) {
50
- new Handler ( Looper . getMainLooper ()). post (new Runnable () {
52
+ MainThreadHandler . runOnMainThread (new Runnable () {
51
53
@ Override
52
54
public void run () {
53
55
try {
@@ -73,12 +75,17 @@ public void run() {
73
75
*/
74
76
@ TargetApi (21 )
75
77
@ ReactMethod
76
- public void setAutoScreenRecordingEnabled (boolean autoScreenRecordingEnabled ) {
77
- try {
78
- BugReporting .setAutoScreenRecordingEnabled (autoScreenRecordingEnabled );
79
- } catch (Exception e ) {
80
- e .printStackTrace ();
81
- }
78
+ public void setAutoScreenRecordingEnabled (final boolean autoScreenRecordingEnabled ) {
79
+ MainThreadHandler .runOnMainThread (new Runnable () {
80
+ @ Override
81
+ public void run () {
82
+ try {
83
+ BugReporting .setAutoScreenRecordingEnabled (autoScreenRecordingEnabled );
84
+ } catch (Exception e ) {
85
+ e .printStackTrace ();
86
+ }
87
+ }
88
+ });
82
89
}
83
90
84
91
/**
@@ -88,30 +95,40 @@ public void setAutoScreenRecordingEnabled(boolean autoScreenRecordingEnabled) {
88
95
* @param extendedBugReportMode
89
96
*/
90
97
@ ReactMethod
91
- public void setExtendedBugReportMode (String extendedBugReportMode ) {
92
- try {
93
- BugReporting .setExtendedBugReportState (
94
- ArgsRegistry .getDeserializedValue (extendedBugReportMode , ExtendedBugReport .State .class ));
95
- } catch (Exception e ) {
96
- e .printStackTrace ();
97
- }
98
+ public void setExtendedBugReportMode (final String extendedBugReportMode ) {
99
+ MainThreadHandler .runOnMainThread (new Runnable () {
100
+ @ Override
101
+ public void run () {
102
+ try {
103
+ BugReporting .setExtendedBugReportState (
104
+ ArgsRegistry .getDeserializedValue (extendedBugReportMode , ExtendedBugReport .State .class ));
105
+ } catch (Exception e ) {
106
+ e .printStackTrace ();
107
+ }
108
+ }
109
+ });
98
110
}
99
111
100
112
/**
101
113
* Enables or disables view hierarchy in the dashboard.
102
114
* @param isEnabled boolean indicating enabled or disabled.
103
115
*/
104
116
@ ReactMethod
105
- public void setViewHierarchyEnabled (boolean isEnabled ) {
106
- try {
107
- if (isEnabled ) {
108
- BugReporting .setViewHierarchyState (Feature .State .ENABLED );
109
- } else {
110
- BugReporting .setViewHierarchyState (Feature .State .DISABLED );
117
+ public void setViewHierarchyEnabled (final boolean isEnabled ) {
118
+ MainThreadHandler .runOnMainThread (new Runnable () {
119
+ @ Override
120
+ public void run () {
121
+ try {
122
+ if (isEnabled ) {
123
+ BugReporting .setViewHierarchyState (Feature .State .ENABLED );
124
+ } else {
125
+ BugReporting .setViewHierarchyState (Feature .State .DISABLED );
126
+ }
127
+ } catch (Exception e ) {
128
+ e .printStackTrace ();
129
+ }
111
130
}
112
- } catch (Exception e ) {
113
- e .printStackTrace ();
114
- }
131
+ });
115
132
}
116
133
117
134
/**
@@ -120,13 +137,18 @@ public void setViewHierarchyEnabled(boolean isEnabled) {
120
137
* @param corner corner to stick the video recording floating button to
121
138
*/
122
139
@ ReactMethod
123
- public void setVideoRecordingFloatingButtonPosition (String corner ) {
124
- try {
125
- BugReporting .setVideoRecordingFloatingButtonPosition (
126
- ArgsRegistry .getDeserializedValue (corner , InstabugVideoRecordingButtonPosition .class ));
127
- } catch (Exception e ) {
128
- e .printStackTrace ();
129
- }
140
+ public void setVideoRecordingFloatingButtonPosition (final String corner ) {
141
+ MainThreadHandler .runOnMainThread (new Runnable () {
142
+ @ Override
143
+ public void run () {
144
+ try {
145
+ BugReporting .setVideoRecordingFloatingButtonPosition (
146
+ ArgsRegistry .getDeserializedValue (corner , InstabugVideoRecordingButtonPosition .class ));
147
+ } catch (Exception e ) {
148
+ e .printStackTrace ();
149
+ }
150
+ }
151
+ });
130
152
}
131
153
132
154
/**
@@ -138,14 +160,19 @@ public void setVideoRecordingFloatingButtonPosition(String corner) {
138
160
* @param {boolean} screenRecording A boolean to enable or disable screen recording attachments.
139
161
*/
140
162
@ ReactMethod
141
- public void setEnabledAttachmentTypes (boolean screenshot , boolean extraScreenshot , boolean
142
- galleryImage , boolean screenRecording ) {
143
- try {
144
- BugReporting .setAttachmentTypesEnabled (screenshot , extraScreenshot , galleryImage ,
145
- screenRecording );
146
- } catch (Exception e ) {
147
- e .printStackTrace ();
148
- }
163
+ public void setEnabledAttachmentTypes (final boolean screenshot , final boolean extraScreenshot , final boolean
164
+ galleryImage , final boolean screenRecording ) {
165
+ MainThreadHandler .runOnMainThread (new Runnable () {
166
+ @ Override
167
+ public void run () {
168
+ try {
169
+ BugReporting .setAttachmentTypesEnabled (screenshot , extraScreenshot , galleryImage ,
170
+ screenRecording );
171
+ } catch (Exception e ) {
172
+ e .printStackTrace ();
173
+ }
174
+ }
175
+ });
149
176
}
150
177
151
178
/**
@@ -157,7 +184,7 @@ public void setEnabledAttachmentTypes(boolean screenshot, boolean extraScreensho
157
184
*/
158
185
@ ReactMethod
159
186
public void setInvocationEvent (final String invocationEventValue ) {
160
- new Handler ( Looper . getMainLooper ()). post (new Runnable () {
187
+ MainThreadHandler . runOnMainThread (new Runnable () {
161
188
@ Override
162
189
public void run () {
163
190
try {
@@ -187,7 +214,7 @@ public void setInvocationEvents(ReadableArray invocationEventValues) {
187
214
for (String event : stringArray ) {
188
215
parsedInvocationEvents .add (ArgsRegistry .getDeserializedValue (event , InstabugInvocationEvent .class ));
189
216
}
190
- new Handler ( Looper . getMainLooper ()). post (new Runnable () {
217
+ MainThreadHandler . runOnMainThread (new Runnable () {
191
218
@ Override
192
219
public void run () {
193
220
try {
@@ -208,18 +235,21 @@ public void run() {
208
235
* @param optionValues the invocation option value
209
236
*/
210
237
@ ReactMethod
211
- public void setOptions (ReadableArray optionValues ) {
212
- try {
213
-
214
- Object [] objectArray = ArrayUtil .toArray (optionValues );
215
- String [] stringArray = Arrays .copyOf (objectArray , objectArray .length , String [].class );
216
- for (String option : stringArray ) {
217
- BugReporting .setOptions ((int ) ArgsRegistry .getRawValue (option ));
238
+ public void setOptions (final ReadableArray optionValues ) {
239
+ MainThreadHandler .runOnMainThread (new Runnable () {
240
+ @ Override
241
+ public void run () {
242
+ try {
243
+ Object [] objectArray = ArrayUtil .toArray (optionValues );
244
+ String [] stringArray = Arrays .copyOf (objectArray , objectArray .length , String [].class );
245
+ for (String option : stringArray ) {
246
+ BugReporting .setOptions ((int ) ArgsRegistry .getRawValue (option ));
247
+ }
248
+ } catch (Exception e ) {
249
+ e .printStackTrace ();
250
+ }
218
251
}
219
-
220
- } catch (Exception e ) {
221
- e .printStackTrace ();
222
- }
252
+ });
223
253
}
224
254
225
255
/**
@@ -232,16 +262,21 @@ public void setOptions(ReadableArray optionValues) {
232
262
*/
233
263
@ ReactMethod
234
264
public void setOnInvokeHandler (final Callback onInvokeHandler ) {
235
- try {
236
- BugReporting .setOnInvokeCallback (new OnInvokeCallback () {
237
- @ Override
238
- public void onInvoke () {
239
- InstabugUtil .sendEvent (getReactApplicationContext (), Constants .IBG_PRE_INVOCATION_HANDLER , null );
265
+ MainThreadHandler .runOnMainThread (new Runnable () {
266
+ @ Override
267
+ public void run () {
268
+ try {
269
+ BugReporting .setOnInvokeCallback (new OnInvokeCallback () {
270
+ @ Override
271
+ public void onInvoke () {
272
+ InstabugUtil .sendEvent (getReactApplicationContext (), Constants .IBG_PRE_INVOCATION_HANDLER , null );
273
+ }
274
+ });
275
+ } catch (java .lang .Exception exception ) {
276
+ exception .printStackTrace ();
240
277
}
241
- });
242
- } catch (java .lang .Exception exception ) {
243
- exception .printStackTrace ();
244
- }
278
+ }
279
+ });
245
280
}
246
281
247
282
/**
@@ -251,7 +286,7 @@ public void onInvoke() {
251
286
*/
252
287
@ ReactMethod
253
288
public void setFloatingButtonEdge (final String floatingButtonEdge , final int floatingButtonOffset ) {
254
- new Handler ( Looper . getMainLooper ()). post (new Runnable () {
289
+ MainThreadHandler . runOnMainThread (new Runnable () {
255
290
@ Override
256
291
public void run () {
257
292
BugReporting .setFloatingButtonOffset (floatingButtonOffset );
@@ -273,19 +308,24 @@ public void run() {
273
308
*/
274
309
@ ReactMethod
275
310
public void setOnSDKDismissedHandler (final Callback handler ) {
276
- try {
277
- BugReporting .setOnDismissCallback (new OnSdkDismissCallback () {
278
- @ Override
279
- public void call (DismissType dismissType , ReportType reportType ) {
280
- WritableMap params = Arguments .createMap ();
281
- params .putString ("dismissType" , dismissType .toString ());
282
- params .putString ("reportType" , reportType .toString ());
283
- InstabugUtil .sendEvent (getReactApplicationContext (), Constants .IBG_POST_INVOCATION_HANDLER , params );
311
+ MainThreadHandler .runOnMainThread (new Runnable () {
312
+ @ Override
313
+ public void run () {
314
+ try {
315
+ BugReporting .setOnDismissCallback (new OnSdkDismissCallback () {
316
+ @ Override
317
+ public void call (DismissType dismissType , ReportType reportType ) {
318
+ WritableMap params = Arguments .createMap ();
319
+ params .putString ("dismissType" , dismissType .toString ());
320
+ params .putString ("reportType" , reportType .toString ());
321
+ InstabugUtil .sendEvent (getReactApplicationContext (), Constants .IBG_POST_INVOCATION_HANDLER , params );
322
+ }
323
+ });
324
+ } catch (java .lang .Exception exception ) {
325
+ exception .printStackTrace ();
284
326
}
285
- });
286
- } catch (java .lang .Exception exception ) {
287
- exception .printStackTrace ();
288
- }
327
+ }
328
+ });
289
329
}
290
330
291
331
/**
@@ -297,12 +337,17 @@ public void call(DismissType dismissType, ReportType reportType) {
297
337
* @param androidThreshold Threshold for android devices.
298
338
*/
299
339
@ ReactMethod
300
- public void setShakingThresholdForAndroid (int androidThreshold ) {
301
- try {
302
- BugReporting .setShakingThreshold (androidThreshold );
303
- } catch (Exception e ) {
304
- e .printStackTrace ();
305
- }
340
+ public void setShakingThresholdForAndroid (final int androidThreshold ) {
341
+ MainThreadHandler .runOnMainThread (new Runnable () {
342
+ @ Override
343
+ public void run () {
344
+ try {
345
+ BugReporting .setShakingThreshold (androidThreshold );
346
+ } catch (Exception e ) {
347
+ e .printStackTrace ();
348
+ }
349
+ }
350
+ });
306
351
}
307
352
308
353
/**
@@ -319,7 +364,7 @@ public void setReportTypes(ReadableArray types) {
319
364
for (int i = 0 ; i < stringArray .length ; i ++) {
320
365
parsedReportTypes [i ] = (int ) ArgsRegistry .getRawValue (stringArray [i ]);
321
366
}
322
- new Handler ( Looper . getMainLooper ()). post (new Runnable () {
367
+ MainThreadHandler . runOnMainThread (new Runnable () {
323
368
@ Override
324
369
public void run () {
325
370
try {
@@ -339,13 +384,17 @@ public void run() {
339
384
* @see Option
340
385
*/
341
386
@ ReactMethod
342
- public void show (String reportType , ReadableArray options ) {
343
- if (ArgsRegistry .getDeserializedValue (reportType , Integer .class ) == null ) {
344
- return ;
345
- }
346
- BugReporting .show ((int ) ArgsRegistry .getRawValue (reportType ));
347
- setOptions (options );
348
-
387
+ public void show (final String reportType , final ReadableArray options ) {
388
+ MainThreadHandler .runOnMainThread (new Runnable () {
389
+ @ Override
390
+ public void run () {
391
+ if (ArgsRegistry .getDeserializedValue (reportType , Integer .class ) == null ) {
392
+ return ;
393
+ }
394
+ BugReporting .show ((int ) ArgsRegistry .getRawValue (reportType ));
395
+ setOptions (options );
396
+ }
397
+ });
349
398
}
350
399
351
400
0 commit comments