From cd82c88b9aa8f344d8ee9938eeae8a6293d5f231 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 27 Aug 2022 12:48:04 -0400 Subject: [PATCH] Fix checkbox selection when tapping text in Compose dialogs --- .../components/ChangeCategoryDialog.kt | 23 +++++++++------ .../components/DeleteLibraryMangaDialog.kt | 28 +++++++++++++------ .../tachiyomi/ui/library/LibraryController.kt | 1 + 3 files changed, 34 insertions(+), 18 deletions(-) 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 8914458ce8..3e05c3517e 100644 --- a/app/src/main/java/eu/kanade/presentation/components/ChangeCategoryDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/components/ChangeCategoryDialog.kt @@ -1,8 +1,10 @@ package eu.kanade.presentation.components +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.AlertDialog import androidx.compose.material3.Checkbox @@ -85,27 +87,30 @@ fun ChangeCategoryDialog( text = { Column { 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() + } Row( + modifier = Modifier + .fillMaxWidth() + .clickable { onChange(checkbox) }, verticalAlignment = Alignment.CenterVertically, ) { - val onCheckboxChange: (CheckboxState) -> Unit = { - val index = selection.indexOf(it) - val mutableList = selection.toMutableList() - mutableList.removeAt(index) - mutableList.add(index, it.next()) - selection = mutableList.toList() - } when (checkbox) { is CheckboxState.TriState -> { TriStateCheckbox( state = checkbox.asState(), - onClick = { onCheckboxChange(checkbox) }, + onClick = { onChange(checkbox) }, ) } is CheckboxState.State -> { Checkbox( checked = checkbox.isChecked, - onCheckedChange = { onCheckboxChange(checkbox) }, + onCheckedChange = { onChange(checkbox) }, ) } } diff --git a/app/src/main/java/eu/kanade/presentation/components/DeleteLibraryMangaDialog.kt b/app/src/main/java/eu/kanade/presentation/components/DeleteLibraryMangaDialog.kt index cc9a60e3c3..7eb6ba1686 100644 --- a/app/src/main/java/eu/kanade/presentation/components/DeleteLibraryMangaDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/components/DeleteLibraryMangaDialog.kt @@ -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.Row +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material3.AlertDialog import androidx.compose.material3.Checkbox import androidx.compose.material3.Text @@ -12,6 +14,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import eu.kanade.core.prefs.CheckboxState import eu.kanade.tachiyomi.R @@ -58,16 +61,23 @@ fun DeleteLibraryMangaDialog( text = { Column { list.forEach { state -> - Row(verticalAlignment = Alignment.CenterVertically) { + val onCheck = { + val index = list.indexOf(state) + val mutableList = list.toMutableList() + mutableList.removeAt(index) + mutableList.add(index, state.next() as CheckboxState.State) + list = mutableList.toList() + } + + Row( + modifier = Modifier + .fillMaxWidth() + .clickable { onCheck() }, + verticalAlignment = Alignment.CenterVertically, + ) { Checkbox( checked = state.isChecked, - onCheckedChange = { - val index = list.indexOf(state) - val mutableList = list.toMutableList() - mutableList.removeAt(index) - mutableList.add(index, state.next() as CheckboxState.State) - list = mutableList.toList() - }, + onCheckedChange = { onCheck() }, ) Text(text = stringResource(state.value)) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index ccc88f4426..95be196e85 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -13,6 +13,7 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.toDbManga import eu.kanade.presentation.components.ChangeCategoryDialog +import eu.kanade.presentation.components.DeleteLibraryMangaDialog import eu.kanade.presentation.library.LibraryScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.toDomainManga