22
33import com .onesignal .OneSignal ;
44import com .onesignal .debug .internal .logging .Logging ;
5- import org .json .JSONException ;
6-
7- import com .onesignal .inAppMessages .IInAppMessageClickListener ;
85import com .onesignal .inAppMessages .IInAppMessageClickEvent ;
9- import com .onesignal .inAppMessages .IInAppMessageLifecycleListener ;
10- import com .onesignal .inAppMessages .IInAppMessageWillDisplayEvent ;
6+ import com .onesignal .inAppMessages .IInAppMessageClickListener ;
7+ import com .onesignal .inAppMessages .IInAppMessageDidDismissEvent ;
118import com .onesignal .inAppMessages .IInAppMessageDidDisplayEvent ;
9+ import com .onesignal .inAppMessages .IInAppMessageLifecycleListener ;
1210import com .onesignal .inAppMessages .IInAppMessageWillDismissEvent ;
13- import com .onesignal .inAppMessages .IInAppMessageDidDismissEvent ;
14- import java .util .Collection ;
15- import java .util .Map ;
16-
11+ import com .onesignal .inAppMessages .IInAppMessageWillDisplayEvent ;
1712import io .flutter .plugin .common .BinaryMessenger ;
1813import io .flutter .plugin .common .MethodCall ;
1914import io .flutter .plugin .common .MethodChannel ;
2015import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
2116import io .flutter .plugin .common .MethodChannel .Result ;
17+ import java .util .Collection ;
18+ import java .util .Map ;
19+ import org .json .JSONException ;
2220
23- public class OneSignalInAppMessages extends FlutterMessengerResponder implements MethodCallHandler ,
24- IInAppMessageClickListener , IInAppMessageLifecycleListener {
21+ public class OneSignalInAppMessages extends FlutterMessengerResponder
22+ implements MethodCallHandler , IInAppMessageClickListener , IInAppMessageLifecycleListener {
2523
2624 static void registerWith (BinaryMessenger messenger ) {
2725 OneSignalInAppMessages sharedInstance = new OneSignalInAppMessages ();
2826
2927 sharedInstance .messenger = messenger ;
3028 sharedInstance .channel = new MethodChannel (messenger , "OneSignal#inappmessages" );
31- sharedInstance .channel .setMethodCallHandler (sharedInstance );
29+ sharedInstance .channel .setMethodCallHandler (sharedInstance );
3230 }
3331
3432 @ Override
3533 public void onMethodCall (MethodCall call , Result result ) {
36- if (call .method .contentEquals ("OneSignal#addTrigger" ))
37- this .addTriggers (call , result );
38- else if (call .method .contentEquals ("OneSignal#addTriggers" ))
39- this .addTriggers (call , result );
40- else if (call .method .contentEquals ("OneSignal#removeTrigger" ))
41- this .removeTrigger (call , result );
42- else if (call .method .contentEquals ("OneSignal#removeTriggers" ))
43- this .removeTriggers (call , result );
44- else if (call .method .contentEquals ("OneSignal#clearTriggers" ))
45- this .clearTriggers (call , result );
34+ if (call .method .contentEquals ("OneSignal#addTrigger" )) this .addTriggers (call , result );
35+ else if (call .method .contentEquals ("OneSignal#addTriggers" )) this .addTriggers (call , result );
36+ else if (call .method .contentEquals ("OneSignal#removeTrigger" )) this .removeTrigger (call , result );
37+ else if (call .method .contentEquals ("OneSignal#removeTriggers" )) this .removeTriggers (call , result );
38+ else if (call .method .contentEquals ("OneSignal#clearTriggers" )) this .clearTriggers (call , result );
4639 else if (call .method .contentEquals ("OneSignal#arePaused" ))
4740 replySuccess (result , OneSignal .getInAppMessages ().getPaused ());
48- else if (call .method .contentEquals ("OneSignal#paused" ))
49- this .paused (call , result );
50- else if (call .method .contentEquals ("OneSignal#lifecycleInit" ))
51- this .lifecycleInit (result );
52- else
53- replyNotImplemented (result );
41+ else if (call .method .contentEquals ("OneSignal#paused" )) this .paused (call , result );
42+ else if (call .method .contentEquals ("OneSignal#lifecycleInit" )) this .lifecycleInit (result );
43+ else replyNotImplemented (result );
5444 }
5545
5646 private void addTriggers (MethodCall call , Result result ) {
@@ -60,7 +50,11 @@ private void addTriggers(MethodCall call, Result result) {
6050 OneSignal .getInAppMessages ().addTriggers ((Map <String , String >) call .arguments );
6151 replySuccess (result , null );
6252 } catch (ClassCastException e ) {
63- replyError (result , "OneSignal" , "Add triggers failed with error: " + e .getMessage () + "\n " + e .getStackTrace (), null );
53+ replyError (
54+ result ,
55+ "OneSignal" ,
56+ "Add triggers failed with error: " + e .getMessage () + "\n " + e .getStackTrace (),
57+ null );
6458 }
6559 }
6660
@@ -76,7 +70,11 @@ private void removeTriggers(MethodCall call, Result result) {
7670 OneSignal .getInAppMessages ().removeTriggers ((Collection <String >) call .arguments );
7771 replySuccess (result , null );
7872 } catch (ClassCastException e ) {
79- replyError (result , "OneSignal" , "Remove triggers for keys failed with error: " + e .getMessage () + "\n " + e .getStackTrace (), null );
73+ replyError (
74+ result ,
75+ "OneSignal" ,
76+ "Remove triggers for keys failed with error: " + e .getMessage () + "\n " + e .getStackTrace (),
77+ null );
8078 }
8179 }
8280
@@ -99,56 +97,74 @@ public void lifecycleInit(Result result) {
9997 @ Override
10098 public void onClick (IInAppMessageClickEvent event ) {
10199 try {
102- invokeMethodOnUiThread ("OneSignal#onClickInAppMessage" , OneSignalSerializer .convertInAppMessageClickEventToMap (event ));
100+ invokeMethodOnUiThread (
101+ "OneSignal#onClickInAppMessage" , OneSignalSerializer .convertInAppMessageClickEventToMap (event ));
103102 } catch (JSONException e ) {
104103 e .getStackTrace ();
105- Logging .error ("Encountered an error attempting to convert IInAppMessageClickEvent object to hash map:" + e .toString (), null );
106- }
104+ Logging .error (
105+ "Encountered an error attempting to convert IInAppMessageClickEvent object to hash map:"
106+ + e .toString (),
107+ null );
108+ }
107109 }
108110
109111 @ Override
110- public void onWillDisplay (IInAppMessageWillDisplayEvent event ) {
112+ public void onWillDisplay (IInAppMessageWillDisplayEvent event ) {
111113 try {
112- invokeMethodOnUiThread ("OneSignal#onWillDisplayInAppMessage" ,
113- OneSignalSerializer .convertInAppMessageWillDisplayEventToMap (event ));
114+ invokeMethodOnUiThread (
115+ "OneSignal#onWillDisplayInAppMessage" ,
116+ OneSignalSerializer .convertInAppMessageWillDisplayEventToMap (event ));
114117 } catch (JSONException e ) {
115118 e .getStackTrace ();
116- Logging .error ("Encountered an error attempting to convert IInAppMessageWillDisplayEvent object to hash map:" + e .toString (), null );
117- }
118-
119+ Logging .error (
120+ "Encountered an error attempting to convert IInAppMessageWillDisplayEvent object to hash map:"
121+ + e .toString (),
122+ null );
123+ }
119124 }
120125
121126 @ Override
122127 public void onDidDisplay (IInAppMessageDidDisplayEvent event ) {
123128 try {
124- invokeMethodOnUiThread ("OneSignal#onDidDisplayInAppMessage" ,
125- OneSignalSerializer .convertInAppMessageDidDisplayEventToMap (event ));
129+ invokeMethodOnUiThread (
130+ "OneSignal#onDidDisplayInAppMessage" ,
131+ OneSignalSerializer .convertInAppMessageDidDisplayEventToMap (event ));
126132 } catch (JSONException e ) {
127133 e .getStackTrace ();
128- Logging .error ("Encountered an error attempting to convert IInAppMessageDidDisplayEvent object to hash map:" + e .toString (), null );
134+ Logging .error (
135+ "Encountered an error attempting to convert IInAppMessageDidDisplayEvent object to hash map:"
136+ + e .toString (),
137+ null );
129138 }
130139 }
131140
132141 @ Override
133142 public void onWillDismiss (IInAppMessageWillDismissEvent event ) {
134143 try {
135- invokeMethodOnUiThread ("OneSignal#onWillDismissInAppMessage" ,
136- OneSignalSerializer .convertInAppMessageWillDismissEventToMap (event ));
144+ invokeMethodOnUiThread (
145+ "OneSignal#onWillDismissInAppMessage" ,
146+ OneSignalSerializer .convertInAppMessageWillDismissEventToMap (event ));
137147 } catch (JSONException e ) {
138148 e .getStackTrace ();
139- Logging .error ("Encountered an error attempting to convert IInAppMessageWillDismissEvent object to hash map:" + e .toString (), null );
149+ Logging .error (
150+ "Encountered an error attempting to convert IInAppMessageWillDismissEvent object to hash map:"
151+ + e .toString (),
152+ null );
140153 }
141154 }
142155
143156 @ Override
144157 public void onDidDismiss (IInAppMessageDidDismissEvent event ) {
145158 try {
146- invokeMethodOnUiThread ("OneSignal#onDidDismissInAppMessage" ,
147- OneSignalSerializer .convertInAppMessageDidDismissEventToMap (event ));
159+ invokeMethodOnUiThread (
160+ "OneSignal#onDidDismissInAppMessage" ,
161+ OneSignalSerializer .convertInAppMessageDidDismissEventToMap (event ));
148162 } catch (JSONException e ) {
149163 e .getStackTrace ();
150- Logging .error ("Encountered an error attempting to convert IInAppMessageDidDismissEvent object to hash map:" + e .toString (), null );
164+ Logging .error (
165+ "Encountered an error attempting to convert IInAppMessageDidDismissEvent object to hash map:"
166+ + e .toString (),
167+ null );
151168 }
152-
153169 }
154170}
0 commit comments