22
33import android .annotation .SuppressLint ;
44import android .annotation .TargetApi ;
5- import android .os .Handler ;
6- import android .os .Looper ;
75
86import com .facebook .react .bridge .Arguments ;
97import com .facebook .react .bridge .Callback ;
1412import com .facebook .react .bridge .WritableMap ;
1513import com .instabug .bug .BugReporting ;
1614import com .instabug .bug .invocation .Option ;
17- import com .instabug .chat .Replies ;
1815import com .instabug .library .Feature ;
1916import com .instabug .library .OnSdkDismissCallback ;
2017import com .instabug .library .extendedbugreport .ExtendedBugReport ;
2724import com .instabug .reactlibrary .utils .MainThreadHandler ;
2825
2926import java .util .ArrayList ;
30- import java .util .Arrays ;
3127
3228import javax .annotation .Nonnull ;
3329
@@ -100,8 +96,9 @@ public void setExtendedBugReportMode(final String extendedBugReportMode) {
10096 @ Override
10197 public void run () {
10298 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 );
105102 } catch (Exception e ) {
106103 e .printStackTrace ();
107104 }
@@ -142,8 +139,9 @@ public void setVideoRecordingFloatingButtonPosition(final String corner) {
142139 @ Override
143140 public void run () {
144141 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 );
147145 } catch (Exception e ) {
148146 e .printStackTrace ();
149147 }
@@ -183,28 +181,18 @@ public void run() {
183181 */
184182 @ ReactMethod
185183 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 ();
203193 }
204- });
205- } catch (Exception e ) {
206- e .printStackTrace ();
207- }
194+ }
195+ });
208196 }
209197
210198 /**
@@ -215,14 +203,17 @@ public void run() {
215203 @ ReactMethod
216204 public void setOptions (final ReadableArray optionValues ) {
217205 MainThreadHandler .runOnMainThread (new Runnable () {
206+ @ SuppressLint ("WrongConstant" )
218207 @ Override
219208 public void run () {
220209 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 ));
225215 }
216+
226217 } catch (Exception e ) {
227218 e .printStackTrace ();
228219 }
@@ -267,11 +258,10 @@ public void setFloatingButtonEdge(final String floatingButtonEdge, final int flo
267258 MainThreadHandler .runOnMainThread (new Runnable () {
268259 @ Override
269260 public void run () {
261+ final InstabugFloatingButtonEdge parsedEdge = ArgsRegistry .floatingButtonEdges
262+ .getOrDefault (floatingButtonEdge , InstabugFloatingButtonEdge .RIGHT );
270263 BugReporting .setFloatingButtonOffset (floatingButtonOffset );
271- if (floatingButtonEdge .equals ("left" ))
272- BugReporting .setFloatingButtonEdge (InstabugFloatingButtonEdge .LEFT );
273- else
274- BugReporting .setFloatingButtonEdge (InstabugFloatingButtonEdge .RIGHT );
264+ BugReporting .setFloatingButtonEdge (parsedEdge );
275265 }
276266 });
277267 }
@@ -333,20 +323,22 @@ public void run() {
333323 * @param types
334324 * @see BugReporting.ReportType
335325 */
336- @ SuppressLint ("WrongConstant" )
337326 @ ReactMethod
338327 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- }
345328 MainThreadHandler .runOnMainThread (new Runnable () {
329+ @ SuppressLint ("WrongConstant" )
346330 @ Override
347331 public void run () {
348332 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 );
350342 } catch (Exception e ) {
351343 e .printStackTrace ();
352344 }
@@ -366,10 +358,9 @@ public void show(final String reportType, final ReadableArray options) {
366358 MainThreadHandler .runOnMainThread (new Runnable () {
367359 @ Override
368360 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 );
373364 setOptions (options );
374365 }
375366 });
0 commit comments