allow disable automation event
This commit is contained in:
parent
ac8dffe44c
commit
6d91938b3f
4 changed files with 50 additions and 22 deletions
|
@ -16,6 +16,7 @@ public class AutomationEvent {
|
|||
private Trigger trigger = new TriggerConnector();
|
||||
private List<Action> 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++) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<EventListAdapter.ViewHolder> {
|
||||
|
@ -51,6 +54,7 @@ class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder>
|
|||
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<EventListAdapter.ViewHolder>
|
|||
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<EventListAdapter.ViewHolder>
|
|||
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<EventListAdapter.ViewHolder>
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,27 @@
|
|||
android:background="@color/ribbonDefault"
|
||||
android:padding="8dp">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/automation_enabled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/viewEventTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/automation_enabled"
|
||||
android:layout_alignBottom="@+id/automation_enabled"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_toStartOf="@+id/iconTrash"
|
||||
android:layout_toEndOf="@id/automation_enabled"
|
||||
android:text="Title"
|
||||
android:textAlignment="viewStart"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iconTrash"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -21,26 +42,12 @@
|
|||
android:orientation="horizontal"
|
||||
android:src="@drawable/ic_trash_outline" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toStartOf="@id/iconTrash"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/viewEventTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/iconLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/automation_enabled"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue