From 118d3b7fcc5cf8a27e52ff690cb3ecd28860c10c Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 28 Oct 2023 15:28:39 -0400 Subject: [PATCH] Add ability to reset chapter flags to defaults Closes #10063 --- .../kanade/domain/manga/interactor/SetMangaViewerFlags.kt | 4 ++-- .../eu/kanade/presentation/manga/ChapterSettingsDialog.kt | 8 ++++++++ .../more/settings/screen/SettingsAdvancedScreen.kt | 4 ++-- .../main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt | 1 + .../java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 7 +++++++ .../java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt | 4 ++-- data/src/main/sqldelight/tachiyomi/data/mangas.sq | 6 ++++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/manga/interactor/SetMangaViewerFlags.kt b/app/src/main/java/eu/kanade/domain/manga/interactor/SetMangaViewerFlags.kt index 521be8b8c9..8ffc27bb9b 100644 --- a/app/src/main/java/eu/kanade/domain/manga/interactor/SetMangaViewerFlags.kt +++ b/app/src/main/java/eu/kanade/domain/manga/interactor/SetMangaViewerFlags.kt @@ -9,7 +9,7 @@ class SetMangaViewerFlags( private val mangaRepository: MangaRepository, ) { - suspend fun awaitSetMangaReadingMode(id: Long, flag: Long) { + suspend fun awaitSetReadingMode(id: Long, flag: Long) { val manga = mangaRepository.getMangaById(id) mangaRepository.update( MangaUpdate( @@ -19,7 +19,7 @@ class SetMangaViewerFlags( ) } - suspend fun awaitSetOrientationType(id: Long, flag: Long) { + suspend fun awaitSetOrientation(id: Long, flag: Long) { val manga = mangaRepository.getMangaById(id) mangaRepository.update( MangaUpdate( diff --git a/app/src/main/java/eu/kanade/presentation/manga/ChapterSettingsDialog.kt b/app/src/main/java/eu/kanade/presentation/manga/ChapterSettingsDialog.kt index 9f842fead5..b90a86fa54 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/ChapterSettingsDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/ChapterSettingsDialog.kt @@ -40,6 +40,7 @@ fun ChapterSettingsDialog( onSortModeChanged: (Long) -> Unit, onDisplayModeChanged: (Long) -> Unit, onSetAsDefault: (applyToExistingManga: Boolean) -> Unit, + onResetToDefault: () -> Unit, ) { var showSetAsDefaultDialog by rememberSaveable { mutableStateOf(false) } if (showSetAsDefaultDialog) { @@ -64,6 +65,13 @@ fun ChapterSettingsDialog( closeMenu() }, ) + DropdownMenuItem( + text = { Text(stringResource(R.string.action_reset)) }, + onClick = { + onResetToDefault() + closeMenu() + }, + ) }, ) { page -> Column( diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index 34e1981a9c..97d852e50f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -59,7 +59,7 @@ import okhttp3.Headers import tachiyomi.core.util.lang.launchNonCancellable import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.system.logcat -import tachiyomi.domain.manga.repository.MangaRepository +import tachiyomi.domain.manga.interactor.ResetViewerFlags import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -309,7 +309,7 @@ object SettingsAdvancedScreen : SearchableSettings { subtitle = stringResource(R.string.pref_reset_viewer_flags_summary), onClick = { scope.launchNonCancellable { - val success = Injekt.get().resetViewerFlags() + val success = Injekt.get().await() withUIContext { val message = if (success) { R.string.pref_reset_viewer_flags_success diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index 39595fbe5a..f16767a494 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -172,6 +172,7 @@ class MangaScreen( onSortModeChanged = screenModel::setSorting, onDisplayModeChanged = screenModel::setDisplayMode, onSetAsDefault = screenModel::setCurrentSettingsAsDefault, + onResetToDefault = screenModel::resetToDefaultSettings, ) MangaScreenModel.Dialog.TrackSheet -> { NavigatorAdaptiveSheet( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 95feba4873..a4f6f5d957 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -834,6 +834,13 @@ class MangaScreenModel( } } + fun resetToDefaultSettings() { + val manga = successState?.manga ?: return + screenModelScope.launchNonCancellable { + setMangaDefaultChapterFlags.await(manga) + } + } + fun toggleSelection( item: ChapterItem, selected: Boolean, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 555bdef3ae..d1c91b62a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -630,7 +630,7 @@ class ReaderViewModel @JvmOverloads constructor( fun setMangaReadingMode(readingModeType: ReadingModeType) { val manga = manga ?: return runBlocking(Dispatchers.IO) { - setMangaViewerFlags.awaitSetMangaReadingMode(manga.id, readingModeType.flagValue.toLong()) + setMangaViewerFlags.awaitSetReadingMode(manga.id, readingModeType.flagValue.toLong()) val currChapters = state.value.viewerChapters if (currChapters != null) { // Save current page @@ -666,7 +666,7 @@ class ReaderViewModel @JvmOverloads constructor( fun setMangaOrientationType(rotationType: OrientationType) { val manga = manga ?: return viewModelScope.launchIO { - setMangaViewerFlags.awaitSetOrientationType(manga.id, rotationType.flagValue.toLong()) + setMangaViewerFlags.awaitSetOrientation(manga.id, rotationType.flagValue.toLong()) val currChapters = state.value.viewerChapters if (currChapters != null) { // Save current page diff --git a/data/src/main/sqldelight/tachiyomi/data/mangas.sq b/data/src/main/sqldelight/tachiyomi/data/mangas.sq index 7260332def..220b908ad7 100644 --- a/data/src/main/sqldelight/tachiyomi/data/mangas.sq +++ b/data/src/main/sqldelight/tachiyomi/data/mangas.sq @@ -57,7 +57,8 @@ WHERE _id = :id; getMangaByUrlAndSource: SELECT * FROM mangas -WHERE url = :url AND source = :source +WHERE url = :url +AND source = :source LIMIT 1; getFavorites: @@ -107,7 +108,8 @@ GROUP BY source; deleteMangasNotInLibraryBySourceIds: DELETE FROM mangas -WHERE favorite = 0 AND source IN :sourceIds; +WHERE favorite = 0 +AND source IN :sourceIds; 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)