diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java index b92dadc89b..6eb3be382b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java @@ -16,6 +16,7 @@ public class AutomationEvent { private Trigger trigger = new TriggerConnector(); private List actions = new ArrayList<>(); private String title; + private boolean enabled = true; public void setTitle(String title) { this.title = title; @@ -33,6 +34,14 @@ public class AutomationEvent { return actions; } + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean newState) { + enabled = newState; + } + public TriggerConnector getPreconditions() { TriggerConnector trigger = new TriggerConnector(TriggerConnector.Type.AND); for (Action action : actions) { @@ -55,6 +64,7 @@ public class AutomationEvent { try { // title o.put("title", title); + o.put("enabled", enabled); // trigger o.put("trigger", trigger.toJSON()); // actions @@ -72,11 +82,9 @@ public class AutomationEvent { public AutomationEvent fromJSON(String data) { try { JSONObject d = new JSONObject(data); - // title title = d.optString("title", ""); - // trigger + enabled = d.optBoolean("enabled", true); trigger = Trigger.instantiate(d.getString("trigger")); - // actions JSONArray array = d.getJSONArray("actions"); actions.clear(); for (int i = 0; i < array.length(); i++) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index 2ab2c91411..a2a84890fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -171,7 +171,7 @@ object AutomationPlugin : PluginBase(PluginDescription() if (L.isEnabled(L.AUTOMATION)) log.debug("processActions") for (event in automationEvents) { - if (event.trigger.shouldRun() && event.preconditions.shouldRun()) { + if (event.isEnabled() && event.trigger.shouldRun() && event.preconditions.shouldRun()) { val actions = event.actions for (action in actions) { action.doAction(object : Callback() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java index 4bbd4a0959..b4c6fb1f11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; @@ -20,8 +21,10 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.automation.actions.Action; import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog; +import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged; import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; class EventListAdapter extends RecyclerView.Adapter { @@ -51,6 +54,7 @@ class EventListAdapter extends RecyclerView.Adapter public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final AutomationEvent event = mEventList.get(position); holder.eventTitle.setText(event.getTitle()); + holder.enabled.setChecked(event.isEnabled()); holder.iconLayout.removeAllViews(); // trigger icons @@ -77,6 +81,13 @@ class EventListAdapter extends RecyclerView.Adapter addImage(res, holder.context, holder.iconLayout); } + // enabled event + holder.enabled.setOnCheckedChangeListener((buttonView, isChecked) -> { + event.setEnabled(isChecked); + notifyDataSetChanged(); + RxBus.INSTANCE.send(new EventAutomationDataChanged()); + }); + // remove event holder.iconTrash.setOnClickListener(v -> { mEventList.remove(event); @@ -107,6 +118,7 @@ class EventListAdapter extends RecyclerView.Adapter final TextView eventTitle; final Context context; final ImageView iconTrash; + final CheckBox enabled; ViewHolder(View view, Context context) { super(view); @@ -115,6 +127,7 @@ class EventListAdapter extends RecyclerView.Adapter rootLayout = view.findViewById(R.id.rootLayout); iconLayout = view.findViewById(R.id.iconLayout); iconTrash = view.findViewById(R.id.iconTrash); + enabled = view.findViewById(R.id.automation_enabled); } } } diff --git a/app/src/main/res/layout/automation_event_item.xml b/app/src/main/res/layout/automation_event_item.xml index ce377a6aa0..6cbc138278 100644 --- a/app/src/main/res/layout/automation_event_item.xml +++ b/app/src/main/res/layout/automation_event_item.xml @@ -11,6 +11,27 @@ android:background="@color/ribbonDefault" android:padding="8dp"> + + + + + android:layout_below="@id/automation_enabled" + android:orientation="horizontal" /> - - - - - \ No newline at end of file