mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Fix checkbox selection when tapping text in Compose dialogs
This commit is contained in:
parent
8d40e20b7d
commit
cd82c88b9a
3 changed files with 34 additions and 18 deletions
|
@ -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<Category>) -> 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<Category>) -> 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) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Int>)
|
||||
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<Int>)
|
||||
list = mutableList.toList()
|
||||
},
|
||||
onCheckedChange = { onCheck() },
|
||||
)
|
||||
Text(text = stringResource(state.value))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue