* feat(local): Allow delete local files * Refresh chapters list after deleting * Allow delete whole entry's downloaded folder & clear episodes/chapters list Also hide `Open folder` for merged entries * Don't delete local folder & refresh local's chapters list state after clear * use forEachIndexed instead of forEach * adding comment * add empty line
74 lines
2.6 KiB
Kotlin
74 lines
2.6 KiB
Kotlin
package eu.kanade.presentation.library
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.material3.AlertDialog
|
|
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 dev.icerock.moko.resources.StringResource
|
|
import tachiyomi.core.common.preference.CheckboxState
|
|
import tachiyomi.i18n.MR
|
|
import tachiyomi.presentation.core.components.LabeledCheckbox
|
|
import tachiyomi.presentation.core.i18n.stringResource
|
|
|
|
@Composable
|
|
fun DeleteLibraryMangaDialog(
|
|
containsLocalManga: Boolean,
|
|
onDismissRequest: () -> Unit,
|
|
onConfirm: (Boolean, Boolean) -> Unit,
|
|
) {
|
|
var list by remember {
|
|
mutableStateOf(
|
|
buildList<CheckboxState.State<StringResource>> {
|
|
add(CheckboxState.State.None(MR.strings.manga_from_library))
|
|
if (!containsLocalManga) {
|
|
add(CheckboxState.State.None(MR.strings.downloaded_chapters))
|
|
}
|
|
},
|
|
)
|
|
}
|
|
AlertDialog(
|
|
onDismissRequest = onDismissRequest,
|
|
dismissButton = {
|
|
TextButton(onClick = onDismissRequest) {
|
|
Text(text = stringResource(MR.strings.action_cancel))
|
|
}
|
|
},
|
|
confirmButton = {
|
|
TextButton(
|
|
enabled = list.any { it.isChecked },
|
|
onClick = {
|
|
onDismissRequest()
|
|
onConfirm(
|
|
list[0].isChecked,
|
|
list.getOrElse(1) { CheckboxState.State.None(0) }.isChecked,
|
|
)
|
|
},
|
|
) {
|
|
Text(text = stringResource(MR.strings.action_ok))
|
|
}
|
|
},
|
|
title = {
|
|
Text(text = stringResource(MR.strings.action_remove))
|
|
},
|
|
text = {
|
|
Column {
|
|
list.forEachIndexed { index, state ->
|
|
LabeledCheckbox(
|
|
label = stringResource(state.value),
|
|
checked = state.isChecked,
|
|
onCheckedChange = {
|
|
val mutableList = list.toMutableList()
|
|
mutableList[index] = state.next() as CheckboxState.State<StringResource>
|
|
list = mutableList.toList()
|
|
},
|
|
)
|
|
}
|
|
}
|
|
},
|
|
)
|
|
}
|