<commit_before>package com.pollfish.cordova;

/**
 * Created by Pollfish on 4/27/15.
 */

import android.util.Log;

import com.pollfish.constants.Position;
import com.pollfish.interfaces.PollfishClosedListener;
import com.pollfish.interfaces.PollfishOpenedListener;
import com.pollfish.interfaces.PollfishCompletedSurveyListener;
import com.pollfish.interfaces.PollfishSurveyNotAvailableListener;
import com.pollfish.interfaces.PollfishReceivedSurveyListener;
import com.pollfish.interfaces.PollfishUserNotEligibleListener;
import com.pollfish.interfaces.PollfishUserRejectedSurveyListener;
import com.pollfish.constants.UserProperties;
import com.pollfish.main.PollFish;
import com.pollfish.classes.SurveyInfo;
import com.pollfish.main.PollFish.ParamsBuilder;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class PollfishPlugin extends CordovaPlugin {
    
    protected static String TAG = "PollfishPlugin";
    
    // Pollfish functions
    
    private static final String INIT_POLLFISH = "init";
    private static final String SHOW_POLLFISH = "show";
    private static final String HIDE_POLLFISH = "hide";
    private static final String SET_ATTRIBUTES_MAP_POLLFISH = "setAttributesMap";
    private static final String SET_EVENTS_POLLFISH = "setEventCallback";
    
    
    // Pollfish listeners
    
    private CallbackContext onPollfishSurveyReceived=null;
    private CallbackContext onPollfishSurveyCompleted =null;
    private CallbackContext onPollfishSurveyNotAvailable=null;
    private CallbackContext onPollfishUserNotEligible=null;
    private CallbackContext onPollfishUserRejectedSurvey=null;
    private CallbackContext onPollfishOpened=null;
    private CallbackContext onPollfishClosed=null;
    
    
    @Override
    public void onResume(boolean multitasking) {
        super.onResume(multitasking);
    }
    
    /**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param pollfishParams              JSONArray of arguments for the plugin.
     * @param callbackContext   The callback context used when calling back into JavaScript.
     * @return                  True when the action was valid, false otherwise.
     */
    @Override
    public boolean execute(String action, final JSONArray pollfishParams, CallbackContext callbackContext) throws JSONException {
        
        Log.d(TAG, "action: "+ action);
        Log.d(TAG, "Number of Pollfish params: "+ pollfishParams.length());

        if (action.equals(INIT_POLLFISH))  {

            final String curAction=action;
            
            final boolean releaseMode = pollfishParams.getBoolean(0);
            final boolean rewardMode = pollfishParams.getBoolean(1);
            
            final String apiKey = pollfishParams.getString(2);
            final int positionInt =pollfishParams.getInt(3);
            final int indPadding=pollfishParams.getInt(4);
            
            String request_uuid_temp =null;
            
            if(pollfishParams.length()>=5) {
                request_uuid_temp  =pollfishParams.getString(5);
            }
                     
            boolean offerwallMode_temp =false;
        
            if(pollfishParams.length()>=6) {
                offerwallMode_temp  = pollfishParams.getBoolean(6);
            }
       
             JSONObject mapObject_temp = null;
             UserProperties userProperties_temp=null;
             
             if(pollfishParams.length()>=7) {
               
               mapObject_temp  = pollfishParams.optJSONObject(7);
            
     		   userProperties_temp = new UserProperties();
                    
               
                Iterator<?> keys = mapObject_temp.keys();
                    
                while (keys.hasNext()) {
                        
                        try {
                            String key = (String) keys.next();
                            String value = mapObject_temp.getString(key);
                            
                            Log.d(TAG, "Attribute with key: " + key + " and value: " + value);
                            
                            
                            userProperties_temp.setCustomAttributes(key, value);
                            
                        }catch (JSONException e){
                            
                            Log.e(TAG, "Exception while iterating in map dictionary: " + e);
                            
                        }
                        
                }
            }

            
            final String request_uuid = request_uuid_temp;<commit_msg>Update PollfishPlugin.java<commit_after>package com.pollfish.cordova;

/**
 * Created by Pollfish on 4/27/15.
 */

import android.util.Log;

import com.pollfish.constants.Position;
import com.pollfish.interfaces.PollfishClosedListener;
import com.pollfish.interfaces.PollfishOpenedListener;
import com.pollfish.interfaces.PollfishCompletedSurveyListener;
import com.pollfish.interfaces.PollfishSurveyNotAvailableListener;
import com.pollfish.interfaces.PollfishReceivedSurveyListener;
import com.pollfish.interfaces.PollfishUserNotEligibleListener;
import com.pollfish.interfaces.PollfishUserRejectedSurveyListener;
import com.pollfish.constants.UserProperties;
import com.pollfish.main.PollFish;
import com.pollfish.classes.SurveyInfo;
import com.pollfish.main.PollFish.ParamsBuilder;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class PollfishPlugin extends CordovaPlugin {
    
    protected static String TAG = "PollfishPlugin";
    
    // Pollfish functions
    
    private static final String INIT_POLLFISH = "init";
    private static final String SHOW_POLLFISH = "show";
    private static final String HIDE_POLLFISH = "hide";
    private static final String SET_ATTRIBUTES_MAP_POLLFISH = "setAttributesMap";
    private static final String SET_EVENTS_POLLFISH = "setEventCallback";
    
    
    // Pollfish listeners
    
    private CallbackContext onPollfishSurveyReceived=null;
    private CallbackContext onPollfishSurveyCompleted =null;
    private CallbackContext onPollfishSurveyNotAvailable=null;
    private CallbackContext onPollfishUserNotEligible=null;
    private CallbackContext onPollfishUserRejectedSurvey=null;
    private CallbackContext onPollfishOpened=null;
    private CallbackContext onPollfishClosed=null;
    
    
    @Override
    public void onResume(boolean multitasking) {
        super.onResume(multitasking);
    }
    
    /**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param pollfishParams              JSONArray of arguments for the plugin.
     * @param callbackContext   The callback context used when calling back into JavaScript.
     * @return                  True when the action was valid, false otherwise.
     */
    @Override
    public boolean execute(String action, final JSONArray pollfishParams, CallbackContext callbackContext) throws JSONException {
        
        Log.d(TAG, "action: "+ action);
        Log.d(TAG, "Number of Pollfish params: "+ pollfishParams.length());

        if (action.equals(INIT_POLLFISH))  {

            final String curAction=action;
            
            final boolean releaseMode = pollfishParams.getBoolean(0);
            final boolean rewardMode = pollfishParams.getBoolean(1);
            
            final String apiKey = pollfishParams.getString(2);
            final int positionInt =pollfishParams.getInt(3);
            final int indPadding=pollfishParams.getInt(4);
            
            String request_uuid_temp =null;
            
            if(pollfishParams.length()>=6) {
                request_uuid_temp  =pollfishParams.getString(5);
            }
                     
            boolean offerwallMode_temp =false;
        
            if(pollfishParams.length()>=7) {
                offerwallMode_temp  = pollfishParams.getBoolean(6);
            }
       
             JSONObject mapObject_temp = null;
             UserProperties userProperties_temp=null;
             
             if(pollfishParams.length()>=8) {
               
               mapObject_temp  = pollfishParams.optJSONObject(7);
            
     		   userProperties_temp = new UserProperties();
                    
               
                Iterator<?> keys = mapObject_temp.keys();
                    
                while (keys.hasNext()) {
                        
                        try {
                            String key = (String) keys.next();
                            String value = mapObject_temp.getString(key);
                            
                            Log.d(TAG, "Attribute with key: " + key + " and value: " + value);
                            
                            
                            userProperties_temp.setCustomAttributes(key, value);
                            
                        }catch (JSONException e){
                            
                            Log.e(TAG, "Exception while iterating in map dictionary: " + e);
                            
                        }
                        
                }
            }

            
            final String request_uuid = request_uuid_temp;
{'fraction_non_alphanumeric': 0.07069474112501271, 'fraction_numerical': 0.003255009663309938, 'mean_word_length': 1.9948218093207433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864787', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2502, 'n_words': 538}