From 4502902fb0df21f637c905dc5c4c36625dedc710 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 5 Nov 2023 10:01:19 -0500 Subject: [PATCH] Clean up reading mode / orientation enum classes Categorizing the reading modes so we can implement a better selection UI. --- .../manga/interactor/SetMangaViewerFlags.kt | 8 +-- .../eu/kanade/domain/manga/model/Manga.kt | 12 ++-- .../settings/screen/SettingsReaderScreen.kt | 8 +-- ...ctDialog.kt => OrientationSelectDialog.kt} | 20 +++---- .../reader/ReadingModeSelectDialog.kt | 14 ++--- .../reader/appbars/BottomReaderBar.kt | 14 ++--- .../reader/appbars/ReaderAppBars.kt | 14 ++--- .../reader/settings/ReadingModePage.kt | 34 +++++------ .../java/eu/kanade/tachiyomi/Migrations.kt | 14 ++--- .../data/backup/models/BackupManga.kt | 4 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 28 ++++----- .../tachiyomi/ui/reader/ReaderViewModel.kt | 34 +++++------ ...rientationType.kt => ReaderOrientation.kt} | 4 +- .../ui/reader/setting/ReaderPreferences.kt | 4 +- .../setting/ReaderSettingsScreenModel.kt | 4 +- .../{ReadingModeType.kt => ReadingMode.kt} | 58 ++++++++++++++++--- 16 files changed, 156 insertions(+), 118 deletions(-) rename app/src/main/java/eu/kanade/presentation/reader/{OrientationModeSelectDialog.kt => OrientationSelectDialog.kt} (79%) rename app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/{OrientationType.kt => ReaderOrientation.kt} (91%) rename app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/{ReadingModeType.kt => ReadingMode.kt} (50%) 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 8ffc27bb9..083d26e98 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 @@ -1,7 +1,7 @@ package eu.kanade.domain.manga.interactor -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import tachiyomi.domain.manga.model.MangaUpdate import tachiyomi.domain.manga.repository.MangaRepository @@ -14,7 +14,7 @@ class SetMangaViewerFlags( mangaRepository.update( MangaUpdate( id = id, - viewerFlags = manga.viewerFlags.setFlag(flag, ReadingModeType.MASK.toLong()), + viewerFlags = manga.viewerFlags.setFlag(flag, ReadingMode.MASK.toLong()), ), ) } @@ -24,7 +24,7 @@ class SetMangaViewerFlags( mangaRepository.update( MangaUpdate( id = id, - viewerFlags = manga.viewerFlags.setFlag(flag, OrientationType.MASK.toLong()), + viewerFlags = manga.viewerFlags.setFlag(flag, ReaderOrientation.MASK.toLong()), ), ) } diff --git a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt index 6c2ee4a5e..686b29f43 100644 --- a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt @@ -3,8 +3,8 @@ package eu.kanade.domain.manga.model import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import tachiyomi.core.metadata.comicinfo.ComicInfo import tachiyomi.core.metadata.comicinfo.ComicInfoPublishingStatus import tachiyomi.core.preference.TriState @@ -14,11 +14,11 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get // TODO: move these into the domain model -val Manga.readingModeType: Long - get() = viewerFlags and ReadingModeType.MASK.toLong() +val Manga.readingMode: Long + get() = viewerFlags and ReadingMode.MASK.toLong() -val Manga.orientationType: Long - get() = viewerFlags and OrientationType.MASK.toLong() +val Manga.readerOrientation: Long + get() = viewerFlags and ReaderOrientation.MASK.toLong() val Manga.downloadedFilter: TriState get() { diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index 4d975200a..ab2759c39 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -10,9 +10,9 @@ import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import eu.kanade.presentation.more.settings.Preference import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -32,7 +32,7 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.ListPreference( pref = readerPref.defaultReadingMode(), title = stringResource(R.string.pref_viewer_type), - entries = ReadingModeType.entries.drop(1) + entries = ReadingMode.entries.drop(1) .associate { it.flagValue to stringResource(it.stringRes) }, ), Preference.PreferenceItem.ListPreference( @@ -88,7 +88,7 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.ListPreference( pref = readerPreferences.defaultOrientationType(), title = stringResource(R.string.pref_rotation_type), - entries = OrientationType.entries.drop(1) + entries = ReaderOrientation.entries.drop(1) .associate { it.flagValue to stringResource(it.stringRes) }, ), Preference.PreferenceItem.ListPreference( diff --git a/app/src/main/java/eu/kanade/presentation/reader/OrientationModeSelectDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt similarity index 79% rename from app/src/main/java/eu/kanade/presentation/reader/OrientationModeSelectDialog.kt rename to app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt index a143634ab..08a08c08b 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/OrientationModeSelectDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt @@ -13,28 +13,28 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.unit.dp -import eu.kanade.domain.manga.model.orientationType +import eu.kanade.domain.manga.model.readerOrientation import eu.kanade.presentation.components.AdaptiveSheet import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import tachiyomi.presentation.core.components.SettingsIconGrid import tachiyomi.presentation.core.components.material.IconToggleButton import tachiyomi.presentation.core.util.ThemePreviews @Composable -fun OrientationModeSelectDialog( +fun OrientationSelectDialog( onDismissRequest: () -> Unit, screenModel: ReaderSettingsScreenModel, onChange: (Int) -> Unit, ) { val manga by screenModel.mangaFlow.collectAsState() - val orientationType = remember(manga) { OrientationType.fromPreference(manga?.orientationType?.toInt()) } + val orientation = remember(manga) { ReaderOrientation.fromPreference(manga?.readerOrientation?.toInt()) } AdaptiveSheet(onDismissRequest = onDismissRequest) { DialogContent( - orientationType = orientationType, + orientation = orientation, onChangeOrientation = { screenModel.onChangeOrientation(it) onChange(it.stringRes) @@ -46,14 +46,14 @@ fun OrientationModeSelectDialog( @Composable private fun DialogContent( - orientationType: OrientationType, - onChangeOrientation: (OrientationType) -> Unit, + orientation: ReaderOrientation, + onChangeOrientation: (ReaderOrientation) -> Unit, ) { Box(modifier = Modifier.padding(vertical = 16.dp)) { SettingsIconGrid(R.string.rotation_type) { - items(OrientationType.entries) { mode -> + items(ReaderOrientation.entries) { mode -> IconToggleButton( - checked = mode == orientationType, + checked = mode == orientation, onCheckedChange = { onChangeOrientation(mode) }, @@ -71,7 +71,7 @@ private fun DialogContent( private fun DialogContentPreview() { TachiyomiTheme { DialogContent( - orientationType = OrientationType.DEFAULT, + orientation = ReaderOrientation.DEFAULT, onChangeOrientation = {}, ) } diff --git a/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt index a2089c7f5..2d976f92a 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt @@ -13,12 +13,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource -import eu.kanade.domain.manga.model.readingModeType +import eu.kanade.domain.manga.model.readingMode import eu.kanade.presentation.components.AdaptiveSheet import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import tachiyomi.presentation.core.components.SettingsIconGrid import tachiyomi.presentation.core.components.material.IconToggleButton import tachiyomi.presentation.core.components.material.padding @@ -31,7 +31,7 @@ fun ReadingModeSelectDialog( onChange: (Int) -> Unit, ) { val manga by screenModel.mangaFlow.collectAsState() - val readingMode = remember(manga) { ReadingModeType.fromPreference(manga?.readingModeType?.toInt()) } + val readingMode = remember(manga) { ReadingMode.fromPreference(manga?.readingMode?.toInt()) } AdaptiveSheet(onDismissRequest = onDismissRequest) { DialogContent( @@ -47,12 +47,12 @@ fun ReadingModeSelectDialog( @Composable private fun DialogContent( - readingMode: ReadingModeType, - onChangeReadingMode: (ReadingModeType) -> Unit, + readingMode: ReadingMode, + onChangeReadingMode: (ReadingMode) -> Unit, ) { Box(modifier = Modifier.padding(vertical = MaterialTheme.padding.medium)) { SettingsIconGrid(R.string.pref_category_reading_mode) { - items(ReadingModeType.entries) { mode -> + items(ReadingMode.entries) { mode -> IconToggleButton( checked = mode == readingMode, onCheckedChange = { @@ -72,7 +72,7 @@ private fun DialogContent( private fun DialogContentPreview() { TachiyomiTheme { DialogContent( - readingMode = ReadingModeType.DEFAULT, + readingMode = ReadingMode.DEFAULT, onChangeReadingMode = {}, ) } diff --git a/app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt b/app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt index e48867fcb..041f68c5e 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt @@ -17,16 +17,16 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode @Composable fun BottomReaderBar( backgroundColor: Color, - readingMode: ReadingModeType, + readingMode: ReadingMode, onClickReadingMode: () -> Unit, - orientationMode: OrientationType, - onClickOrientationMode: () -> Unit, + orientation: ReaderOrientation, + onClickOrientation: () -> Unit, cropEnabled: Boolean, onClickCropBorder: () -> Unit, onClickSettings: () -> Unit, @@ -53,9 +53,9 @@ fun BottomReaderBar( ) } - IconButton(onClick = onClickOrientationMode) { + IconButton(onClick = onClickOrientation) { Icon( - painter = painterResource(orientationMode.iconRes), + painter = painterResource(orientation.iconRes), contentDescription = stringResource(R.string.pref_rotation_type), ) } diff --git a/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt b/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt index 7b360b04d..de3d0131f 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt @@ -24,8 +24,8 @@ import androidx.compose.ui.unit.dp import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import eu.kanade.tachiyomi.ui.reader.viewer.Viewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer @@ -54,10 +54,10 @@ fun ReaderAppBars( totalPages: Int, onSliderValueChange: (Int) -> Unit, - readingMode: ReadingModeType, + readingMode: ReadingMode, onClickReadingMode: () -> Unit, - orientationMode: OrientationType, - onClickOrientationMode: () -> Unit, + orientation: ReaderOrientation, + onClickOrientation: () -> Unit, cropEnabled: Boolean, onClickCropBorder: () -> Unit, onClickSettings: () -> Unit, @@ -155,8 +155,8 @@ fun ReaderAppBars( backgroundColor = backgroundColor, readingMode = readingMode, onClickReadingMode = onClickReadingMode, - orientationMode = orientationMode, - onClickOrientationMode = onClickOrientationMode, + orientation = orientation, + onClickOrientation = onClickOrientation, cropEnabled = cropEnabled, onClickCropBorder = onClickCropBorder, onClickSettings = onClickSettings, diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt index 07d6cb49a..8bf1d0079 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt @@ -8,13 +8,13 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.res.stringResource -import eu.kanade.domain.manga.model.orientationType -import eu.kanade.domain.manga.model.readingModeType +import eu.kanade.domain.manga.model.readerOrientation +import eu.kanade.domain.manga.model.readingMode import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.HeadingItem @@ -23,33 +23,29 @@ import tachiyomi.presentation.core.components.SliderItem import tachiyomi.presentation.core.util.collectAsState import java.text.NumberFormat -private val readingModeOptions = ReadingModeType.entries.map { it.stringRes to it } -private val orientationTypeOptions = OrientationType.entries.map { it.stringRes to it } -private val tappingInvertModeOptions = ReaderPreferences.TappingInvertMode.entries.map { it.titleResId to it } - @Composable internal fun ColumnScope.ReadingModePage(screenModel: ReaderSettingsScreenModel) { HeadingItem(R.string.pref_category_for_this_series) val manga by screenModel.mangaFlow.collectAsState() - val readingMode = remember(manga) { ReadingModeType.fromPreference(manga?.readingModeType?.toInt()) } + val readingMode = remember(manga) { ReadingMode.fromPreference(manga?.readingMode?.toInt()) } SettingsChipRow(R.string.pref_category_reading_mode) { - readingModeOptions.map { (stringRes, it) -> + ReadingMode.entries.map { FilterChip( selected = it == readingMode, onClick = { screenModel.onChangeReadingMode(it) }, - label = { Text(stringResource(stringRes)) }, + label = { Text(stringResource(it.stringRes)) }, ) } } - val orientationType = remember(manga) { OrientationType.fromPreference(manga?.orientationType?.toInt()) } + val orientation = remember(manga) { ReaderOrientation.fromPreference(manga?.readerOrientation?.toInt()) } SettingsChipRow(R.string.rotation_type) { - orientationTypeOptions.map { (stringRes, it) -> + ReaderOrientation.entries.map { FilterChip( - selected = it == orientationType, + selected = it == orientation, onClick = { screenModel.onChangeOrientation(it) }, - label = { Text(stringResource(stringRes)) }, + label = { Text(stringResource(it.stringRes)) }, ) } } @@ -209,11 +205,11 @@ private fun ColumnScope.TapZonesItems( if (selected != 5) { SettingsChipRow(R.string.pref_read_with_tapping_inverted) { - tappingInvertModeOptions.map { (stringRes, mode) -> + ReaderPreferences.TappingInvertMode.entries.map { FilterChip( - selected = mode == invertMode, - onClick = { onSelectInvertMode(mode) }, - label = { Text(stringResource(stringRes)) }, + selected = it == invertMode, + onClick = { onSelectInvertMode(it) }, + label = { Text(stringResource(it.titleResId)) }, ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index bd672e316..b3889f2e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.toast @@ -170,12 +170,12 @@ object Migrations { if (oldVersion < 60) { // Migrate Rotation and Viewer values to default values for viewer_flags val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) { - 1 -> OrientationType.FREE.flagValue - 2 -> OrientationType.PORTRAIT.flagValue - 3 -> OrientationType.LANDSCAPE.flagValue - 4 -> OrientationType.LOCKED_PORTRAIT.flagValue - 5 -> OrientationType.LOCKED_LANDSCAPE.flagValue - else -> OrientationType.FREE.flagValue + 1 -> ReaderOrientation.FREE.flagValue + 2 -> ReaderOrientation.PORTRAIT.flagValue + 3 -> ReaderOrientation.LANDSCAPE.flagValue + 4 -> ReaderOrientation.LOCKED_PORTRAIT.flagValue + 5 -> ReaderOrientation.LOCKED_LANDSCAPE.flagValue + else -> ReaderOrientation.FREE.flagValue } // Reading mode flag and prefValue is the same value diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupManga.kt index a3d0f4493..8dd429c15 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupManga.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.data.backup.models import eu.kanade.tachiyomi.source.model.UpdateStrategy -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoNumber import tachiyomi.domain.chapter.model.Chapter @@ -89,7 +89,7 @@ data class BackupManga( favorite = manga.favorite, source = manga.source, dateAdded = manga.dateAdded, - viewer = (manga.viewerFlags.toInt() and ReadingModeType.MASK), + viewer = (manga.viewerFlags.toInt() and ReadingMode.MASK), viewer_flags = manga.viewerFlags.toInt(), chapterFlags = manga.chapterFlags.toInt(), updateStrategy = manga.updateStrategy, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index a9428213f..108b9dcef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -44,7 +44,7 @@ import dev.chrisbanes.insetter.applyInsetter import eu.kanade.domain.base.BasePreferences import eu.kanade.presentation.reader.BrightnessOverlay import eu.kanade.presentation.reader.DisplayRefreshHost -import eu.kanade.presentation.reader.OrientationModeSelectDialog +import eu.kanade.presentation.reader.OrientationSelectDialog import eu.kanade.presentation.reader.PageIndicatorText import eu.kanade.presentation.reader.ReaderPageActionsDialog import eu.kanade.presentation.reader.ReadingModeSelectDialog @@ -63,10 +63,10 @@ import eu.kanade.tachiyomi.ui.reader.ReaderViewModel.SetAsCoverResult.Success import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.system.hasDisplayCutout @@ -332,7 +332,7 @@ class ReaderActivity : BaseActivity() { val cropBorderPaged by readerPreferences.cropBorders().collectAsState() val cropBorderWebtoon by readerPreferences.cropBordersWebtoon().collectAsState() - val isPagerType = ReadingModeType.isPagerType(viewModel.getMangaReadingMode()) + val isPagerType = ReadingMode.isPagerType(viewModel.getMangaReadingMode()) val cropEnabled = if (isPagerType) cropBorderPaged else cropBorderWebtoon ReaderAppBars( @@ -360,14 +360,14 @@ class ReaderActivity : BaseActivity() { moveToPageIndex(it) }, - readingMode = ReadingModeType.fromPreference( + readingMode = ReadingMode.fromPreference( viewModel.getMangaReadingMode(resolveDefault = false), ), onClickReadingMode = viewModel::openReadingModeSelectDialog, - orientationMode = OrientationType.fromPreference( - viewModel.getMangaOrientationType(resolveDefault = false), + orientation = ReaderOrientation.fromPreference( + viewModel.getMangaOrientation(resolveDefault = false), ), - onClickOrientationMode = viewModel::openOrientationModeSelectDialog, + onClickOrientation = viewModel::openOrientationModeSelectDialog, cropEnabled = cropEnabled, onClickCropBorder = { val enabled = viewModel.toggleCropBorders() @@ -425,7 +425,7 @@ class ReaderActivity : BaseActivity() { ) } is ReaderViewModel.Dialog.OrientationModeSelect -> { - OrientationModeSelectDialog( + OrientationSelectDialog( onDismissRequest = onDismissRequest, screenModel = settingsScreenModel, onChange = { stringRes -> @@ -482,15 +482,15 @@ class ReaderActivity : BaseActivity() { */ private fun setManga(manga: Manga) { val prevViewer = viewModel.state.value.viewer - val newViewer = ReadingModeType.toViewer(viewModel.getMangaReadingMode(), this) + val newViewer = ReadingMode.toViewer(viewModel.getMangaReadingMode(), this) if (window.sharedElementEnterTransition is MaterialContainerTransform) { // Wait until transition is complete to avoid crash on API 26 window.sharedElementEnterTransition.doOnEnd { - setOrientation(viewModel.getMangaOrientationType()) + setOrientation(viewModel.getMangaOrientation()) } } else { - setOrientation(viewModel.getMangaOrientationType()) + setOrientation(viewModel.getMangaOrientation()) } // Destroy previous viewer if there was one @@ -543,7 +543,7 @@ class ReaderActivity : BaseActivity() { private fun showReadingModeToast(mode: Int) { try { readingModeToast?.cancel() - readingModeToast = toast(ReadingModeType.fromPreference(mode).stringRes) + readingModeToast = toast(ReadingMode.fromPreference(mode).stringRes) } catch (e: ArrayIndexOutOfBoundsException) { logcat(LogPriority.ERROR) { "Unknown reading mode: $mode" } } @@ -721,7 +721,7 @@ class ReaderActivity : BaseActivity() { * Forces the user preferred [orientation] on the activity. */ private fun setOrientation(orientation: Int) { - val newOrientation = OrientationType.fromPreference(orientation) + val newOrientation = ReaderOrientation.fromPreference(orientation) if (newOrientation.flag != requestedOrientation) { requestedOrientation = newOrientation.flag } 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 0fae11b49..6718f6935 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 @@ -10,8 +10,8 @@ import androidx.lifecycle.viewModelScope import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.SetMangaViewerFlags -import eu.kanade.domain.manga.model.orientationType -import eu.kanade.domain.manga.model.readingModeType +import eu.kanade.domain.manga.model.readerOrientation +import eu.kanade.domain.manga.model.readingMode import eu.kanade.domain.track.interactor.TrackChapter import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.tachiyomi.data.database.models.toDomainChapter @@ -29,9 +29,9 @@ import eu.kanade.tachiyomi.ui.reader.model.InsertPage import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters -import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences -import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import eu.kanade.tachiyomi.ui.reader.viewer.Viewer import eu.kanade.tachiyomi.util.chapter.filterDownloaded import eu.kanade.tachiyomi.util.chapter.removeDuplicates @@ -630,20 +630,20 @@ class ReaderViewModel @JvmOverloads constructor( */ fun getMangaReadingMode(resolveDefault: Boolean = true): Int { val default = readerPreferences.defaultReadingMode().get() - val readingMode = ReadingModeType.fromPreference(manga?.readingModeType?.toInt()) + val readingMode = ReadingMode.fromPreference(manga?.readingMode?.toInt()) return when { - resolveDefault && readingMode == ReadingModeType.DEFAULT -> default - else -> manga?.readingModeType?.toInt() ?: default + resolveDefault && readingMode == ReadingMode.DEFAULT -> default + else -> manga?.readingMode?.toInt() ?: default } } /** * Updates the viewer position for the open manga. */ - fun setMangaReadingMode(readingModeType: ReadingModeType) { + fun setMangaReadingMode(readingMode: ReadingMode) { val manga = manga ?: return runBlocking(Dispatchers.IO) { - setMangaViewerFlags.awaitSetReadingMode(manga.id, readingModeType.flagValue.toLong()) + setMangaViewerFlags.awaitSetReadingMode(manga.id, readingMode.flagValue.toLong()) val currChapters = state.value.viewerChapters if (currChapters != null) { // Save current page @@ -664,22 +664,22 @@ class ReaderViewModel @JvmOverloads constructor( /** * Returns the orientation type used by this manga or the default one. */ - fun getMangaOrientationType(resolveDefault: Boolean = true): Int { + fun getMangaOrientation(resolveDefault: Boolean = true): Int { val default = readerPreferences.defaultOrientationType().get() - val orientation = OrientationType.fromPreference(manga?.orientationType?.toInt()) + val orientation = ReaderOrientation.fromPreference(manga?.readerOrientation?.toInt()) return when { - resolveDefault && orientation == OrientationType.DEFAULT -> default - else -> manga?.orientationType?.toInt() ?: default + resolveDefault && orientation == ReaderOrientation.DEFAULT -> default + else -> manga?.readerOrientation?.toInt() ?: default } } /** * Updates the orientation type for the open manga. */ - fun setMangaOrientationType(rotationType: OrientationType) { + fun setMangaOrientationType(orientation: ReaderOrientation) { val manga = manga ?: return viewModelScope.launchIO { - setMangaViewerFlags.awaitSetOrientation(manga.id, rotationType.flagValue.toLong()) + setMangaViewerFlags.awaitSetOrientation(manga.id, orientation.flagValue.toLong()) val currChapters = state.value.viewerChapters if (currChapters != null) { // Save current page @@ -692,14 +692,14 @@ class ReaderViewModel @JvmOverloads constructor( viewerChapters = currChapters, ) } - eventChannel.send(Event.SetOrientation(getMangaOrientationType())) + eventChannel.send(Event.SetOrientation(getMangaOrientation())) eventChannel.send(Event.ReloadViewerChapters) } } } fun toggleCropBorders(): Boolean { - val isPagerType = ReadingModeType.isPagerType(getMangaReadingMode()) + val isPagerType = ReadingMode.isPagerType(getMangaReadingMode()) return if (isPagerType) { readerPreferences.cropBorders().toggle() } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderOrientation.kt similarity index 91% rename from app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderOrientation.kt index c2edb39e9..c1d2e9b2d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/OrientationType.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderOrientation.kt @@ -5,7 +5,7 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import eu.kanade.tachiyomi.R -enum class OrientationType( +enum class ReaderOrientation( val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, @@ -58,6 +58,6 @@ enum class OrientationType( companion object { const val MASK = 0x00000038 - fun fromPreference(preference: Int?): OrientationType = entries.find { it.flagValue == preference } ?: DEFAULT + fun fromPreference(preference: Int?): ReaderOrientation = entries.find { it.flagValue == preference } ?: DEFAULT } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt index 5b2314916..9389a89e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt @@ -32,12 +32,12 @@ class ReaderPreferences( fun defaultReadingMode() = preferenceStore.getInt( "pref_default_reading_mode_key", - ReadingModeType.RIGHT_TO_LEFT.flagValue, + ReadingMode.RIGHT_TO_LEFT.flagValue, ) fun defaultOrientationType() = preferenceStore.getInt( "pref_default_orientation_type_key", - OrientationType.FREE.flagValue, + ReaderOrientation.FREE.flagValue, ) fun webtoonDoubleTapZoomEnabled() = preferenceStore.getBoolean("pref_enable_double_tap_zoom_webtoon", true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt index 5014ba204..5f107c388 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt @@ -14,8 +14,8 @@ import uy.kohesive.injekt.api.get class ReaderSettingsScreenModel( readerState: StateFlow, val hasDisplayCutout: Boolean, - val onChangeReadingMode: (ReadingModeType) -> Unit, - val onChangeOrientation: (OrientationType) -> Unit, + val onChangeReadingMode: (ReadingMode) -> Unit, + val onChangeOrientation: (ReaderOrientation) -> Unit, val preferences: ReaderPreferences = Injekt.get(), ) : ScreenModel { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingMode.kt similarity index 50% rename from app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingMode.kt index 4d5974ee5..d042795eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingMode.kt @@ -10,27 +10,59 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer -enum class ReadingModeType( +enum class ReadingMode( @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int, + val direction: Direction? = null, + val type: ViewerType? = null, ) { DEFAULT(R.string.label_default, R.drawable.ic_reader_default_24dp, 0x00000000), - LEFT_TO_RIGHT(R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp, 0x00000001), - RIGHT_TO_LEFT(R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp, 0x00000002), - VERTICAL(R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp, 0x00000003), - WEBTOON(R.string.webtoon_viewer, R.drawable.ic_reader_webtoon_24dp, 0x00000004), - CONTINUOUS_VERTICAL(R.string.vertical_plus_viewer, R.drawable.ic_reader_continuous_vertical_24dp, 0x00000005), + LEFT_TO_RIGHT( + R.string.left_to_right_viewer, + R.drawable.ic_reader_ltr_24dp, + 0x00000001, + Direction.Horizontal, + ViewerType.Pager, + ), + RIGHT_TO_LEFT( + R.string.right_to_left_viewer, + R.drawable.ic_reader_rtl_24dp, + 0x00000002, + Direction.Horizontal, + ViewerType.Pager, + ), + VERTICAL( + R.string.vertical_viewer, + R.drawable.ic_reader_vertical_24dp, + 0x00000003, + Direction.Vertical, + ViewerType.Pager, + ), + WEBTOON( + R.string.webtoon_viewer, + R.drawable.ic_reader_webtoon_24dp, + 0x00000004, + Direction.Vertical, + ViewerType.Webtoon, + ), + CONTINUOUS_VERTICAL( + R.string.vertical_plus_viewer, + R.drawable.ic_reader_continuous_vertical_24dp, + 0x00000005, + Direction.Vertical, + ViewerType.Webtoon, + ), ; companion object { const val MASK = 0x00000007 - fun fromPreference(preference: Int?): ReadingModeType = entries.find { it.flagValue == preference } ?: DEFAULT + fun fromPreference(preference: Int?): ReadingMode = entries.find { it.flagValue == preference } ?: DEFAULT fun isPagerType(preference: Int): Boolean { val mode = fromPreference(preference) - return mode == LEFT_TO_RIGHT || mode == RIGHT_TO_LEFT || mode == VERTICAL + return mode.type is ViewerType.Pager } fun toViewer(preference: Int?, activity: ReaderActivity): Viewer { @@ -44,4 +76,14 @@ enum class ReadingModeType( } } } + + sealed interface Direction { + data object Horizontal : Direction + data object Vertical : Direction + } + + sealed interface ViewerType { + data object Pager : ViewerType + data object Webtoon : ViewerType + } }