initiate touchhelper at folders only when going to drag & drop

This commit is contained in:
tibbi 2021-05-14 20:01:47 +02:00
parent 047f6bf18d
commit 53f3cfe02e
1 changed files with 13 additions and 11 deletions

View File

@ -68,7 +68,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
private var currentDirectoriesHash = dirs.hashCode() private var currentDirectoriesHash = dirs.hashCode()
private var lockedFolderPaths = ArrayList<String>() private var lockedFolderPaths = ArrayList<String>()
private var isDragAndDropping = false private var isDragAndDropping = false
private var startReorderDragListener: StartReorderDragListener private var startReorderDragListener: StartReorderDragListener? = null
private var showMediaCount = config.showFolderMediaCount private var showMediaCount = config.showFolderMediaCount
private var folderStyle = config.folderStyle private var folderStyle = config.folderStyle
@ -77,15 +77,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
init { init {
setupDragListener(true) setupDragListener(true)
fillLockedFolders() fillLockedFolders()
val touchHelper = ItemTouchHelper(ItemMoveCallback(this, true))
touchHelper.attachToRecyclerView(recyclerView)
startReorderDragListener = object : StartReorderDragListener {
override fun requestDrag(viewHolder: RecyclerView.ViewHolder) {
touchHelper.startDrag(viewHolder)
}
}
} }
override fun getActionMenuId() = R.menu.cab_directories override fun getActionMenuId() = R.menu.cab_directories
@ -493,6 +484,17 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
isDragAndDropping = true isDragAndDropping = true
notifyDataSetChanged() notifyDataSetChanged()
actMode?.invalidate() actMode?.invalidate()
if (startReorderDragListener == null) {
val touchHelper = ItemTouchHelper(ItemMoveCallback(this, true))
touchHelper.attachToRecyclerView(recyclerView)
startReorderDragListener = object : StartReorderDragListener {
override fun requestDrag(viewHolder: RecyclerView.ViewHolder) {
touchHelper.startDrag(viewHolder)
}
}
}
} }
private fun moveFilesTo() { private fun moveFilesTo() {
@ -837,7 +839,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
dir_drag_handle.applyColorFilter(textColor) dir_drag_handle.applyColorFilter(textColor)
dir_drag_handle.setOnTouchListener { v, event -> dir_drag_handle.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) { if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder) startReorderDragListener?.requestDrag(holder)
} }
false false
} }