From ecc6ede0815a89b7f8288e47c607c57bacc47e71 Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Sun, 13 Apr 2025 20:24:31 +0500 Subject: [PATCH] Add option to keep read manga when clearing database (#1979) --- CHANGELOG.md | 1 + .../screen/advanced/ClearDatabaseScreen.kt | 49 ++++++++++++++++--- .../main/sqldelight/tachiyomi/data/mangas.sq | 13 ++++- .../moko-resources/base/strings.xml | 4 +- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e88736f..da0c0753a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Fix user notes not restoring when manga doesn't exist in DB ([@AntsyLich](https://github.com/AntsyLich)) ([#1945](https://github.com/mihonapp/mihon/pull/1945)) - Add markdown support for manga descriptions ([@Secozzi](https://github.com/Secozzi)) ([#1948](https://github.com/mihonapp/mihon/pull/1948)) - Add Nord Theme ([@Riztard](https://github.com/Riztard)) ([#1951](https://github.com/mihonapp/mihon/pull/1951)) +- Option to keep read manga when clearing database ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#1979](https://github.com/mihonapp/mihon/pull/1979)) ### Improved - Significantly improve browsing speed (near instantaneous) ([@AntsyLich](https://github.com/AntsyLich)) ([#1946](https://github.com/mihonapp/mihon/pull/1946)) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/advanced/ClearDatabaseScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/advanced/ClearDatabaseScreen.kt index eaaec9585..aab15bff2 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/advanced/ClearDatabaseScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/advanced/ClearDatabaseScreen.kt @@ -1,8 +1,10 @@ package eu.kanade.presentation.more.settings.screen.advanced import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.items @@ -12,13 +14,17 @@ import androidx.compose.material.icons.outlined.SelectAll import androidx.compose.material3.AlertDialog import androidx.compose.material3.Checkbox import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -39,6 +45,7 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.update import tachiyomi.core.common.util.lang.launchIO import tachiyomi.core.common.util.lang.launchUI +import tachiyomi.core.common.util.lang.toLong import tachiyomi.core.common.util.lang.withNonCancellableContext import tachiyomi.data.Database import tachiyomi.domain.source.interactor.GetSourcesWithNonLibraryManga @@ -47,6 +54,7 @@ import tachiyomi.domain.source.model.SourceWithCount import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.LazyColumnWithAction import tachiyomi.presentation.core.components.material.Scaffold +import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.screens.EmptyScreen import tachiyomi.presentation.core.screens.LoadingScreen @@ -68,13 +76,45 @@ class ClearDatabaseScreen : Screen() { is ClearDatabaseScreenModel.State.Loading -> LoadingScreen() is ClearDatabaseScreenModel.State.Ready -> { if (s.showConfirmation) { + var keepReadManga by remember { mutableStateOf(true) } AlertDialog( + title = { + Text(text = stringResource(MR.strings.are_you_sure)) + }, + text = { + Column( + verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small), + ) { + Text(text = stringResource(MR.strings.clear_database_text)) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.extraSmall), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = stringResource(MR.strings.clear_db_exclude_read), + modifier = Modifier.weight(1f), + ) + Switch( + checked = keepReadManga, + onCheckedChange = { keepReadManga = it }, + ) + } + if (!keepReadManga) { + Text( + text = stringResource(MR.strings.clear_database_history_warning), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.error, + ) + } + } + }, onDismissRequest = model::hideConfirmation, confirmButton = { TextButton( onClick = { scope.launchUI { - model.removeMangaBySourceId() + model.removeMangaBySourceId(keepReadManga) model.clearSelection() model.hideConfirmation() context.toast(MR.strings.clear_database_completed) @@ -89,9 +129,6 @@ class ClearDatabaseScreen : Screen() { Text(text = stringResource(MR.strings.action_cancel)) } }, - text = { - Text(text = stringResource(MR.strings.clear_database_confirmation)) - }, ) } @@ -203,9 +240,9 @@ private class ClearDatabaseScreenModel : StateScreenModelClear database Delete history for entries that are not saved in your library %1$d non-library entries in database - Are you sure? Read chapters and progress of non-library entries will be lost + You’re about to remove entries from the database + Read chapters and progress of non-library entries will be lost + Keep entries with read chapters Entries deleted Nothing to clear Clear WebView data