Fallback to default viewer properly (closes #5068)

This commit is contained in:
arkon 2021-05-22 17:41:53 -04:00
parent 107727eea9
commit 2a7ed1375a
3 changed files with 20 additions and 11 deletions

View File

@ -50,10 +50,7 @@ import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsSheet import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsSheet
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer 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
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.GLUtil
import eu.kanade.tachiyomi.util.system.hasDisplayCutout import eu.kanade.tachiyomi.util.system.hasDisplayCutout
@ -540,13 +537,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
val viewerMode = ReadingModeType.fromPreference(presenter.getMangaReadingMode(resolveDefault = false)) val viewerMode = ReadingModeType.fromPreference(presenter.getMangaReadingMode(resolveDefault = false))
binding.actionReadingMode.setImageResource(viewerMode.iconRes) binding.actionReadingMode.setImageResource(viewerMode.iconRes)
val newViewer = when (presenter.getMangaReadingMode()) { val newViewer = ReadingModeType.toViewer(presenter.getMangaReadingMode(), this)
ReadingModeType.LEFT_TO_RIGHT.prefValue -> L2RPagerViewer(this)
ReadingModeType.VERTICAL.prefValue -> VerticalPagerViewer(this)
ReadingModeType.WEBTOON.prefValue -> WebtoonViewer(this)
ReadingModeType.CONTINUOUS_VERTICAL.prefValue -> WebtoonViewer(this, isContinuous = false)
else -> R2LPagerViewer(this)
}
setOrientation(presenter.getMangaOrientationType()) setOrientation(presenter.getMangaOrientationType())

View File

@ -501,8 +501,9 @@ class ReaderPresenter(
*/ */
fun getMangaReadingMode(resolveDefault: Boolean = true): Int { fun getMangaReadingMode(resolveDefault: Boolean = true): Int {
val default = preferences.defaultReadingMode() val default = preferences.defaultReadingMode()
val readingMode = ReadingModeType.fromPreference(manga?.readingModeType)
return when { return when {
resolveDefault && manga?.readingModeType == ReadingModeType.DEFAULT.flagValue -> default resolveDefault && readingMode == ReadingModeType.DEFAULT -> default
else -> manga?.readingModeType ?: default else -> manga?.readingModeType ?: default
} }
} }

View File

@ -3,6 +3,12 @@ package eu.kanade.tachiyomi.ui.reader.setting
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
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(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) { enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) {
DEFAULT(0, R.string.default_viewer, R.drawable.ic_reader_default_24dp, 0x00000000), DEFAULT(0, R.string.default_viewer, R.drawable.ic_reader_default_24dp, 0x00000000),
@ -24,5 +30,16 @@ enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @D
} }
fun fromSpinner(position: Int?) = values().find { value -> value.prefValue == position } ?: DEFAULT fun fromSpinner(position: Int?) = values().find { value -> value.prefValue == position } ?: DEFAULT
fun toViewer(preference: Int?, activity: ReaderActivity): BaseViewer {
return when (fromPreference(preference)) {
LEFT_TO_RIGHT -> L2RPagerViewer(activity)
RIGHT_TO_LEFT -> R2LPagerViewer(activity)
VERTICAL -> VerticalPagerViewer(activity)
WEBTOON -> WebtoonViewer(activity)
CONTINUOUS_VERTICAL -> WebtoonViewer(activity, isContinuous = false)
DEFAULT -> throw IllegalStateException("Preference value must be resolved: $preference")
}
}
} }
} }