diff --git a/app/src/main/java/eu/kanade/presentation/components/ChangeCategoryDialog.kt b/app/src/main/java/eu/kanade/presentation/components/ChangeCategoryDialog.kt index 6c83e4677..e4191391e 100644 --- a/app/src/main/java/eu/kanade/presentation/components/ChangeCategoryDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/components/ChangeCategoryDialog.kt @@ -93,10 +93,12 @@ fun ChangeCategoryDialog( selection.forEach { checkbox -> val onChange: (CheckboxState) -> Unit = { val index = selection.indexOf(it) - val mutableList = selection.toMutableList() - mutableList.removeAt(index) - mutableList.add(index, it.next()) - selection = mutableList.toList() + if (index != -1) { + val mutableList = selection.toMutableList() + mutableList.removeAt(index) + mutableList.add(index, it.next()) + selection = mutableList.toList() + } } Row( modifier = Modifier diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt index 38d021872..7d0ac529c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt @@ -14,6 +14,7 @@ import androidx.appcompat.widget.PopupMenu import androidx.core.content.withStyledAttributes import androidx.core.view.forEach import androidx.core.view.get +import androidx.core.view.size import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.core.preference.Preference import eu.kanade.tachiyomi.databinding.PrefSpinnerBinding @@ -66,12 +67,13 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att } fun setSelection(selection: Int) { - popup?.menu?.get(selectedPosition)?.let { - it.icon = emptyIcon - it.title = entries[selectedPosition] + if (selectedPosition < (popup?.menu?.size ?: 0)) { + popup?.menu?.getItem(selectedPosition)?.let { + it.icon = emptyIcon + } } selectedPosition = selection - popup?.menu?.get(selectedPosition)?.let { + popup?.menu?.getItem(selectedPosition)?.let { it.icon = checkmarkIcon } binding.details.text = entries.getOrNull(selection).orEmpty()