From 2c850d0e33e82b9dd6b155ec9e8bf2eb1c716496 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 20 Nov 2022 15:12:51 -0500 Subject: [PATCH] Fix invert tapping dropdown not updating checked state in reader Fixes #8566 Should ideally just Compose-ify it all some day. --- .../ui/reader/setting/ReaderReadingModeSettings.kt | 5 +++-- .../kanade/tachiyomi/widget/MaterialSpinnerView.kt | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt index 8c583aba73..474b876d61 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt @@ -7,6 +7,7 @@ import androidx.core.view.isVisible import androidx.core.widget.NestedScrollView import androidx.lifecycle.lifecycleScope import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer @@ -68,7 +69,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr binding.webtoonPrefsGroup.root.isVisible = false binding.pagerPrefsGroup.root.isVisible = true - binding.pagerPrefsGroup.tappingInverted.bindToPreference(readerPreferences.pagerNavInverted()) + binding.pagerPrefsGroup.tappingInverted.bindToPreference(readerPreferences.pagerNavInverted(), PreferenceValues.TappingInvertMode::class.java) binding.pagerPrefsGroup.navigatePan.bindToPreference(readerPreferences.navigateToPan()) binding.pagerPrefsGroup.pagerNav.bindToPreference(readerPreferences.navigationModePager()) @@ -104,7 +105,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr binding.pagerPrefsGroup.root.isVisible = false binding.webtoonPrefsGroup.root.isVisible = true - binding.webtoonPrefsGroup.tappingInverted.bindToPreference(readerPreferences.webtoonNavInverted()) + binding.webtoonPrefsGroup.tappingInverted.bindToPreference(readerPreferences.webtoonNavInverted(), PreferenceValues.TappingInvertMode::class.java) binding.webtoonPrefsGroup.webtoonNav.bindToPreference(readerPreferences.navigationModeWebtoon()) readerPreferences.navigationModeWebtoon() diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt index 7d0ac529ca..9bfe337f13 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt @@ -89,14 +89,14 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att } } - inline fun > bindToPreference(pref: Preference) { - val enumConstants = T::class.java.enumConstants + fun > bindToPreference(pref: Preference, clazz: Class) { + val enumConstants = clazz.enumConstants enumConstants?.indexOf(pref.get())?.let { setSelection(it) } - val popup = makeSettingsPopup(pref) - setOnTouchListener(popup.dragToOpenListener) + popup = makeSettingsPopup(pref, clazz) + setOnTouchListener(popup?.dragToOpenListener) setOnClickListener { - popup.show() + popup?.show() } } @@ -111,11 +111,11 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att } } - inline fun > makeSettingsPopup(preference: Preference): PopupMenu { + private fun > makeSettingsPopup(preference: Preference, clazz: Class): PopupMenu { return createPopupMenu { pos -> onItemSelectedListener?.invoke(pos) - val enumConstants = T::class.java.enumConstants + val enumConstants = clazz.enumConstants enumConstants?.get(pos)?.let { enumValue -> preference.set(enumValue) } } }