Delete Automation rule with button

onItemDismiss left but could be simplified
This commit is contained in:
Philoul 2020-11-29 17:39:08 +01:00
parent 1eb9a47ba0
commit 7a87cfc7ee
3 changed files with 25 additions and 2 deletions

View file

@ -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)

View file

@ -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

View file

@ -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" />
<ImageView
android:id="@+id/iconTrash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginEnd="20dp"
android:layout_toStartOf="@+id/iconSort"
android:contentDescription="@string/remove_label"
android:orientation="horizontal"
android:src="@drawable/ic_trash_outline" />
<ImageView
android:id="@+id/iconSort"
android:layout_width="wrap_content"