mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 06:09:19 +01:00
Move PageLayout to enum and new file
This commit is contained in:
parent
a99b9b7fcc
commit
1fba86886c
@ -12,9 +12,9 @@ import com.tfcporciuncula.flow.FlowSharedPreferences
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.track.TrackService
|
import eu.kanade.tachiyomi.data.track.TrackService
|
||||||
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
|
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.settings.PageLayout
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
|
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
|
|
||||||
import eu.kanade.tachiyomi.ui.recents.RecentMangaAdapter
|
import eu.kanade.tachiyomi.ui.recents.RecentMangaAdapter
|
||||||
import eu.kanade.tachiyomi.util.system.Themes
|
import eu.kanade.tachiyomi.util.system.Themes
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -173,7 +173,7 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun webtoonNavInverted() = flowPrefs.getEnum(Keys.webtoonNavInverted, ViewerNavigation.TappingInvertMode.NONE)
|
fun webtoonNavInverted() = flowPrefs.getEnum(Keys.webtoonNavInverted, ViewerNavigation.TappingInvertMode.NONE)
|
||||||
|
|
||||||
fun pageLayout() = flowPrefs.getInt(Keys.pageLayout, PageLayout.AUTOMATIC)
|
fun pageLayout() = flowPrefs.getInt(Keys.pageLayout, PageLayout.AUTOMATIC.value)
|
||||||
|
|
||||||
fun invertDoublePages() = flowPrefs.getBoolean(Keys.invertDoublePages, false)
|
fun invertDoublePages() = flowPrefs.getBoolean(Keys.invertDoublePages, false)
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
|||||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||||
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
|
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
|
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.settings.PageLayout
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
|
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
|
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet
|
import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet
|
||||||
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.L2RPagerViewer
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
|
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
|
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
|
||||||
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.pager.VerticalPagerViewer
|
||||||
@ -356,8 +356,8 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setBottomNavButtons(pageLayout: Int) {
|
fun setBottomNavButtons(pageLayout: Int) {
|
||||||
val isDoublePage = pageLayout == PageLayout.DOUBLE_PAGES ||
|
val isDoublePage = pageLayout == PageLayout.DOUBLE_PAGES.value ||
|
||||||
(pageLayout == PageLayout.AUTOMATIC && (viewer as? PagerViewer)?.config?.doublePages ?: false)
|
(pageLayout == PageLayout.AUTOMATIC.value && (viewer as? PagerViewer)?.config?.doublePages ?: false)
|
||||||
binding.chaptersSheet.doublePage.setImageDrawable(
|
binding.chaptersSheet.doublePage.setImageDrawable(
|
||||||
ContextCompat.getDrawable(
|
ContextCompat.getDrawable(
|
||||||
this,
|
this,
|
||||||
@ -574,7 +574,7 @@ class ReaderActivity :
|
|||||||
|
|
||||||
with(binding.chaptersSheet) {
|
with(binding.chaptersSheet) {
|
||||||
doublePage.setOnClickListener {
|
doublePage.setOnClickListener {
|
||||||
if (preferences.pageLayout().get() == PageLayout.AUTOMATIC) {
|
if (preferences.pageLayout().get() == PageLayout.AUTOMATIC.value) {
|
||||||
(viewer as? PagerViewer)?.config?.let { config ->
|
(viewer as? PagerViewer)?.config?.let { config ->
|
||||||
config.doublePages = !config.doublePages
|
config.doublePages = !config.doublePages
|
||||||
reloadChapters(config.doublePages, true)
|
reloadChapters(config.doublePages, true)
|
||||||
@ -893,7 +893,7 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newViewer is PagerViewer) {
|
if (newViewer is PagerViewer) {
|
||||||
if (preferences.pageLayout().get() == PageLayout.AUTOMATIC) {
|
if (preferences.pageLayout().get() == PageLayout.AUTOMATIC.value) {
|
||||||
setDoublePageMode(newViewer)
|
setDoublePageMode(newViewer)
|
||||||
}
|
}
|
||||||
lastShiftDoubleState?.let { newViewer.config.shiftDoublePage = it }
|
lastShiftDoubleState?.let { newViewer.config.shiftDoublePage = it }
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.reader.settings
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
|
||||||
|
enum class PageLayout(val value: Int, @StringRes val stringRes: Int, @StringRes private val _fullStringRes: Int? = null) {
|
||||||
|
SINGLE_PAGE(0, R.string.single_page),
|
||||||
|
DOUBLE_PAGES(1, R.string.double_pages),
|
||||||
|
AUTOMATIC(2, R.string.automatic, R.string.automatic_orientation),
|
||||||
|
;
|
||||||
|
|
||||||
|
@StringRes val fullStringRes = _fullStringRes ?: stringRes
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromPreference(preference: Int): PageLayout =
|
||||||
|
values().find { it.value == preference } ?: SINGLE_PAGE
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,6 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.databinding.ReaderPagedLayoutBinding
|
import eu.kanade.tachiyomi.databinding.ReaderPagedLayoutBinding
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
|
|
||||||
import eu.kanade.tachiyomi.util.bindToPreference
|
import eu.kanade.tachiyomi.util.bindToPreference
|
||||||
import eu.kanade.tachiyomi.util.lang.addBetaTag
|
import eu.kanade.tachiyomi.util.lang.addBetaTag
|
||||||
import eu.kanade.tachiyomi.widget.BaseReaderSettingsView
|
import eu.kanade.tachiyomi.widget.BaseReaderSettingsView
|
||||||
@ -96,6 +95,6 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
binding.extendPastCutout.isVisible = show && isFullFit && hasCutout
|
binding.extendPastCutout.isVisible = show && isFullFit && hasCutout
|
||||||
binding.invertDoublePages.isVisible = show && preferences.pageLayout().get() != PageLayout.SINGLE_PAGE
|
binding.invertDoublePages.isVisible = show && preferences.pageLayout().get() != PageLayout.SINGLE_PAGE.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
|||||||
|
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.settings.PageLayout
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.navigation.EdgeNavigation
|
import eu.kanade.tachiyomi.ui.reader.viewer.navigation.EdgeNavigation
|
||||||
@ -45,7 +46,7 @@ class PagerConfig(
|
|||||||
|
|
||||||
var shiftDoublePage = false
|
var shiftDoublePage = false
|
||||||
|
|
||||||
var doublePages = preferences.pageLayout().get() == PageLayout.DOUBLE_PAGES
|
var doublePages = preferences.pageLayout().get() == PageLayout.DOUBLE_PAGES.value
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@ -55,7 +56,7 @@ class PagerConfig(
|
|||||||
|
|
||||||
var invertDoublePages = false
|
var invertDoublePages = false
|
||||||
|
|
||||||
var autoDoublePages = preferences.pageLayout().get() == PageLayout.AUTOMATIC
|
var autoDoublePages = preferences.pageLayout().get() == PageLayout.AUTOMATIC.value
|
||||||
|
|
||||||
init {
|
init {
|
||||||
preferences.pageTransitions()
|
preferences.pageTransitions()
|
||||||
@ -101,18 +102,18 @@ class PagerConfig(
|
|||||||
.asFlow()
|
.asFlow()
|
||||||
.drop(1)
|
.drop(1)
|
||||||
.onEach {
|
.onEach {
|
||||||
autoDoublePages = it == PageLayout.AUTOMATIC
|
autoDoublePages = it == PageLayout.AUTOMATIC.value
|
||||||
if (!autoDoublePages) {
|
if (!autoDoublePages) {
|
||||||
doublePages = it == PageLayout.DOUBLE_PAGES
|
doublePages = it == PageLayout.DOUBLE_PAGES.value
|
||||||
}
|
}
|
||||||
reloadChapterListener?.invoke(doublePages)
|
reloadChapterListener?.invoke(doublePages)
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
preferences.pageLayout()
|
preferences.pageLayout()
|
||||||
.register({
|
.register({
|
||||||
autoDoublePages = it == PageLayout.AUTOMATIC
|
autoDoublePages = it == PageLayout.AUTOMATIC.value
|
||||||
if (!autoDoublePages) {
|
if (!autoDoublePages) {
|
||||||
doublePages = it == PageLayout.DOUBLE_PAGES
|
doublePages = it == PageLayout.DOUBLE_PAGES.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -182,9 +183,3 @@ class PagerConfig(
|
|||||||
const val CUTOUT_IGNORE = 2
|
const val CUTOUT_IGNORE = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object PageLayout {
|
|
||||||
const val SINGLE_PAGE = 0
|
|
||||||
const val DOUBLE_PAGES = 1
|
|
||||||
const val AUTOMATIC = 2
|
|
||||||
}
|
|
||||||
|
@ -7,8 +7,8 @@ import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
|||||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
|
import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton
|
||||||
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
|
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.settings.PageLayout
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
|
|
||||||
import eu.kanade.tachiyomi.util.lang.addBetaTag
|
import eu.kanade.tachiyomi.util.lang.addBetaTag
|
||||||
import eu.kanade.tachiyomi.util.system.isTablet
|
import eu.kanade.tachiyomi.util.system.isTablet
|
||||||
import eu.kanade.tachiyomi.util.view.activityBinding
|
import eu.kanade.tachiyomi.util.view.activityBinding
|
||||||
@ -249,22 +249,19 @@ class SettingsReaderController : SettingsController() {
|
|||||||
key = Keys.pageLayout
|
key = Keys.pageLayout
|
||||||
title = context.getString(R.string.page_layout).addBetaTag(context)
|
title = context.getString(R.string.page_layout).addBetaTag(context)
|
||||||
dialogTitleRes = R.string.page_layout
|
dialogTitleRes = R.string.page_layout
|
||||||
entriesRes = arrayOf(
|
val enumConstants = PageLayout.values()
|
||||||
R.string.single_page,
|
entriesRes = enumConstants.map { it.fullStringRes }.toTypedArray()
|
||||||
R.string.double_pages,
|
entryValues = enumConstants.map { it.value }
|
||||||
R.string.automatic_orientation
|
defaultValue = PageLayout.AUTOMATIC.value
|
||||||
)
|
|
||||||
entryRange = 0..2
|
|
||||||
defaultValue = 2
|
|
||||||
}
|
}
|
||||||
infoPreference(R.string.automatic_can_still_switch).apply {
|
infoPreference(R.string.automatic_can_still_switch).apply {
|
||||||
preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it == PageLayout.AUTOMATIC }
|
preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it == PageLayout.AUTOMATIC.value }
|
||||||
}
|
}
|
||||||
switchPreference {
|
switchPreference {
|
||||||
key = Keys.invertDoublePages
|
key = Keys.invertDoublePages
|
||||||
titleRes = R.string.invert_double_pages
|
titleRes = R.string.invert_double_pages
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it != PageLayout.SINGLE_PAGE }
|
preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it != PageLayout.SINGLE_PAGE.value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preferenceCategory {
|
preferenceCategory {
|
||||||
|
Loading…
Reference in New Issue
Block a user