From c4b975b77734c8cea843796bae87ee6e236180f4 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 27 Mar 2021 17:59:52 -0400 Subject: [PATCH] Cleanup reader spinner layouts --- .../reader/setting/ReaderGeneralSettings.kt | 1 - .../setting/ReaderReadingModeSettings.kt | 1 - .../ui/reader/setting/SpinnerPreference.kt | 23 +++-------- .../util/preference/PreferenceExtensions.kt | 39 ------------------- .../main/res/layout/navigation_view_group.xml | 3 +- .../res/layout/reader_general_settings.xml | 18 +++++++-- .../main/res/layout/reader_pager_settings.xml | 19 ++++----- .../layout/reader_reading_mode_settings.xml | 13 ++----- .../res/layout/reader_webtoon_settings.xml | 19 ++++----- .../main/res/layout/spinner_preference.xml | 12 +++--- 10 files changed, 53 insertions(+), 95 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt index 2ed793d58..152ce33c7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt @@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.ReaderGeneralSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import eu.kanade.tachiyomi.util.preference.bindToIntPreference import eu.kanade.tachiyomi.util.preference.bindToPreference import uy.kohesive.injekt.injectLazy 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 eebb46157..b309794b1 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 @@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer -import eu.kanade.tachiyomi.util.preference.bindToIntPreference import eu.kanade.tachiyomi.util.preference.bindToPreference import kotlinx.coroutines.flow.launchIn import uy.kohesive.injekt.injectLazy diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/SpinnerPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/SpinnerPreference.kt index 53a1306e8..d30e6b5bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/SpinnerPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/SpinnerPreference.kt @@ -8,7 +8,6 @@ import android.view.MenuItem import android.widget.FrameLayout import androidx.annotation.ArrayRes import androidx.appcompat.widget.PopupMenu -import androidx.core.view.get import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.SpinnerPreferenceBinding @@ -53,12 +52,8 @@ class SpinnerPreference @JvmOverloads constructor(context: Context, attrs: Attri } fun setSelection(selection: Int) { - popup?.menu?.get(selectedPosition)?.isCheckable = false - popup?.menu?.get(selectedPosition)?.isChecked = false selectedPosition = selection binding.details.text = entries.getOrNull(selection).orEmpty() - popup?.menu?.get(selectedPosition)?.isCheckable = true - popup?.menu?.get(selectedPosition)?.isChecked = true } fun bindToPreference(pref: Preference, offset: Int = 0, block: ((Int) -> Unit)? = null) { @@ -99,14 +94,14 @@ class SpinnerPreference @JvmOverloads constructor(context: Context, attrs: Attri // Set a listener so we are notified if a menu item is clicked popup.setOnMenuItemClickListener { menuItem -> - val pos = popup.menuClicked(menuItem) + val pos = menuClicked(menuItem) onItemSelectedListener?.invoke(pos) true } // 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) + val pos = menuClicked(menuItem) enumConstants?.get(pos)?.let { preference.set(it) } true } @@ -117,7 +112,7 @@ class SpinnerPreference @JvmOverloads constructor(context: Context, attrs: Attri val popup = popup() // Set a listener so we are notified if a menu item is clicked popup.setOnMenuItemClickListener { menuItem -> - val pos = popup.menuClicked(menuItem) + val pos = menuClicked(menuItem) preference.set(intValues[pos] ?: 0) block?.invoke(pos) true @@ -129,7 +124,7 @@ class SpinnerPreference @JvmOverloads constructor(context: Context, attrs: Attri val popup = popup() // Set a listener so we are notified if a menu item is clicked popup.setOnMenuItemClickListener { menuItem -> - val pos = popup.menuClicked(menuItem) + val pos = menuClicked(menuItem) preference.set(pos + offset) block?.invoke(pos) true @@ -142,20 +137,16 @@ class SpinnerPreference @JvmOverloads constructor(context: Context, attrs: Attri // Set a listener so we are notified if a menu item is clicked popup.setOnMenuItemClickListener { menuItem -> - val pos = popup.menuClicked(menuItem) + val pos = menuClicked(menuItem) onItemSelectedListener?.invoke(pos) true } return popup } - fun PopupMenu.menuClicked(menuItem: MenuItem): Int { + fun menuClicked(menuItem: MenuItem): Int { val pos = menuItem.itemId - menu[selectedPosition].isCheckable = false - menu[selectedPosition].isChecked = false setSelection(pos) - menu[pos].isCheckable = true - menu[pos].isChecked = true return pos } @@ -164,8 +155,6 @@ class SpinnerPreference @JvmOverloads constructor(context: Context, attrs: Attri entries.forEachIndexed { index, entry -> popup.menu.add(0, index, 0, entry) } - popup.menu[selectedPosition].isCheckable = true - popup.menu[selectedPosition].isChecked = true return popup } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt index abc592f3c..d96d8ea3f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt @@ -1,10 +1,7 @@ package eu.kanade.tachiyomi.util.preference import android.widget.CompoundButton -import android.widget.Spinner -import androidx.annotation.ArrayRes import com.tfcporciuncula.flow.Preference -import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener /** * Binds a checkbox or switch view with a boolean preference. @@ -13,39 +10,3 @@ fun CompoundButton.bindToPreference(pref: Preference) { isChecked = pref.get() setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) } } - -/** - * Binds a spinner to an int preference with an optional offset for the value. - */ -fun Spinner.bindToPreference(pref: Preference, offset: Int = 0) { - onItemSelectedListener = IgnoreFirstSpinnerListener { position -> - pref.set(position + offset) - } - setSelection(pref.get() - offset, false) -} - -/** - * Binds a spinner to an enum preference. - */ -inline fun > Spinner.bindToPreference(pref: Preference) { - val enumConstants = T::class.java.enumConstants - - onItemSelectedListener = IgnoreFirstSpinnerListener { position -> - enumConstants?.get(position)?.let { pref.set(it) } - } - - enumConstants?.indexOf(pref.get())?.let { setSelection(it, false) } -} - -/** - * Binds a spinner to an int preference. The position of the spinner item must - * correlate with the [intValues] resource item (in arrays.xml), which is a - * of int values that will be parsed here and applied to the preference. - */ -fun Spinner.bindToIntPreference(pref: Preference, @ArrayRes intValuesResource: Int) { - val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() } - onItemSelectedListener = IgnoreFirstSpinnerListener { position -> - pref.set(intValues[position]!!) - } - setSelection(intValues.indexOf(pref.get()), false) -} diff --git a/app/src/main/res/layout/navigation_view_group.xml b/app/src/main/res/layout/navigation_view_group.xml index b3af126f9..e98107edd 100644 --- a/app/src/main/res/layout/navigation_view_group.xml +++ b/app/src/main/res/layout/navigation_view_group.xml @@ -1,5 +1,6 @@ + app:tint="?attr/colorOnPrimary" /> diff --git a/app/src/main/res/layout/reader_general_settings.xml b/app/src/main/res/layout/reader_general_settings.xml index daffe4d2b..a6a5a2633 100644 --- a/app/src/main/res/layout/reader_general_settings.xml +++ b/app/src/main/res/layout/reader_general_settings.xml @@ -3,9 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - android:clipToPadding="false" - android:padding="16dp"> + android:layout_height="match_parent"> @@ -50,24 +54,32 @@ android:id="@+id/keepscreen" android:layout_width="match_parent" android:layout_height="wrap_content" + android:paddingStart="16dp" + android:paddingEnd="16dp" android:text="@string/pref_keep_screen_on" /> diff --git a/app/src/main/res/layout/reader_pager_settings.xml b/app/src/main/res/layout/reader_pager_settings.xml index 15d7c5f79..b42d4b138 100644 --- a/app/src/main/res/layout/reader_pager_settings.xml +++ b/app/src/main/res/layout/reader_pager_settings.xml @@ -10,12 +10,10 @@ android:id="@+id/pager_prefs" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="24dp" android:text="@string/pager_viewer" - android:textColor="?attr/colorAccent" - android:textStyle="bold" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:textAppearance="@style/TextAppearance.Medium.SubHeading" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:text="@string/pref_crop_borders" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" /> + android:layout_height="match_parent"> @@ -26,9 +25,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/viewer" tools:visibility="visible" /> @@ -37,10 +33,7 @@ layout="@layout/reader_webtoon_settings" android:layout_width="match_parent" android:layout_height="wrap_content" - android:visibility="gone" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/viewer" /> + android:visibility="gone" /> diff --git a/app/src/main/res/layout/reader_webtoon_settings.xml b/app/src/main/res/layout/reader_webtoon_settings.xml index d331a37ec..acf3752d5 100644 --- a/app/src/main/res/layout/reader_webtoon_settings.xml +++ b/app/src/main/res/layout/reader_webtoon_settings.xml @@ -10,12 +10,10 @@ android:id="@+id/webtoon_prefs" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="24dp" android:text="@string/webtoon_viewer" - android:textColor="?attr/colorAccent" - android:textStyle="bold" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:textAppearance="@style/TextAppearance.Medium.SubHeading" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:text="@string/pref_dual_page_split" /> + android:layout_height="?attr/listPreferredItemHeightSmall" + android:background="?attr/selectableItemBackground" + android:paddingStart="16dp" + android:paddingEnd="16dp">