Fix multi-select phantom anchor bug in manga chapters and library (#4201)
* Fix phantom anchor bug in manga chapters list when multi-selecting * Fix phantom bug when long pressing selected items not at top of stack * Fix phantom anchor bug in library page (cherry picked from commit 496a476c13396f3063388e0d7e8f5ab2c3663858) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
This commit is contained in:
parent
3927c62a32
commit
41607ab259
@ -35,6 +35,7 @@ import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
|||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.subscriptions.CompositeSubscription
|
import rx.subscriptions.CompositeSubscription
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.util.ArrayDeque
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,7 +82,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
*/
|
*/
|
||||||
private var subscriptions = CompositeSubscription()
|
private var subscriptions = CompositeSubscription()
|
||||||
|
|
||||||
private var lastClickPosition = -1
|
private var lastClickPositionStack = ArrayDeque(listOf(-1))
|
||||||
|
|
||||||
// EXH -->
|
// EXH -->
|
||||||
private var initialLoadHandle: LoadingHandle? = null
|
private var initialLoadHandle: LoadingHandle? = null
|
||||||
@ -294,7 +295,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
}
|
}
|
||||||
is LibrarySelectionEvent.Unselected -> {
|
is LibrarySelectionEvent.Unselected -> {
|
||||||
findAndToggleSelection(event.manga)
|
findAndToggleSelection(event.manga)
|
||||||
if (adapter.indexOf(event.manga) != -1) lastClickPosition = -1
|
|
||||||
|
with(adapter.indexOf(event.manga)) {
|
||||||
|
if (this != -1) lastClickPositionStack.remove(this)
|
||||||
|
}
|
||||||
|
|
||||||
if (controller.selectedMangas.isEmpty()) {
|
if (controller.selectedMangas.isEmpty()) {
|
||||||
adapter.mode = SelectableAdapter.Mode.SINGLE
|
adapter.mode = SelectableAdapter.Mode.SINGLE
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -305,7 +310,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
is LibrarySelectionEvent.Cleared -> {
|
is LibrarySelectionEvent.Cleared -> {
|
||||||
adapter.mode = SelectableAdapter.Mode.SINGLE
|
adapter.mode = SelectableAdapter.Mode.SINGLE
|
||||||
adapter.clearSelection()
|
adapter.clearSelection()
|
||||||
lastClickPosition = -1
|
|
||||||
|
lastClickPositionStack.clear()
|
||||||
|
lastClickPositionStack.push(-1)
|
||||||
// SY -->
|
// SY -->
|
||||||
adapter.isLongPressDragEnabled = adapter.canDrag()
|
adapter.isLongPressDragEnabled = adapter.canDrag()
|
||||||
// SY <--
|
// SY <--
|
||||||
@ -336,7 +343,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
// 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
|
||||||
return if (adapter.mode == SelectableAdapter.Mode.MULTI) {
|
return if (adapter.mode == SelectableAdapter.Mode.MULTI) {
|
||||||
lastClickPosition = position
|
if (adapter.isSelected(position)) {
|
||||||
|
lastClickPositionStack.remove(position)
|
||||||
|
} else {
|
||||||
|
lastClickPositionStack.push(position)
|
||||||
|
}
|
||||||
toggleSelection(position)
|
toggleSelection(position)
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
@ -352,6 +363,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
*/
|
*/
|
||||||
override fun onItemLongClick(position: Int) {
|
override fun onItemLongClick(position: Int) {
|
||||||
controller.createActionModeIfNeeded()
|
controller.createActionModeIfNeeded()
|
||||||
|
val lastClickPosition = lastClickPositionStack.peek()!!
|
||||||
// SY -->
|
// SY -->
|
||||||
adapter.isLongPressDragEnabled = adapter.canDrag()
|
adapter.isLongPressDragEnabled = adapter.canDrag()
|
||||||
// SY <--
|
// SY <--
|
||||||
@ -365,7 +377,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
setSelection(i)
|
setSelection(i)
|
||||||
else -> setSelection(position)
|
else -> setSelection(position)
|
||||||
}
|
}
|
||||||
lastClickPosition = position
|
if (lastClickPosition != position) {
|
||||||
|
lastClickPositionStack.remove(position)
|
||||||
|
lastClickPositionStack.push(position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
|
@ -119,6 +119,7 @@ import uy.kohesive.injekt.Injekt
|
|||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.util.ArrayDeque
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class MangaController :
|
class MangaController :
|
||||||
@ -216,7 +217,7 @@ class MangaController :
|
|||||||
|
|
||||||
private val isLocalSource by lazy { presenter.source.id == LocalSource.ID }
|
private val isLocalSource by lazy { presenter.source.id == LocalSource.ID }
|
||||||
|
|
||||||
private var lastClickPosition = -1
|
private var lastClickPositionStack = ArrayDeque(listOf(-1))
|
||||||
|
|
||||||
private var isRefreshingInfo = false
|
private var isRefreshingInfo = false
|
||||||
private var isRefreshingChapters = false
|
private var isRefreshingChapters = false
|
||||||
@ -1138,7 +1139,12 @@ class MangaController :
|
|||||||
val adapter = chaptersAdapter ?: return false
|
val adapter = chaptersAdapter ?: return false
|
||||||
val item = adapter.getItem(position) ?: return false
|
val item = adapter.getItem(position) ?: return false
|
||||||
return if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) {
|
return if (actionMode != null && adapter.mode == SelectableAdapter.Mode.MULTI) {
|
||||||
lastClickPosition = position
|
if (adapter.isSelected(position)) {
|
||||||
|
lastClickPositionStack.remove(position) // possible that it's not there, but no harm
|
||||||
|
} else {
|
||||||
|
lastClickPositionStack.push(position)
|
||||||
|
}
|
||||||
|
|
||||||
toggleSelection(position)
|
toggleSelection(position)
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
@ -1149,6 +1155,7 @@ class MangaController :
|
|||||||
|
|
||||||
override fun onItemLongClick(position: Int) {
|
override fun onItemLongClick(position: Int) {
|
||||||
createActionModeIfNeeded()
|
createActionModeIfNeeded()
|
||||||
|
val lastClickPosition = lastClickPositionStack.peek()!!
|
||||||
when {
|
when {
|
||||||
lastClickPosition == -1 -> setSelection(position)
|
lastClickPosition == -1 -> setSelection(position)
|
||||||
lastClickPosition > position ->
|
lastClickPosition > position ->
|
||||||
@ -1159,7 +1166,10 @@ class MangaController :
|
|||||||
setSelection(i)
|
setSelection(i)
|
||||||
else -> setSelection(position)
|
else -> setSelection(position)
|
||||||
}
|
}
|
||||||
lastClickPosition = position
|
if (lastClickPosition != position) {
|
||||||
|
lastClickPositionStack.remove(position) // move to top if already exists
|
||||||
|
lastClickPositionStack.push(position)
|
||||||
|
}
|
||||||
chaptersAdapter?.notifyDataSetChanged()
|
chaptersAdapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1208,7 +1218,8 @@ class MangaController :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun destroyActionModeIfNeeded() {
|
private fun destroyActionModeIfNeeded() {
|
||||||
lastClickPosition = -1
|
lastClickPositionStack.clear()
|
||||||
|
lastClickPositionStack.push(-1)
|
||||||
actionMode?.finish()
|
actionMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user