2022-08-27 12:48:04 -04:00
|
|
|
package eu.kanade.presentation.components
|
2022-08-26 14:57:28 +02:00
|
|
|
|
2022-08-27 12:48:04 -04:00
|
|
|
import androidx.compose.foundation.clickable
|
2022-08-26 14:57:28 +02:00
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Row
|
2022-08-27 12:48:04 -04:00
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
2022-08-26 14:57:28 +02:00
|
|
|
import androidx.compose.material3.AlertDialog
|
|
|
|
import androidx.compose.material3.Checkbox
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.TextButton
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
import androidx.compose.ui.Alignment
|
2022-08-27 12:48:04 -04:00
|
|
|
import androidx.compose.ui.Modifier
|
2022-08-26 14:57:28 +02:00
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
import eu.kanade.core.prefs.CheckboxState
|
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun DeleteLibraryMangaDialog(
|
|
|
|
containsLocalManga: Boolean,
|
|
|
|
onDismissRequest: () -> Unit,
|
|
|
|
onConfirm: (Boolean, Boolean) -> Unit,
|
|
|
|
) {
|
|
|
|
var list by remember {
|
|
|
|
mutableStateOf(
|
|
|
|
buildList<CheckboxState.State<Int>> {
|
|
|
|
add(CheckboxState.State.None(R.string.manga_from_library))
|
|
|
|
if (!containsLocalManga) {
|
|
|
|
add(CheckboxState.State.None(R.string.downloaded_chapters))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
AlertDialog(
|
|
|
|
onDismissRequest = onDismissRequest,
|
|
|
|
dismissButton = {
|
|
|
|
TextButton(onClick = onDismissRequest) {
|
2022-08-26 09:16:26 -04:00
|
|
|
Text(text = stringResource(android.R.string.cancel))
|
2022-08-26 14:57:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
confirmButton = {
|
|
|
|
TextButton(
|
|
|
|
onClick = {
|
|
|
|
onDismissRequest()
|
|
|
|
onConfirm(
|
|
|
|
list[0].isChecked,
|
|
|
|
list.getOrElse(1) { CheckboxState.State.None(0) }.isChecked,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
) {
|
2022-08-26 09:16:26 -04:00
|
|
|
Text(text = stringResource(android.R.string.ok))
|
2022-08-26 14:57:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
title = {
|
2022-08-26 09:16:26 -04:00
|
|
|
Text(text = stringResource(R.string.action_remove))
|
2022-08-26 14:57:28 +02:00
|
|
|
},
|
|
|
|
text = {
|
|
|
|
Column {
|
|
|
|
list.forEach { state ->
|
2022-08-27 12:48:04 -04:00
|
|
|
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,
|
|
|
|
) {
|
2022-08-26 14:57:28 +02:00
|
|
|
Checkbox(
|
|
|
|
checked = state.isChecked,
|
2022-08-27 12:48:04 -04:00
|
|
|
onCheckedChange = { onCheck() },
|
2022-08-26 14:57:28 +02:00
|
|
|
)
|
2022-08-26 09:16:26 -04:00
|
|
|
Text(text = stringResource(state.value))
|
2022-08-26 14:57:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|