Fix invert tapping dropdown not updating checked state in reader

Fixes #8566
Should ideally just Compose-ify it all some day.
This commit is contained in:
arkon 2022-11-20 15:12:51 -05:00
parent f1b85ff39d
commit 2c850d0e33
2 changed files with 10 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer 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.webtoonPrefsGroup.root.isVisible = false
binding.pagerPrefsGroup.root.isVisible = true 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.navigatePan.bindToPreference(readerPreferences.navigateToPan())
binding.pagerPrefsGroup.pagerNav.bindToPreference(readerPreferences.navigationModePager()) binding.pagerPrefsGroup.pagerNav.bindToPreference(readerPreferences.navigationModePager())
@ -104,7 +105,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr
binding.pagerPrefsGroup.root.isVisible = false binding.pagerPrefsGroup.root.isVisible = false
binding.webtoonPrefsGroup.root.isVisible = true 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()) binding.webtoonPrefsGroup.webtoonNav.bindToPreference(readerPreferences.navigationModeWebtoon())
readerPreferences.navigationModeWebtoon() readerPreferences.navigationModeWebtoon()

View File

@ -89,14 +89,14 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
} }
} }
inline fun <reified T : Enum<T>> bindToPreference(pref: Preference<T>) { fun <T : Enum<T>> bindToPreference(pref: Preference<T>, clazz: Class<T>) {
val enumConstants = T::class.java.enumConstants val enumConstants = clazz.enumConstants
enumConstants?.indexOf(pref.get())?.let { setSelection(it) } enumConstants?.indexOf(pref.get())?.let { setSelection(it) }
val popup = makeSettingsPopup(pref) popup = makeSettingsPopup(pref, clazz)
setOnTouchListener(popup.dragToOpenListener) setOnTouchListener(popup?.dragToOpenListener)
setOnClickListener { setOnClickListener {
popup.show() popup?.show()
} }
} }
@ -111,11 +111,11 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
} }
} }
inline fun <reified T : Enum<T>> makeSettingsPopup(preference: Preference<T>): PopupMenu { private fun <T : Enum<T>> makeSettingsPopup(preference: Preference<T>, clazz: Class<T>): PopupMenu {
return createPopupMenu { pos -> return createPopupMenu { pos ->
onItemSelectedListener?.invoke(pos) onItemSelectedListener?.invoke(pos)
val enumConstants = T::class.java.enumConstants val enumConstants = clazz.enumConstants
enumConstants?.get(pos)?.let { enumValue -> preference.set(enumValue) } enumConstants?.get(pos)?.let { enumValue -> preference.set(enumValue) }
} }
} }