Fix checkbox selection when tapping text in Compose dialogs

This commit is contained in:
arkon 2022-08-27 12:48:04 -04:00
parent 8d40e20b7d
commit cd82c88b9a
3 changed files with 34 additions and 18 deletions

View File

@ -1,8 +1,10 @@
package eu.kanade.presentation.components package eu.kanade.presentation.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox import androidx.compose.material3.Checkbox
@ -85,27 +87,30 @@ fun ChangeCategoryDialog(
text = { text = {
Column { Column {
selection.forEach { checkbox -> selection.forEach { checkbox ->
Row( val onChange: (CheckboxState<Category>) -> Unit = {
verticalAlignment = Alignment.CenterVertically,
) {
val onCheckboxChange: (CheckboxState<Category>) -> Unit = {
val index = selection.indexOf(it) val index = selection.indexOf(it)
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(
modifier = Modifier
.fillMaxWidth()
.clickable { onChange(checkbox) },
verticalAlignment = Alignment.CenterVertically,
) {
when (checkbox) { when (checkbox) {
is CheckboxState.TriState -> { is CheckboxState.TriState -> {
TriStateCheckbox( TriStateCheckbox(
state = checkbox.asState(), state = checkbox.asState(),
onClick = { onCheckboxChange(checkbox) }, onClick = { onChange(checkbox) },
) )
} }
is CheckboxState.State -> { is CheckboxState.State -> {
Checkbox( Checkbox(
checked = checkbox.isChecked, checked = checkbox.isChecked,
onCheckedChange = { onCheckboxChange(checkbox) }, onCheckedChange = { onChange(checkbox) },
) )
} }
} }

View File

@ -1,7 +1,9 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.presentation.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -12,6 +14,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.core.prefs.CheckboxState import eu.kanade.core.prefs.CheckboxState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -58,16 +61,23 @@ fun DeleteLibraryMangaDialog(
text = { text = {
Column { Column {
list.forEach { state -> list.forEach { state ->
Row(verticalAlignment = Alignment.CenterVertically) { val onCheck = {
Checkbox(
checked = state.isChecked,
onCheckedChange = {
val index = list.indexOf(state) val index = list.indexOf(state)
val mutableList = list.toMutableList() val mutableList = list.toMutableList()
mutableList.removeAt(index) mutableList.removeAt(index)
mutableList.add(index, state.next() as CheckboxState.State<Int>) mutableList.add(index, state.next() as CheckboxState.State<Int>)
list = mutableList.toList() list = mutableList.toList()
}, }
Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onCheck() },
verticalAlignment = Alignment.CenterVertically,
) {
Checkbox(
checked = state.isChecked,
onCheckedChange = { onCheck() },
) )
Text(text = stringResource(state.value)) Text(text = stringResource(state.value))
} }

View File

@ -13,6 +13,7 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.isLocal
import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.presentation.components.ChangeCategoryDialog import eu.kanade.presentation.components.ChangeCategoryDialog
import eu.kanade.presentation.components.DeleteLibraryMangaDialog
import eu.kanade.presentation.library.LibraryScreen import eu.kanade.presentation.library.LibraryScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.database.models.toDomainManga