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 eefdff894..7935b0891 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,6 +14,7 @@ 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 @@ -42,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 @@ -52,6 +56,7 @@ import tachiyomi.i18n.sy.SYMR import tachiyomi.presentation.core.components.LabeledCheckbox 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 @@ -73,18 +78,45 @@ class ClearDatabaseScreen : Screen() { is ClearDatabaseScreenModel.State.Loading -> LoadingScreen() is ClearDatabaseScreenModel.State.Ready -> { if (s.showConfirmation) { - // SY --> var keepReadManga by remember { mutableStateOf(true) } - // SY <-- 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 { - // SY --> model.removeMangaBySourceId(keepReadManga) - // SY <-- model.clearSelection() model.hideConfirmation() context.toast(MR.strings.clear_database_completed) @@ -99,20 +131,6 @@ class ClearDatabaseScreen : Screen() { Text(text = stringResource(MR.strings.action_cancel)) } }, - text = { - // SY --> - Column { - // SY <-- - Text(text = stringResource(MR.strings.clear_database_confirmation)) - // SY --> - LabeledCheckbox( - label = stringResource(SYMR.strings.clear_db_exclude_read), - checked = keepReadManga, - onCheckedChange = { keepReadManga = it }, - ) - } - // SY <-- - }, ) } @@ -224,15 +242,9 @@ private class ClearDatabaseScreenModel : StateScreenModel */keepReadManga: Boolean /* SY <-- */) = withNonCancellableContext { + suspend fun removeMangaBySourceId(keepReadManga: Boolean) = withNonCancellableContext { val state = state.value as? State.Ready ?: return@withNonCancellableContext - // SY --> - if (keepReadManga) { - database.mangasQueries.deleteMangasNotInLibraryAndNotReadBySourceIds(state.selection) - } else { - database.mangasQueries.deleteMangasNotInLibraryBySourceIds(state.selection) - } - // SY <-- + database.mangasQueries.deleteNonLibraryManga(state.selection, keepReadManga.toLong()) database.historyQueries.removeResettedHistory() } diff --git a/data/src/main/sqldelight/tachiyomi/data/mangas.sq b/data/src/main/sqldelight/tachiyomi/data/mangas.sq index 87743b15a..d386084d6 100644 --- a/data/src/main/sqldelight/tachiyomi/data/mangas.sq +++ b/data/src/main/sqldelight/tachiyomi/data/mangas.sq @@ -168,22 +168,23 @@ FROM mangas WHERE favorite = 0 GROUP BY source; -deleteMangasNotInLibraryBySourceIds: +deleteNonLibraryManga: DELETE FROM mangas WHERE favorite = 0 AND source IN :sourceIds +AND ( + :keepReadManga = 0 + OR _id NOT IN ( + SELECT DISTINCT manga_id + FROM chapters + WHERE read = 1 + OR last_page_read != 0 + ) +) AND _id NOT IN ( SELECT manga_id FROM merged WHERE manga_id != merge_id ); -deleteMangasNotInLibraryAndNotReadBySourceIds: -DELETE FROM mangas -WHERE favorite = 0 AND source IN :sourceIdsAND AND _id NOT IN ( - SELECT manga_id FROM merged WHERE manga_id != merge_id -) AND _id NOT IN ( - SELECT manga_id FROM chapters WHERE read = 1 OR last_page_read != 0 -); - insert: INSERT INTO mangas(source, url, artist, author, description, genre, title, status, thumbnail_url, favorite, last_update, next_update, initialized, viewer, chapter_flags, cover_last_modified, date_added, update_strategy, calculate_interval, last_modified_at, version, notes) VALUES (:source, :url, :artist, :author, :description, :genre, :title, :status, :thumbnailUrl, :favorite, :lastUpdate, :nextUpdate, :initialized, :viewerFlags, :chapterFlags, :coverLastModified, :dateAdded, :updateStrategy, :calculateInterval, 0, :version, :notes); diff --git a/i18n/src/commonMain/moko-resources/base/strings.xml b/i18n/src/commonMain/moko-resources/base/strings.xml index f0caa34fe..d0baa3160 100755 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -600,7 +600,9 @@ Clear 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