@@ -155,6 +155,7 @@ class OSJavaScriptInterface {
155
155
static final String EVENT_TYPE_KEY = "type" ;
156
156
static final String EVENT_TYPE_RENDERING_COMPLETE = "rendering_complete" ;
157
157
static final String EVENT_TYPE_ACTION_TAKEN = "action_taken" ;
158
+ static final String EVENT_TYPE_PAGE_CHANGE = "page_change" ;
158
159
159
160
static final String IAM_DISPLAY_LOCATION_KEY = "displayLocation" ;
160
161
static final String IAM_PAGE_META_DATA_KEY = "pageMetaData" ;
@@ -168,11 +169,20 @@ public void postMessage(String message) {
168
169
JSONObject jsonObject = new JSONObject (message );
169
170
String messageType = jsonObject .getString (EVENT_TYPE_KEY );
170
171
171
- if (messageType .equals (EVENT_TYPE_RENDERING_COMPLETE ))
172
- handleRenderComplete (jsonObject );
173
- else if (messageType .equals (EVENT_TYPE_ACTION_TAKEN ) && !messageView .isDragging ()) {
174
- // Added handling so that click actions won't trigger while dragging the IAM
175
- handleActionTaken (jsonObject );
172
+ switch (messageType ) {
173
+ case EVENT_TYPE_RENDERING_COMPLETE :
174
+ handleRenderComplete (jsonObject );
175
+ break ;
176
+ case EVENT_TYPE_ACTION_TAKEN :
177
+ // Added handling so that click actions won't trigger while dragging the IAM
178
+ if (!messageView .isDragging ())
179
+ handleActionTaken (jsonObject );
180
+ break ;
181
+ case EVENT_TYPE_PAGE_CHANGE :
182
+ handlePageChange (jsonObject );
183
+ break ;
184
+ default :
185
+ break ;
176
186
}
177
187
} catch (JSONException e ) {
178
188
e .printStackTrace ();
@@ -226,6 +236,14 @@ private void handleActionTaken(JSONObject jsonObject) throws JSONException {
226
236
if (close )
227
237
dismissAndAwaitNextMessage (null );
228
238
}
239
+
240
+ private void handlePageChange (JSONObject jsonObject ) throws JSONException {
241
+ JSONObject body = jsonObject .getJSONObject ("body" );
242
+ String id = body .optString ("id" , null );
243
+ if (id != null ) {
244
+ OneSignal .getInAppMessageController ().onPageChanged (message , body );
245
+ }
246
+ }
229
247
}
230
248
231
249
private static int pageRectToViewHeight (final @ NonNull Activity activity , @ NonNull JSONObject jsonObject ) {
0 commit comments