Skip to content

Commit

Permalink
Shorten restore warning message a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed Dec 30, 2023
1 parent 5bba7af commit f3b7eaf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RestoreBackupScreen(
}

if (state.error != null) {
errorMessageItem(state, model)
errorMessageItem(state.error)
}
}

Expand All @@ -118,32 +118,31 @@ class RestoreBackupScreen(
}

private fun LazyListScope.errorMessageItem(
state: RestoreBackupScreenModel.State,
model: RestoreBackupScreenModel,
error: Any?,
) {
item {
SectionCard {
Column(
modifier = Modifier.padding(horizontal = MaterialTheme.padding.medium),
verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
) {
when (val err = state.error) {
when (error) {
is MissingRestoreComponents -> {
val msg = buildString {
append(stringResource(MR.strings.backup_restore_content_full))
if (err.sources.isNotEmpty()) {
if (error.sources.isNotEmpty()) {
append("\n\n")
append(stringResource(MR.strings.backup_restore_missing_sources))
err.sources.joinTo(
error.sources.joinTo(
this,
separator = "\n- ",
prefix = "\n- ",
)
}
if (err.trackers.isNotEmpty()) {
if (error.trackers.isNotEmpty()) {
append("\n\n")
append(stringResource(MR.strings.backup_restore_missing_trackers))
err.trackers.joinTo(
error.trackers.joinTo(
this,
separator = "\n- ",
prefix = "\n- ",
Expand All @@ -159,13 +158,13 @@ class RestoreBackupScreen(
Text(text = stringResource(MR.strings.invalid_backup_file))

SelectionContainer {
Text(text = listOfNotNull(err.uri, err.message).joinToString("\n\n"))
Text(text = listOfNotNull(error.uri, error.message).joinToString("\n\n"))
}
}

else -> {
SelectionContainer {
Text(text = err.toString())
Text(text = error.toString())
}
}
}
Expand All @@ -184,6 +183,22 @@ private class RestoreBackupScreenModel(
validate(uri)
}

fun toggle(setter: (RestoreOptions, Boolean) -> RestoreOptions, enabled: Boolean) {
mutableState.update {
it.copy(
options = setter(it.options, enabled),
)
}
}

fun startRestore() {
BackupRestoreJob.start(
context = context,
uri = uri,
options = state.value.options,
)
}

private fun validate(uri: Uri) {
val results = try {
BackupFileValidator(context).validate(uri)
Expand All @@ -206,22 +221,6 @@ private class RestoreBackupScreenModel(
setError(error = null, canRestore = true)
}

fun toggle(setter: (RestoreOptions, Boolean) -> RestoreOptions, enabled: Boolean) {
mutableState.update {
it.copy(
options = setter(it.options, enabled),
)
}
}

fun startRestore() {
BackupRestoreJob.start(
context = context,
uri = uri,
options = state.value.options,
)
}

private fun setError(error: Any?, canRestore: Boolean) {
mutableState.update {
it.copy(
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
<string name="invalid_backup_file_missing_manga">Backup does not contain any library entries.</string>
<string name="backup_restore_missing_sources">Missing sources:</string>
<string name="backup_restore_missing_trackers">Trackers not logged into:</string>
<string name="backup_restore_content_full">Data from the backup file will be restored.\n\nYou may need to install any missing extensions and log in to tracking services afterwards to use them.</string>
<string name="backup_restore_content_full">You may need to install any missing extensions and log in to tracking services afterwards to use them.</string>
<string name="restore_completed">Restore completed</string>
<string name="restore_duration">%02d min, %02d sec</string>
<string name="backup_in_progress">Backup is already in progress</string>
Expand Down

0 comments on commit f3b7eaf

Please sign in to comment.