Add option to keep read manga when clearing database (#1979)
(cherry picked from commit ecc6ede0815a89b7f8288e47c607c57bacc47e71) # Conflicts: # CHANGELOG.md # app/src/main/java/eu/kanade/presentation/more/settings/screen/advanced/ClearDatabaseScreen.kt # data/src/main/sqldelight/tachiyomi/data/mangas.sq
This commit is contained in:
parent
746b1b051c
commit
85726db45d
@ -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<ClearDatabaseScreenMod
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun removeMangaBySourceId(/* SY --> */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()
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -600,7 +600,9 @@
|
||||
<string name="pref_clear_database">Clear database</string>
|
||||
<string name="pref_clear_database_summary">Delete history for entries that are not saved in your library</string>
|
||||
<string name="clear_database_source_item_count">%1$d non-library entries in database</string>
|
||||
<string name="clear_database_confirmation">Are you sure? Read chapters and progress of non-library entries will be lost</string>
|
||||
<string name="clear_database_text">You’re about to remove entries from the database</string>
|
||||
<string name="clear_database_history_warning">Read chapters and progress of non-library entries will be lost</string>
|
||||
<string name="clear_db_exclude_read">Keep entries with read chapters</string>
|
||||
<string name="clear_database_completed">Entries deleted</string>
|
||||
<string name="database_clean">Nothing to clear</string>
|
||||
<string name="pref_clear_webview_data">Clear WebView data</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user