package com.yumpod.youvstheworldkids;

import java.io.File;

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

import android.os.Environment;

public class CommonMethods extends CordovaPlugin {
	/**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param args              JSONArry of arguments for the plugin.
     * @param callbackContext   The callback id used when calling back into JavaScript.
     * @return                  True if the action was valid, false if not.
     */
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("copyDir")) {
            JSONObject r = new JSONObject();
            r.put("res", "fromCommonMethods");
            r.put("currentFolderPath", this.copyToWww());
            callbackContext.success(r);
        }
        else {
            return false;
        }
        return true;
    }
    
    public String copyToWww() {
        File filePath = Environment.getDataDirectory();
        return filePath.getAbsolutePath();
    }
}
