mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 05:25:08 +01:00
Fix crash when using -1 as an id for MaterialMenuSheet
turns out fast adapter does not like -1 as an id
This commit is contained in:
parent
5c6a91b0d3
commit
d1c709ce2c
@ -23,11 +23,12 @@ import eu.kanade.tachiyomi.util.view.checkHeightThen
|
|||||||
import eu.kanade.tachiyomi.util.view.expand
|
import eu.kanade.tachiyomi.util.view.expand
|
||||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||||
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
|
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class MaterialMenuSheet(
|
class MaterialMenuSheet(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
items: List<MenuSheetItem>,
|
private val items: List<MenuSheetItem>,
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
selectedId: Int? = null,
|
selectedId: Int? = null,
|
||||||
maxHeight: Int? = null,
|
maxHeight: Int? = null,
|
||||||
@ -83,7 +84,7 @@ class MaterialMenuSheet(
|
|||||||
binding.toolbarTitle.text = title
|
binding.toolbarTitle.text = title
|
||||||
|
|
||||||
if (selectedId != null) {
|
if (selectedId != null) {
|
||||||
val pos = itemAdapter.getAdapterPosition(selectedId.toLong())
|
val pos = max(items.indexOfFirst { it.id == selectedId }, 0)
|
||||||
itemAdapter.getAdapterItem(pos).isSelected = true
|
itemAdapter.getAdapterItem(pos).isSelected = true
|
||||||
binding.root.post {
|
binding.root.post {
|
||||||
binding.root.post {
|
binding.root.post {
|
||||||
@ -131,7 +132,7 @@ class MaterialMenuSheet(
|
|||||||
if (clearAll) {
|
if (clearAll) {
|
||||||
clearEndDrawables()
|
clearEndDrawables()
|
||||||
}
|
}
|
||||||
val pos = itemAdapter.getAdapterPosition(id.toLong())
|
val pos = max(items.indexOfFirst { it.id == id }, 0)
|
||||||
val item = itemAdapter.getAdapterItem(pos)
|
val item = itemAdapter.getAdapterItem(pos)
|
||||||
item.sheetItem.endDrawableRes = drawableRes
|
item.sheetItem.endDrawableRes = drawableRes
|
||||||
item.isSelected = true
|
item.isSelected = true
|
||||||
|
@ -15,7 +15,7 @@ class MaterialMenuSheetItem(val sheetItem: MaterialMenuSheet.MenuSheetItem) : Ab
|
|||||||
* Returns the layout resource for this item.
|
* Returns the layout resource for this item.
|
||||||
*/
|
*/
|
||||||
override val layoutRes: Int = R.layout.menu_sheet_item
|
override val layoutRes: Int = R.layout.menu_sheet_item
|
||||||
override var identifier = sheetItem.id.hashCode().toLong()
|
override var identifier = sheetItem.id.toLong()
|
||||||
|
|
||||||
override fun getViewHolder(v: View): ViewHolder {
|
override fun getViewHolder(v: View): ViewHolder {
|
||||||
return ViewHolder(v)
|
return ViewHolder(v)
|
||||||
|
Loading…
Reference in New Issue
Block a user