Fixed double vibration in D&D sort

This commit is contained in:
Jay 2020-01-15 20:33:59 -08:00
parent de66a66961
commit 7fda2f9636

View File

@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.util.*
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.chapters_controller.* import kotlinx.android.synthetic.main.chapters_controller.*
import kotlinx.android.synthetic.main.library_category.view.* import kotlinx.android.synthetic.main.library_category.view.*
import kotlinx.coroutines.delay
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -235,6 +236,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
is LibrarySelectionEvent.Selected -> { is LibrarySelectionEvent.Selected -> {
if (adapter.mode != SelectableAdapter.Mode.MULTI) { if (adapter.mode != SelectableAdapter.Mode.MULTI) {
adapter.mode = SelectableAdapter.Mode.MULTI adapter.mode = SelectableAdapter.Mode.MULTI
}
launchUI {
delay(100)
adapter.isLongPressDragEnabled = false adapter.isLongPressDragEnabled = false
} }
findAndToggleSelection(event.manga) findAndToggleSelection(event.manga)
@ -279,13 +283,13 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
override fun onItemClick(view: View?, position: Int): Boolean { override fun onItemClick(view: View?, position: Int): Boolean {
// If the action mode is created and the position is valid, toggle the selection. // If the action mode is created and the position is valid, toggle the selection.
val item = adapter.getItem(position) ?: return false val item = adapter.getItem(position) ?: return false
if (adapter.mode == SelectableAdapter.Mode.MULTI) { return if (adapter.mode == SelectableAdapter.Mode.MULTI) {
lastClickPosition = position lastClickPosition = position
toggleSelection(position) toggleSelection(position)
return true true
} else { } else {
openManga(item.manga, lastTouchUpY) openManga(item.manga, lastTouchUpY)
return false false
} }
} }
@ -303,7 +307,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
*/ */
override fun onItemLongClick(position: Int) { override fun onItemLongClick(position: Int) {
controller.createActionModeIfNeeded() controller.createActionModeIfNeeded()
adapter.isLongPressDragEnabled = false
when { when {
lastClickPosition == -1 -> setSelection(position) lastClickPosition == -1 -> setSelection(position)
lastClickPosition > position -> for (i in position until lastClickPosition) lastClickPosition > position -> for (i in position until lastClickPosition)
@ -320,9 +323,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
} }
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {
if (adapter.selectedItemCount == 0) { if (adapter.selectedItemCount == 0) saveDragSort()
saveDragSort()
}
} }
private fun saveDragSort() { private fun saveDragSort() {
@ -346,8 +347,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
val position = viewHolder?.adapterPosition ?: return val position = viewHolder?.adapterPosition ?: return
if (actionState == 2) if (actionState == 2) onItemLongClick(position)
onItemLongClick(position)
} }
/** /**