From 0cb7e7178193f762137bb5692d0a9feb2a62ebc2 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 12 Feb 2024 09:07:32 +0200 Subject: [PATCH] Fix chapters selection decoration --- .../core/ui/list/decor/AbstractSelectionItemDecoration.kt | 2 +- .../details/ui/adapter/ChaptersSelectionDecoration.kt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/decor/AbstractSelectionItemDecoration.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/decor/AbstractSelectionItemDecoration.kt index 20e3aef78..8216f4aab 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/decor/AbstractSelectionItemDecoration.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/decor/AbstractSelectionItemDecoration.kt @@ -91,7 +91,7 @@ abstract class AbstractSelectionItemDecoration : RecyclerView.ItemDecoration() { canvas.restoreToCount(checkpoint) } - protected open fun getItemId(parent: RecyclerView, child: View) = parent.getChildItemId(child) + abstract fun getItemId(parent: RecyclerView, child: View): Long protected open fun onDrawBackground( canvas: Canvas, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersSelectionDecoration.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersSelectionDecoration.kt index 505de1c4b..7b8b46694 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersSelectionDecoration.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersSelectionDecoration.kt @@ -9,7 +9,9 @@ import android.view.View import androidx.core.graphics.ColorUtils import androidx.recyclerview.widget.RecyclerView import org.koitharu.kotatsu.core.ui.list.decor.AbstractSelectionItemDecoration +import org.koitharu.kotatsu.core.util.ext.getItem import org.koitharu.kotatsu.core.util.ext.getThemeColor +import org.koitharu.kotatsu.details.ui.model.ChapterListItem import com.google.android.material.R as materialR class ChaptersSelectionDecoration(context: Context) : AbstractSelectionItemDecoration() { @@ -25,6 +27,12 @@ class ChaptersSelectionDecoration(context: Context) : AbstractSelectionItemDecor paint.style = Paint.Style.FILL } + override fun getItemId(parent: RecyclerView, child: View): Long { + val holder = parent.getChildViewHolder(child) ?: return RecyclerView.NO_ID + val item = holder.getItem(ChapterListItem::class.java) ?: return RecyclerView.NO_ID + return item.chapter.id + } + override fun onDrawBackground( canvas: Canvas, parent: RecyclerView,