private void processInAppResponse(final JSONObject response, final Context context) {
        try {
            getConfigLogger().verbose(getAccountId(),"InApp: Processing response");

            if (!response.has("inapp_notifs")) {
                getConfigLogger().verbose(getAccountId(),"InApp: Response JSON object doesn't contain the inapp key, bailing");
                return;
            }

            int perSession = 10;
            int perDay = 10;
            if (response.has(Constants.INAPP_MAX_PER_SESSION) && response.get(Constants.INAPP_MAX_PER_SESSION) instanceof Integer) {
                perSession = response.getInt(Constants.INAPP_MAX_PER_SESSION);
            }

            if (response.has("imp") && response.get("imp") instanceof Integer) {
                perDay = response.getInt("imp");
            }

            inAppFCManager.updateLimits(context, perDay, perSession);

            JSONArray inappNotifs;
            try {
                inappNotifs = response.getJSONArray(Constants.INAPP_JSON_RESPONSE_KEY);
            } catch (JSONException e) {
                getConfigLogger().debug(getAccountId(),"InApp: In-app key didn't contain a valid JSON array");
                return;
            }

            // Add all the new notifications to the queue
            SharedPreferences prefs = StorageHelper.getPreferences(context);
            SharedPreferences.Editor editor = prefs.edit();
            try {
                JSONArray inappsFromPrefs = new JSONArray(getStringFromPrefs(Constants.PREFS_INAPP_KEY, "[]"));

                // Now add the rest of them :)
                if (inappNotifs != null && inappNotifs.length() > 0) {
                    for (int i = 0; i < inappNotifs.length(); i++) {
                        try {
                            JSONObject inappNotif = inappNotifs.getJSONObject(i);
                            inappsFromPrefs.put(inappNotif);
                        } catch (JSONException e) {
                            Logger.v("InAppManager: Malformed inapp notification");
                        }
                    }
                }

                // Commit all the changes
                editor.putString(storageKeyWithSuffix(Constants.PREFS_INAPP_KEY), inappsFromPrefs.toString());
                StorageHelper.persist(editor);
            } catch (Throwable e) {
                getConfigLogger().verbose(getAccountId(),"InApp: Failed to parse the in-app notifications properly");
                getConfigLogger().verbose(getAccountId(),"InAppManager: Reason: " + e.getMessage(), e);
            }
            // Fire the first notification, if any
            runOnNotificationQueue(new Runnable() {
                @Override
                public void run() {
                    _showNotificationIfAvailable(context);
                }
            });
        } catch (Throwable t) {
            Logger.v("InAppManager: Failed to parse response", t);
        }
    }
private void processInAppResponse ( final JSONObject response , final Context context ) { try { getConfigLogger ( ) . verbose ( getAccountId ( ) , "InApp: Processing response" ) ; if ( ! response . has ( "inapp_notifs" ) ) { getConfigLogger ( ) . verbose ( getAccountId ( ) , "InApp: Response JSON object doesn't contain the inapp key, bailing" ) ; return ; } int perSession = 10 ; int perDay = 10 ; if ( response . has ( Constants . INAPP_MAX_PER_SESSION ) && response . get ( Constants . INAPP_MAX_PER_SESSION ) instanceof Integer ) { perSession = response . getInt ( Constants . INAPP_MAX_PER_SESSION ) ; } if ( response . has ( "imp" ) && response . get ( "imp" ) instanceof Integer ) { perDay = response . getInt ( "imp" ) ; } inAppFCManager . updateLimits ( context , perDay , perSession ) ; JSONArray inappNotifs ; try { inappNotifs = response . getJSONArray ( Constants . INAPP_JSON_RESPONSE_KEY ) ; } catch ( JSONException e ) { getConfigLogger ( ) . debug ( getAccountId ( ) , "InApp: In-app key didn't contain a valid JSON array" ) ; return ; } SharedPreferences prefs = StorageHelper . getPreferences ( context ) ; SharedPreferences . Editor editor = prefs . edit ( ) ; try { JSONArray inappsFromPrefs = new JSONArray ( getStringFromPrefs ( Constants . PREFS_INAPP_KEY , "[]" ) ) ; if ( inappNotifs != null && inappNotifs . length ( ) > 0 ) { for ( int i = 0 ; i < inappNotifs . length ( ) ; i ++ ) { try { JSONObject inappNotif = inappNotifs . getJSONObject ( i ) ; inappsFromPrefs . put ( inappNotif ) ; } catch ( JSONException e ) { Logger . v ( "InAppManager: Malformed inapp notification" ) ; } } } editor . putString ( storageKeyWithSuffix ( Constants . PREFS_INAPP_KEY ) , inappsFromPrefs . toString ( ) ) ; StorageHelper . persist ( editor ) ; } catch ( Throwable e ) { getConfigLogger ( ) . verbose ( getAccountId ( ) , "InApp: Failed to parse the in-app notifications properly" ) ; getConfigLogger ( ) . verbose ( getAccountId ( ) , "InAppManager: Reason: " + e . getMessage ( ) , e ) ; } runOnNotificationQueue ( new Runnable ( ) { @ Override public void run ( ) { _showNotificationIfAvailable ( context ) ; } } ) ; } catch ( Throwable t ) { Logger . v ( "InAppManager: Failed to parse response" , t ) ; } }
InApp