diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/ItemTouchHelperAdapter.kt b/core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/ItemTouchHelperAdapter.kt similarity index 91% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/ItemTouchHelperAdapter.kt rename to core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/ItemTouchHelperAdapter.kt index e873e73173..d76f12c4a2 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/ItemTouchHelperAdapter.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/ItemTouchHelperAdapter.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.dragHelpers +package info.nightscout.androidaps.utils.dragHelpers interface ItemTouchHelperAdapter { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/OnStartDragListener.kt b/core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/OnStartDragListener.kt similarity index 78% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/OnStartDragListener.kt rename to core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/OnStartDragListener.kt index 9a90a360de..0924f37b2a 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/OnStartDragListener.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/OnStartDragListener.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.dragHelpers +package info.nightscout.androidaps.utils.dragHelpers import androidx.recyclerview.widget.RecyclerView @@ -9,4 +9,4 @@ interface OnStartDragListener { * @param viewHolder The holder of the view to drag. */ fun onStartDrag(viewHolder: RecyclerView.ViewHolder) -} \ No newline at end of file +} diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt b/core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/SimpleItemTouchHelperCallback.kt similarity index 52% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt rename to core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/SimpleItemTouchHelperCallback.kt index 76d15f5477..2dc27917bc 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dragHelpers/SimpleItemTouchHelperCallback.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/dragHelpers/SimpleItemTouchHelperCallback.kt @@ -1,21 +1,25 @@ -package info.nightscout.androidaps.plugins.general.automation.dragHelpers +package info.nightscout.androidaps.utils.dragHelpers import androidx.recyclerview.widget.ItemTouchHelper +import androidx.recyclerview.widget.ItemTouchHelper.ACTION_STATE_DRAG +import androidx.recyclerview.widget.ItemTouchHelper.DOWN +import androidx.recyclerview.widget.ItemTouchHelper.END +import androidx.recyclerview.widget.ItemTouchHelper.START +import androidx.recyclerview.widget.ItemTouchHelper.UP import androidx.recyclerview.widget.RecyclerView -import info.nightscout.androidaps.plugins.general.automation.AutomationFragment -class SimpleItemTouchHelperCallback : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN or ItemTouchHelper.START or ItemTouchHelper.END, 0) { +const val ALPHA_FULL = 1f +const val ALPHA_DRAGGING = 0.5f - override fun isLongPressDragEnabled(): Boolean { - return false - } +class SimpleItemTouchHelperCallback : ItemTouchHelper.SimpleCallback(UP or DOWN or START or END, 0) { + + override fun isLongPressDragEnabled() = false override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { - val adapter = recyclerView.adapter as AutomationFragment.EventListAdapter + val adapter = recyclerView.adapter as ItemTouchHelperAdapter val from = viewHolder.layoutPosition val to = target.layoutPosition adapter.onItemMove(from, to) - adapter.notifyItemMoved(from, to) return true } @@ -24,14 +28,14 @@ class SimpleItemTouchHelperCallback : ItemTouchHelper.SimpleCallback(ItemTouchHe override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { super.onSelectedChanged(viewHolder, actionState) - if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { - viewHolder?.itemView?.alpha = 0.5f + if (actionState == ACTION_STATE_DRAG) { + viewHolder?.itemView?.alpha = ALPHA_DRAGGING } } override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { super.clearView(recyclerView, viewHolder) - viewHolder.itemView.alpha = 1.0f - (recyclerView.adapter as AutomationFragment.EventListAdapter).onDrop() + viewHolder.itemView.alpha = ALPHA_FULL + (recyclerView.adapter as ItemTouchHelperAdapter).onDrop() } }