diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderNavigationOverlayView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderNavigationOverlayView.kt index 4baeceaa18..26a41372f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderNavigationOverlayView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderNavigationOverlayView.kt @@ -22,7 +22,7 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet) var isLTR = true fun setNavigation(navigation: ViewerNavigation, showOnStart: Boolean) { - if (!showOnStart && (this.navigation == null || this.navigation === navigation) && !forceShowOverlay) { + if (!showOnStart && (this.navigation == null || this.navigation === navigation)) { if (this.navigation == null) { this.navigation = navigation isVisible = false @@ -30,8 +30,11 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet) return } - forceShowOverlay = false this.navigation = navigation + showNavigationAgain() + } + + fun showNavigationAgain() { invalidate() if (isVisible) return @@ -121,10 +124,6 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet) performClick() return super.onTouchEvent(event) } - - companion object { - var forceShowOverlay = false - } } private const val FADE_DURATION = 1000L diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt index fc2ed1ac85..aec16c0689 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt @@ -4,7 +4,6 @@ import android.content.Context import android.util.AttributeSet import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import eu.kanade.tachiyomi.ui.reader.ReaderNavigationOverlayView import eu.kanade.tachiyomi.util.bindToPreference import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.widget.BaseReaderSettingsView @@ -19,20 +18,16 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu crop_borders.bindToPreference(preferences.cropBorders()) page_transitions.bindToPreference(preferences.pageTransitions()) pager_nav.bindToPreference(preferences.navigationModePager()) - pager_invert.bindToPreference(preferences.pagerNavInverted()) { - ReaderNavigationOverlayView.forceShowOverlay = true - } + pager_invert.bindToPreference(preferences.pagerNavInverted()) - val mangaViewer = (context as ReaderActivity).presenter.getMangaViewer() + val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0 val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS val hasMargins = mangaViewer == ReaderActivity.VERTICAL_PLUS crop_borders_webtoon.bindToPreference(if (hasMargins) preferences.cropBorders() else preferences.cropBordersWebtoon()) webtoon_side_padding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values) webtoon_enable_zoom_out.bindToPreference(preferences.webtoonEnableZoomOut()) webtoon_nav.bindToPreference(preferences.navigationModeWebtoon()) - webtoon_invert.bindToPreference(preferences.webtoonNavInverted()) { - ReaderNavigationOverlayView.forceShowOverlay = true - } + webtoon_invert.bindToPreference(preferences.webtoonNavInverted()) updatePagedGroup(!isWebtoonView) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt index 0c602308af..499fe78165 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderSpinnerView.kt @@ -80,16 +80,6 @@ class ReaderSpinnerView @JvmOverloads constructor(context: Context, attrs: Attri } } - inline fun > bindToPreference(pref: Preference, crossinline block: ((Int) -> Unit)) { - val enumConstants = T::class.java.enumConstants - enumConstants?.indexOf(pref.get())?.let { setSelection(it) } - val popup = makeSettingsPopup(pref, block) - setOnTouchListener(popup.dragToOpenListener) - setOnClickListener { - popup.show() - } - } - fun bindToIntPreference(pref: Preference, @ArrayRes intValuesResource: Int, block: ((Int) -> Unit)? = null) { setSelection(pref.get()) this.pref = pref @@ -121,19 +111,6 @@ class ReaderSpinnerView @JvmOverloads constructor(context: Context, attrs: Attri return popup } - inline fun > makeSettingsPopup(preference: Preference, crossinline block: ((Int) -> Unit)): PopupMenu { - val popup = popup() - // Set a listener so we are notified if a menu item is clicked - popup.setOnMenuItemClickListener { menuItem -> - val enumConstants = T::class.java.enumConstants - val pos = popup.menuClicked(menuItem) - enumConstants?.get(pos)?.let { preference.set(it) } - block(pos) - true - } - return popup - } - private fun makeSettingsPopup(preference: Preference, intValues: List, block: ((Int) -> Unit)? = null): PopupMenu { val popup = popup() // Set a listener so we are notified if a menu item is clicked diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt index f52a3c5f7b..21c0a0ce91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt @@ -13,11 +13,12 @@ import kotlinx.coroutines.flow.onEach */ abstract class ViewerConfig(preferences: PreferencesHelper) { - private val scope = CoroutineScope(Job() + Dispatchers.Main) + protected val scope = CoroutineScope(Job() + Dispatchers.Main) var imagePropertyChangedListener: (() -> Unit)? = null var navigationModeChangedListener: (() -> Unit)? = null + var navigationModeInvertedListener: (() -> Unit)? = null var tappingEnabled = true var tappingInverted = ViewerNavigation.TappingInvertMode.NONE diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index 9a7d10cc9c..d7ad37c8da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -7,6 +7,9 @@ import eu.kanade.tachiyomi.ui.reader.viewer.navigation.EdgeNavigation import eu.kanade.tachiyomi.ui.reader.viewer.navigation.KindlishNavigation import eu.kanade.tachiyomi.ui.reader.viewer.navigation.LNavigation import eu.kanade.tachiyomi.ui.reader.viewer.navigation.RightAndLeftNavigation +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -44,9 +47,15 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe preferences.pagerNavInverted() .register({ tappingInverted = it }, { navigator.invertMode = it - navigationModeChangedListener?.invoke() }) + preferences.pagerNavInverted().asFlow() + .drop(1) + .onEach { + navigationModeInvertedListener?.invoke() + } + .launchIn(scope) + preferences.zoomStart() .register({ zoomTypeFromPreference(it) }, { imagePropertyChangedListener?.invoke() }) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index f73059db40..2c19dfe107 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -109,6 +109,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { val showOnStart = config.navigationOverlayForNewUser activity.navigation_overlay.setNavigation(config.navigator, showOnStart) } + config.navigationModeInvertedListener = { activity.navigation_overlay.showNavigationAgain() } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index 82de7c05a7..9050f89f61 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -7,6 +7,9 @@ import eu.kanade.tachiyomi.ui.reader.viewer.navigation.EdgeNavigation import eu.kanade.tachiyomi.ui.reader.viewer.navigation.KindlishNavigation import eu.kanade.tachiyomi.ui.reader.viewer.navigation.LNavigation import eu.kanade.tachiyomi.ui.reader.viewer.navigation.RightAndLeftNavigation +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -36,9 +39,15 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfi preferences.webtoonNavInverted() .register({ tappingInverted = it }, { navigator.invertMode = it - navigationModeChangedListener?.invoke() }) + preferences.webtoonNavInverted().asFlow() + .drop(1) + .onEach { + navigationModeInvertedListener?.invoke() + } + .launchIn(scope) + preferences.cropBordersWebtoon() .register({ webtoonCropBorders = it }, { imagePropertyChangedListener?.invoke() }) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 6844b60100..67272c70fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -128,6 +128,7 @@ class WebtoonViewer(val activity: ReaderActivity, val hasMargins: Boolean = fals val showOnStart = config.navigationOverlayForNewUser activity.navigation_overlay.setNavigation(config.navigator, showOnStart) } + config.navigationModeInvertedListener = { activity.navigation_overlay.showNavigationAgain() } frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) frame.addView(recycler)