From 236349a0638d7db71612c03585e9740e049f5665 Mon Sep 17 00:00:00 2001 From: Nico Schmitz Date: Tue, 26 Mar 2019 23:28:46 +0100 Subject: [PATCH] Bugfixes. Add remove icon for actions. --- .../general/automation/AutomationEvent.java | 1 + .../automation/AutomationFragment.java | 18 ++++-- .../automation/triggers/TriggerConnector.java | 1 + .../res/layout/automation_action_item.xml | 56 +++++++++++++------ 4 files changed, 52 insertions(+), 24 deletions(-) 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 bdc5c01e2e..96cf65fc93 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 @@ -63,6 +63,7 @@ public class AutomationEvent { trigger = Trigger.instantiate(d.getString("trigger")); // actions JSONArray array = d.getJSONArray("actions"); + actions.clear(); for (int i = 0; i < array.length(); i++) { actions.add(Action.instantiate(new JSONObject(array.getString(i)))); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java index ec207659ba..ea3d4a8e7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java @@ -131,13 +131,13 @@ public class AutomationFragment extends SubscriberFragment { addImage(res, holder.context, holder.iconLayout); } - // action: remove + // remove event holder.iconTrash.setOnClickListener(v -> { mEventList.remove(event); notifyDataSetChanged(); }); - // action: edit + // edit event holder.rootLayout.setOnClickListener(v -> { EditEventDialog dialog = EditEventDialog.newInstance(event, false); dialog.show(mFragmentManager, "EditEventDialog"); @@ -168,7 +168,7 @@ public class AutomationFragment extends SubscriberFragment { } /** - * RecyclerViewAdapter to display event lists. + * RecyclerViewAdapter to display action lists. */ public static class ActionListAdapter extends RecyclerView.Adapter { private final List mActionList; @@ -190,12 +190,16 @@ public class AutomationFragment extends SubscriberFragment { public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final Action action = mActionList.get(position); holder.actionTitle.setText(action.friendlyName()); - holder.itemRoot.setOnClickListener(v -> { + holder.layoutText.setOnClickListener(v -> { if (action.hasDialog()) { EditActionDialog dialog = EditActionDialog.newInstance(action); dialog.show(mFragmentManager, "EditActionDialog"); } }); + holder.iconTrash.setOnClickListener(v -> { + mActionList.remove(action); + notifyDataSetChanged(); + }); } @Override @@ -206,13 +210,15 @@ public class AutomationFragment extends SubscriberFragment { static class ViewHolder extends RecyclerView.ViewHolder { TextView actionTitle; TextView actionDescription; - LinearLayout itemRoot; + LinearLayout layoutText; + ImageView iconTrash; public ViewHolder(View view) { super(view); - itemRoot = view.findViewById(R.id.itemRoot); + layoutText = view.findViewById(R.id.layoutText); actionTitle = view.findViewById(R.id.viewActionTitle); actionDescription = view.findViewById(R.id.viewActionDescription); + iconTrash = view.findViewById(R.id.iconTrash); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java index 70a4f01772..28ee9b0705 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java @@ -160,6 +160,7 @@ public class TriggerConnector extends Trigger { JSONObject d = new JSONObject(data); connectorType = Type.valueOf(JsonHelper.safeGetString(d, "connectorType")); JSONArray array = d.getJSONArray("triggerList"); + list.clear(); for (int i = 0; i < array.length(); i++) { Trigger newItem = instantiate(new JSONObject(array.getString(i))); add(newItem); diff --git a/app/src/main/res/layout/automation_action_item.xml b/app/src/main/res/layout/automation_action_item.xml index b6ed902642..add8e4968a 100644 --- a/app/src/main/res/layout/automation_action_item.xml +++ b/app/src/main/res/layout/automation_action_item.xml @@ -1,32 +1,52 @@ - + android:layout_marginTop="8dp"> - + app:srcCompat="@drawable/ic_trash_outline" + android:layout_alignParentRight="true" + android:layout_alignParentTop="true" + android:layout_alignParentBottom="true"/> - - \ No newline at end of file + android:orientation="vertical" + android:layout_alignParentTop="true" + android:layout_alignParentBottom="true" + android:layout_toLeftOf="@id/iconTrash" + android:layout_alignParentLeft="true"> + + + + + + + + \ No newline at end of file