|
@@ -27,6 +27,7 @@ import reactivecircus.flowbinding.recyclerview.scrollStateChanges
|
|
|
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
|
|
import rx.subscriptions.CompositeSubscription
|
|
|
import uy.kohesive.injekt.injectLazy
|
|
|
+import java.util.ArrayDeque
|
|
|
|
|
|
/**
|
|
|
* Fragment containing the library manga for a certain category.
|
|
@@ -66,7 +67,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|
|
*/
|
|
|
private var subscriptions = CompositeSubscription()
|
|
|
|
|
|
- private var lastClickPosition = -1
|
|
|
+ private var lastClickPositionStack = ArrayDeque(listOf(-1))
|
|
|
|
|
|
fun onCreate(controller: LibraryController, binding: LibraryCategoryBinding) {
|
|
|
this.controller = controller
|
|
@@ -205,7 +206,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|
|
}
|
|
|
is LibrarySelectionEvent.Unselected -> {
|
|
|
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()) {
|
|
|
adapter.mode = SelectableAdapter.Mode.SINGLE
|
|
|
}
|
|
@@ -213,7 +218,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|
|
is LibrarySelectionEvent.Cleared -> {
|
|
|
adapter.mode = SelectableAdapter.Mode.SINGLE
|
|
|
adapter.clearSelection()
|
|
|
- lastClickPosition = -1
|
|
|
+
|
|
|
+ lastClickPositionStack.clear()
|
|
|
+ lastClickPositionStack.push(-1)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -241,7 +248,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|
|
// If the action mode is created and the position is valid, toggle the selection.
|
|
|
val item = adapter.getItem(position) ?: return false
|
|
|
return if (adapter.mode == SelectableAdapter.Mode.MULTI) {
|
|
|
- lastClickPosition = position
|
|
|
+ if (adapter.isSelected(position)) {
|
|
|
+ lastClickPositionStack.remove(position)
|
|
|
+ } else {
|
|
|
+ lastClickPositionStack.push(position)
|
|
|
+ }
|
|
|
toggleSelection(position)
|
|
|
true
|
|
|
} else {
|
|
@@ -257,6 +268,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|
|
*/
|
|
|
override fun onItemLongClick(position: Int) {
|
|
|
controller.createActionModeIfNeeded()
|
|
|
+ val lastClickPosition = lastClickPositionStack.peek()!!
|
|
|
when {
|
|
|
lastClickPosition == -1 -> setSelection(position)
|
|
|
lastClickPosition > position ->
|
|
@@ -267,7 +279,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|
|
setSelection(i)
|
|
|
else -> setSelection(position)
|
|
|
}
|
|
|
- lastClickPosition = position
|
|
|
+ if (lastClickPosition != position) {
|
|
|
+ lastClickPositionStack.remove(position)
|
|
|
+ lastClickPositionStack.push(position)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|