diff --git a/app/src/main/java/org/koitharu/kotatsu/base/ui/list/SectionedSelectionController.kt b/app/src/main/java/org/koitharu/kotatsu/base/ui/list/SectionedSelectionController.kt index a7edfeea3..3f7abea0b 100644 --- a/app/src/main/java/org/koitharu/kotatsu/base/ui/list/SectionedSelectionController.kt +++ b/app/src/main/java/org/koitharu/kotatsu/base/ui/list/SectionedSelectionController.kt @@ -16,7 +16,6 @@ import androidx.savedstate.SavedStateRegistryOwner import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.Dispatchers import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration -import org.koitharu.kotatsu.utils.ext.removeItemDecoration private const val PROVIDER_NAME = "selection_decoration_sectioned" @@ -61,24 +60,24 @@ class SectionedSelectionController( startActionMode() notifySelectionChanged() } - recyclerView.removeItemDecoration(decoration.javaClass) - recyclerView.addItemDecoration(decoration) + var shouldAddDecoration = true + for (i in (0 until recyclerView.itemDecorationCount).reversed()) { + val decor = recyclerView.getItemDecorationAt(i) + if (decor === decoration) { + shouldAddDecoration = false + break + } else if (decor.javaClass == decoration.javaClass) { + recyclerView.removeItemDecorationAt(i) + } + } + if (shouldAddDecoration) { + recyclerView.addItemDecoration(decoration) + } if (pendingData?.isEmpty() == true) { pendingData = null } } - fun isAttached(recyclerView: RecyclerView): Boolean { - if (decorations.isEmpty()) return false - val anyDecoration = decorations.valueAt(0) - for (i in 0 until recyclerView.itemDecorationCount) { - if (recyclerView.getItemDecorationAt(i).javaClass == anyDecoration.javaClass) { - return true - } - } - return false - } - override fun saveState(): Bundle { val bundle = Bundle(decorations.size) for ((k, v) in decorations) { diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt b/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt index 1d3035fbb..c7384037d 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt +++ b/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt @@ -55,10 +55,8 @@ fun libraryGroupAD( binding.recyclerView.addItemDecoration(spacingDecoration) binding.buttonMore.setOnClickListener(listenerAdapter) - bind { payloads -> - if (payloads.isEmpty() || !selectionController.isAttached(binding.recyclerView)) { - selectionController.attachToRecyclerView(item, binding.recyclerView) - } + bind { + selectionController.attachToRecyclerView(item, binding.recyclerView) binding.textViewTitle.text = item.getTitle(context.resources) binding.buttonMore.setTextAndVisible(item.showAllButtonText) adapter.items = item.items