|
@@ -13,9 +13,11 @@ import android.util.Log;
|
|
|
|
|
|
|
|
import com.example.david.libretasker.Actions.Actions;
|
|
import com.example.david.libretasker.Actions.Actions;
|
|
|
import com.example.david.libretasker.Events.Event;
|
|
import com.example.david.libretasker.Events.Event;
|
|
|
|
|
+import com.example.david.libretasker.State.Network;
|
|
|
import com.example.david.libretasker.Store.Store;
|
|
import com.example.david.libretasker.Store.Store;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -25,27 +27,33 @@ import java.util.HashMap;
|
|
|
public class MainService extends Service {
|
|
public class MainService extends Service {
|
|
|
private static final String TAG = "LibreTasker";
|
|
private static final String TAG = "LibreTasker";
|
|
|
|
|
|
|
|
- private String test;
|
|
|
|
|
private static final String BCAST_CONFIGCHANGED = "android.intent.action.CONFIGURATION_CHANGED";
|
|
private static final String BCAST_CONFIGCHANGED = "android.intent.action.CONFIGURATION_CHANGED";
|
|
|
- private static Context mContext;
|
|
|
|
|
|
|
+ private Context mContext;
|
|
|
private EventReceiver receiver = new EventReceiver();
|
|
private EventReceiver receiver = new EventReceiver();
|
|
|
|
|
|
|
|
- private Runnable r = new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- HashMap<String, Object> data = new HashMap<>();
|
|
|
|
|
- HashMap<String, Object> eventData = Store.getState();
|
|
|
|
|
- ArrayList<HashMap<String, Object>> actions;
|
|
|
|
|
- test = "asd";
|
|
|
|
|
- /*actions = (ArrayList<HashMap<String, Object>>)data.get("Actions");
|
|
|
|
|
- eventData = (HashMap<String, Object>)data.get("Event");
|
|
|
|
|
- eventData.put("Intent", intent);
|
|
|
|
|
- if (e.trigger(context, eventData)) {
|
|
|
|
|
|
|
+ private Runnable createRunnable(final HashMap<String, Object> conditions, final ArrayList<HashMap<String, Object>> actions) {
|
|
|
|
|
+ return new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ final HashMap<String, Object> state = Store.getState();
|
|
|
|
|
+
|
|
|
|
|
+ if ( !state.keySet().containsAll(conditions.keySet()) ) //Not all condition keys are even *present*
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ if ( !conditions.keySet().contains((String)state.get("LastEventType")) )
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ for ( String ck : conditions.keySet() ) {
|
|
|
|
|
+ if ( !conditions.get(ck).equals(state.get(ck)) ) //A condition doesn't match
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //If I'm here every condition matched to the state
|
|
|
|
|
+
|
|
|
for (HashMap<String, Object> a : actions) {
|
|
for (HashMap<String, Object> a : actions) {
|
|
|
- Actions.Launch(context, (String) a.get("Type"), a.get("Value"));
|
|
|
|
|
|
|
+ Actions.Launch(mContext, (String) a.get("Type"), a.get("Value"));
|
|
|
}
|
|
}
|
|
|
- }*/
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -54,8 +62,14 @@ public class MainService extends Service {
|
|
|
|
|
|
|
|
mContext = this;
|
|
mContext = this;
|
|
|
receiver = new EventReceiver();
|
|
receiver = new EventReceiver();
|
|
|
|
|
+ HashMap<String, Object> net = new HashMap<>();
|
|
|
|
|
+ HashMap<String, Object> conditions = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ net.put("ValidSSIDs", Arrays.asList("Cueva"));
|
|
|
|
|
+ Network n = new Network(net);
|
|
|
|
|
+ conditions.put("Network", n);
|
|
|
|
|
|
|
|
- Store.subscribe(r);
|
|
|
|
|
|
|
+ Store.subscribe(createRunnable(conditions, new ArrayList<HashMap<String, Object>>()));
|
|
|
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
IntentFilter filter = new IntentFilter();
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|