|
@@ -31,7 +31,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
|
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
|
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
-import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
|
|
import eu.kanade.tachiyomi.data.preference.toggle
|
|
|
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
|
|
|
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
|
|
@@ -63,7 +62,6 @@ import eu.kanade.tachiyomi.util.view.setTooltip
|
|
|
import eu.kanade.tachiyomi.util.view.showBar
|
|
|
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
|
|
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
|
|
-import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.flow.drop
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
@@ -358,12 +356,12 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
|
|
|
setOnClickListener {
|
|
|
popupMenu(
|
|
|
- items = ReadingModeType.values().map { it.prefValue to it.stringRes },
|
|
|
- selectedItemId = presenter.getMangaViewer(resolveDefault = false),
|
|
|
+ items = ReadingModeType.values().map { it.flagValue to it.stringRes },
|
|
|
+ selectedItemId = presenter.getMangaReadingMode(resolveDefault = false),
|
|
|
) {
|
|
|
val newReadingMode = ReadingModeType.fromPreference(itemId)
|
|
|
|
|
|
- presenter.setMangaViewer(newReadingMode.prefValue)
|
|
|
+ presenter.setMangaReadingMode(newReadingMode.flagValue)
|
|
|
|
|
|
menuToggleToast?.cancel()
|
|
|
if (!preferences.showReadingMode()) {
|
|
@@ -379,28 +377,28 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
|
|
|
setOnClickListener {
|
|
|
popupMenu(
|
|
|
- items = OrientationType.values().map { it.prefValue to it.stringRes },
|
|
|
- selectedItemId = preferences.rotation().get(),
|
|
|
+ items = OrientationType.values().map { it.flagValue to it.stringRes },
|
|
|
+ selectedItemId = presenter.manga?.orientationType
|
|
|
+ ?: preferences.defaultOrientationType(),
|
|
|
) {
|
|
|
val newOrientation = OrientationType.fromPreference(itemId)
|
|
|
|
|
|
- preferences.rotation().set(newOrientation.prefValue)
|
|
|
- setOrientation(newOrientation.flag)
|
|
|
+ presenter.setMangaOrientationType(newOrientation.flagValue)
|
|
|
+
|
|
|
+ updateOrientationShortcut(newOrientation.flagValue)
|
|
|
|
|
|
menuToggleToast?.cancel()
|
|
|
menuToggleToast = toast(newOrientation.stringRes)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- preferences.rotation().asImmediateFlow { updateRotationShortcut(it) }
|
|
|
- .launchIn(lifecycleScope)
|
|
|
|
|
|
// Crop borders
|
|
|
with(binding.actionCropBorders) {
|
|
|
setTooltip(R.string.pref_crop_borders)
|
|
|
|
|
|
setOnClickListener {
|
|
|
- val isPagerType = ReadingModeType.isPagerType(presenter.getMangaViewer())
|
|
|
+ val isPagerType = ReadingModeType.isPagerType(presenter.getMangaReadingMode())
|
|
|
if (isPagerType) {
|
|
|
preferences.cropBorders().toggle()
|
|
|
} else {
|
|
@@ -431,13 +429,13 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun updateRotationShortcut(preference: Int) {
|
|
|
+ private fun updateOrientationShortcut(preference: Int) {
|
|
|
val orientation = OrientationType.fromPreference(preference)
|
|
|
binding.actionRotation.setImageResource(orientation.iconRes)
|
|
|
}
|
|
|
|
|
|
private fun updateCropBordersShortcut() {
|
|
|
- val isPagerType = ReadingModeType.isPagerType(presenter.getMangaViewer())
|
|
|
+ val isPagerType = ReadingModeType.isPagerType(presenter.getMangaReadingMode())
|
|
|
val enabled = if (isPagerType) {
|
|
|
preferences.cropBorders().get()
|
|
|
} else {
|
|
@@ -529,10 +527,10 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
fun setManga(manga: Manga) {
|
|
|
val prevViewer = viewer
|
|
|
|
|
|
- val viewerMode = ReadingModeType.fromPreference(presenter.getMangaViewer(resolveDefault = false))
|
|
|
+ val viewerMode = ReadingModeType.fromPreference(presenter.getMangaReadingMode(resolveDefault = false))
|
|
|
binding.actionReadingMode.setImageResource(viewerMode.iconRes)
|
|
|
|
|
|
- val newViewer = when (presenter.getMangaViewer()) {
|
|
|
+ val newViewer = when (presenter.getMangaReadingMode()) {
|
|
|
ReadingModeType.LEFT_TO_RIGHT.prefValue -> L2RPagerViewer(this)
|
|
|
ReadingModeType.VERTICAL.prefValue -> VerticalPagerViewer(this)
|
|
|
ReadingModeType.WEBTOON.prefValue -> WebtoonViewer(this)
|
|
@@ -540,6 +538,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
else -> R2LPagerViewer(this)
|
|
|
}
|
|
|
|
|
|
+ setOrientation(presenter.getMangaOrientationType())
|
|
|
+
|
|
|
// Destroy previous viewer if there was one
|
|
|
if (prevViewer != null) {
|
|
|
prevViewer.destroy()
|
|
@@ -549,7 +549,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
binding.viewerContainer.addView(newViewer.getView())
|
|
|
|
|
|
if (preferences.showReadingMode()) {
|
|
|
- showReadingModeToast(presenter.getMangaViewer())
|
|
|
+ showReadingModeToast(presenter.getMangaReadingMode())
|
|
|
}
|
|
|
|
|
|
binding.toolbar.title = manga.title
|
|
@@ -777,7 +777,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
/**
|
|
|
* Forces the user preferred [orientation] on the activity.
|
|
|
*/
|
|
|
- private fun setOrientation(orientation: Int) {
|
|
|
+ fun setOrientation(orientation: Int) {
|
|
|
val newOrientation = OrientationType.fromPreference(orientation)
|
|
|
if (newOrientation.flag != requestedOrientation) {
|
|
|
requestedOrientation = newOrientation.flag
|
|
@@ -793,14 +793,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
* Initializes the reader subscriptions.
|
|
|
*/
|
|
|
init {
|
|
|
- preferences.rotation().asImmediateFlow { setOrientation(it) }
|
|
|
- .drop(1)
|
|
|
- .onEach {
|
|
|
- delay(250)
|
|
|
- setOrientation(it)
|
|
|
- }
|
|
|
- .launchIn(lifecycleScope)
|
|
|
-
|
|
|
preferences.readerTheme().asFlow()
|
|
|
.drop(1) // We only care about updates
|
|
|
.onEach { recreate() }
|