mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 14:09:17 +01:00
Avoid some IndexOutOfBoundsExceptions
This commit is contained in:
parent
d2e62ffb19
commit
eb742b29f8
@ -93,11 +93,13 @@ fun ChangeCategoryDialog(
|
|||||||
selection.forEach { checkbox ->
|
selection.forEach { checkbox ->
|
||||||
val onChange: (CheckboxState<Category>) -> Unit = {
|
val onChange: (CheckboxState<Category>) -> Unit = {
|
||||||
val index = selection.indexOf(it)
|
val index = selection.indexOf(it)
|
||||||
|
if (index != -1) {
|
||||||
val mutableList = selection.toMutableList()
|
val mutableList = selection.toMutableList()
|
||||||
mutableList.removeAt(index)
|
mutableList.removeAt(index)
|
||||||
mutableList.add(index, it.next())
|
mutableList.add(index, it.next())
|
||||||
selection = mutableList.toList()
|
selection = mutableList.toList()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
@ -14,6 +14,7 @@ import androidx.appcompat.widget.PopupMenu
|
|||||||
import androidx.core.content.withStyledAttributes
|
import androidx.core.content.withStyledAttributes
|
||||||
import androidx.core.view.forEach
|
import androidx.core.view.forEach
|
||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
|
import androidx.core.view.size
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.core.preference.Preference
|
import eu.kanade.tachiyomi.core.preference.Preference
|
||||||
import eu.kanade.tachiyomi.databinding.PrefSpinnerBinding
|
import eu.kanade.tachiyomi.databinding.PrefSpinnerBinding
|
||||||
@ -66,12 +67,13 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setSelection(selection: Int) {
|
fun setSelection(selection: Int) {
|
||||||
popup?.menu?.get(selectedPosition)?.let {
|
if (selectedPosition < (popup?.menu?.size ?: 0)) {
|
||||||
|
popup?.menu?.getItem(selectedPosition)?.let {
|
||||||
it.icon = emptyIcon
|
it.icon = emptyIcon
|
||||||
it.title = entries[selectedPosition]
|
}
|
||||||
}
|
}
|
||||||
selectedPosition = selection
|
selectedPosition = selection
|
||||||
popup?.menu?.get(selectedPosition)?.let {
|
popup?.menu?.getItem(selectedPosition)?.let {
|
||||||
it.icon = checkmarkIcon
|
it.icon = checkmarkIcon
|
||||||
}
|
}
|
||||||
binding.details.text = entries.getOrNull(selection).orEmpty()
|
binding.details.text = entries.getOrNull(selection).orEmpty()
|
||||||
|
Loading…
Reference in New Issue
Block a user