Skip to content

Commit

Permalink
Add ability to reset chapter flags to defaults
Browse files Browse the repository at this point in the history
Closes #10063
  • Loading branch information
arkon committed Oct 28, 2023
1 parent eed57b8 commit 118d3b7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -64,6 +65,13 @@ fun ChapterSettingsDialog(
closeMenu()
},
)
DropdownMenuItem(
text = { Text(stringResource(R.string.action_reset)) },
onClick = {
onResetToDefault()
closeMenu()
},
)
},
) { page ->
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -309,7 +309,7 @@ object SettingsAdvancedScreen : SearchableSettings {
subtitle = stringResource(R.string.pref_reset_viewer_flags_summary),
onClick = {
scope.launchNonCancellable {
val success = Injekt.get<MangaRepository>().resetViewerFlags()
val success = Injekt.get<ResetViewerFlags>().await()
withUIContext {
val message = if (success) {
R.string.pref_reset_viewer_flags_success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class MangaScreen(
onSortModeChanged = screenModel::setSorting,
onDisplayModeChanged = screenModel::setDisplayMode,
onSetAsDefault = screenModel::setCurrentSettingsAsDefault,
onResetToDefault = screenModel::resetToDefaultSettings,
)
MangaScreenModel.Dialog.TrackSheet -> {
NavigatorAdaptiveSheet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,13 @@ class MangaScreenModel(
}
}

fun resetToDefaultSettings() {
val manga = successState?.manga ?: return
screenModelScope.launchNonCancellable {
setMangaDefaultChapterFlags.await(manga)
}
}

fun toggleSelection(
item: ChapterItem,
selected: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions data/src/main/sqldelight/tachiyomi/data/mangas.sq
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 118d3b7

Please sign in to comment.