package mobi.acpm.inspeckage.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import mobi.acpm.inspeckage.Module;
import mobi.acpm.inspeckage.util.Config;

/**
 * Created by acpm on 20/01/16.
 */
public class InspeckageWebReceiver extends BroadcastReceiver {

    private Context mContext;
    public InspeckageWebReceiver(Context ctx){
        mContext = ctx;
    }
    @Override
    public void onReceive(Context context, Intent intent) {

        SharedPreferences mPrefs = mContext.getSharedPreferences(Module.PREFS, mContext.MODE_WORLD_READABLE);
        SharedPreferences.Editor edit = mPrefs.edit();

        String action = intent.getExtras().getString("action");

        if(action.equals("fileTree")){

            String sub1 = intent.getExtras().getString("tree");

            String script = "<script>\n" +
                    "$(document).ready(function() {\n" +
                    "\n" +
                    "    CollapsibleLists.apply();\n" +
                    "\n" +
                    "});\n" +
                    "</script>";

            String tree = script+"<ul class=\"collapsibleList\">"+sub1+"</ul>";
            edit.putString(Config.SP_DATA_DIR_TREE, tree);
            edit.apply();
        }

        if(action.equals("checkApp")){

            boolean isRunning = intent.getExtras().getBoolean("isRunning");
            int pid = intent.getExtras().getInt("PID");
            edit.putBoolean(Config.SP_APP_IS_RUNNING, isRunning);
            edit.putInt(Config.SP_APP_PID, pid);
            edit.apply();
        }
    }
}
@@ -1330,25 +1330,20 @@
        %7D
-%0A%0A       
+else
  if(acti
@@ -1614,16 +1614,16 @@
 , pid);%0A
-
         
@@ -1632,32 +1632,461 @@
   edit.apply();%0A
+        %7Delse if(action.equals(%22clipboard%22))%7B%0A%0A            String value = intent.getExtras().getString(%22value%22);%0A%0A            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);%0A            android.content.ClipData clip = android.content.ClipData%0A                    .newPlainText(%22simple text%22, value);%0A            clipboard.setPrimaryClip(clip);%0A
         %7D%0A    %7D%0A

add clipboard option