mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
style: Fix inconsistency
This commit is contained in:
parent
e45dffcb16
commit
dd6ad1fbbb
1 changed files with 34 additions and 84 deletions
|
@ -2,18 +2,10 @@ package dev.yokai.presentation.settings.screen.data
|
|||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.AlertDialogDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
|
@ -21,13 +13,9 @@ 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
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.hippo.unifile.UniFile
|
||||
import dev.yokai.presentation.component.LabeledCheckbox
|
||||
import dev.yokai.presentation.theme.Size
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.backup.BackupFileValidator.Results
|
||||
import eu.kanade.tachiyomi.data.backup.create.BackupCreatorJob
|
||||
|
@ -35,7 +23,6 @@ import eu.kanade.tachiyomi.data.backup.create.BackupOptions
|
|||
import eu.kanade.tachiyomi.data.backup.models.Backup
|
||||
import eu.kanade.tachiyomi.data.backup.restore.BackupRestoreJob
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
@Composable
|
||||
fun RestoreBackup(
|
||||
|
@ -105,78 +92,41 @@ fun CreateBackup(
|
|||
) {
|
||||
var options by remember { mutableStateOf(BackupOptions()) }
|
||||
|
||||
Dialog(onDismissRequest = onDismissRequest) {
|
||||
Surface(
|
||||
modifier = Modifier,
|
||||
shape = AlertDialogDefaults.shape,
|
||||
color = AlertDialogDefaults.containerColor,
|
||||
tonalElevation = AlertDialogDefaults.TonalElevation,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(Size.large),
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(Size.medium)
|
||||
.align(Alignment.Start),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.create_backup),
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(weight = 1f, fill = false)
|
||||
.padding(Size.medium)
|
||||
.align(Alignment.Start)
|
||||
) {
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.wrapContentSize(),
|
||||
) {
|
||||
options(BackupOptions.getEntries(), options) { option, enabled ->
|
||||
options = option.setter(options, enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.align(Alignment.End)) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(Size.small)) {
|
||||
TextButton(onClick = {
|
||||
val actualUri =
|
||||
UniFile.fromUri(context, uri)?.createFile(Backup.getBackupFilename())?.uri ?: return@TextButton
|
||||
context.toast(R.string.creating_backup)
|
||||
BackupCreatorJob.startNow(context, actualUri, options)
|
||||
onDismissRequest()
|
||||
}) {
|
||||
Text(stringResource(R.string.create))
|
||||
}
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
val actualUri =
|
||||
UniFile.fromUri(context, uri)?.createFile(Backup.getBackupFilename())?.uri ?: return@TextButton
|
||||
context.toast(R.string.creating_backup)
|
||||
BackupCreatorJob.startNow(context, actualUri, options)
|
||||
onDismissRequest()
|
||||
}) {
|
||||
Text(stringResource(R.string.create))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
},
|
||||
title = { Text(text = stringResource(R.string.create_backup)) },
|
||||
text = {
|
||||
Box {
|
||||
val state = rememberLazyListState()
|
||||
LazyColumn(state = state) {
|
||||
BackupOptions.getEntries().forEach { option ->
|
||||
item {
|
||||
LabeledCheckbox(
|
||||
label = stringResource(option.label),
|
||||
checked = option.getter(options),
|
||||
onCheckedChange = { options = option.setter(options, it) },
|
||||
enabled = option.enabled(options),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun LazyListScope.options(
|
||||
options: ImmutableList<BackupOptions.Entry>,
|
||||
state: BackupOptions,
|
||||
onChange: (BackupOptions.Entry, Boolean) -> Unit,
|
||||
) {
|
||||
items(options.size) {
|
||||
val option = options[it]
|
||||
LabeledCheckbox(
|
||||
label = stringResource(option.label),
|
||||
checked = option.getter(state),
|
||||
onCheckedChange = {
|
||||
onChange(option, it)
|
||||
},
|
||||
enabled = option.enabled(state),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue