Add option to keep read manga when clearing database (mihonapp/mihon#1979)
(cherry picked from commit ecc6ede0815a89b7f8288e47c607c57bacc47e71)
This commit is contained in:
parent
6e966746db
commit
55dc08d330
4 changed files with 52 additions and 39 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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,16 +45,16 @@ 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
|
||||
import tachiyomi.domain.source.model.Source
|
||||
import tachiyomi.domain.source.model.SourceWithCount
|
||||
import tachiyomi.i18n.MR
|
||||
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 +76,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 +129,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 +240,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,20 +168,20 @@ FROM mangas
|
|||
WHERE favorite = 0
|
||||
GROUP BY source;
|
||||
|
||||
deleteMangasNotInLibraryBySourceIds:
|
||||
deleteNonLibraryManga:
|
||||
DELETE FROM mangas
|
||||
WHERE favorite = 0
|
||||
AND source IN :sourceIds
|
||||
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 (
|
||||
: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 chapters WHERE read = 1 OR last_page_read != 0
|
||||
SELECT DISTINCT manga_id FROM merged WHERE manga_id != merge_id
|
||||
);
|
||||
|
||||
insert:
|
||||
|
|
|
|||
|
|
@ -602,7 +602,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…
Reference in a new issue