From 7a87cfc7ee4ff43dc07d8fc866d22ef1dd4c2809 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 29 Nov 2020 17:39:08 +0100 Subject: [PATCH] Delete Automation rule with button onItemDismiss left but could be simplified --- .../general/automation/AutomationFragment.kt | 12 ++++++++++++ .../dragHelpers/SimpleItemTouchHelperCallback.kt | 2 +- app/src/main/res/layout/automation_event_item.xml | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt index 3e472a9ce9..3ecae0666b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt @@ -192,6 +192,17 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener { } v.onTouchEvent(motionEvent) } + // remove event + holder.iconTrash.setOnClickListener { + showConfirmation(requireContext(), resourceHelper.gs(R.string.removerecord) + " " + automationPlugin.automationEvents[position].title, + Runnable { + automationPlugin.automationEvents.removeAt(position) + notifyItemRemoved(position) + rxBus.send(EventAutomationDataChanged()) + rxBus.send(EventAutomationUpdateGui()) + }, Runnable { rxBus.send(EventAutomationUpdateGui()) + }) + } } override fun getItemCount(): Int = automationPlugin.automationEvents.size @@ -219,6 +230,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener { val rootLayout: RelativeLayout = view.findViewById(R.id.rootLayout) val iconLayout: LinearLayout = view.findViewById(R.id.iconLayout) val eventTitle: TextView = view.findViewById(R.id.viewEventTitle) + val iconTrash: ImageView = view.findViewById(R.id.iconTrash) val iconSort: ImageView = view.findViewById(R.id.iconSort) val enabled: CheckBox = view.findViewById(R.id.automation_enabled) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt index 7e66046e73..849e5c6a26 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt @@ -21,7 +21,7 @@ class SimpleItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter } override fun isItemViewSwipeEnabled(): Boolean { - return true + return false } override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int { // Set movement flags based on the layout manager diff --git a/app/src/main/res/layout/automation_event_item.xml b/app/src/main/res/layout/automation_event_item.xml index 543f452d64..bff688626d 100644 --- a/app/src/main/res/layout/automation_event_item.xml +++ b/app/src/main/res/layout/automation_event_item.xml @@ -28,12 +28,23 @@ android:layout_alignBottom="@+id/automation_enabled" android:layout_centerVertical="true" android:layout_marginTop="6dp" - android:layout_toStartOf="@+id/iconSort" + android:layout_toStartOf="@+id/iconTrash" android:layout_toEndOf="@id/automation_enabled" android:text="Title" android:textAlignment="viewStart" android:textStyle="bold" /> + +