From ca7373c28b68fb728691b01a0a3c3e9499486c04 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 6 Jun 2020 14:36:04 -0400 Subject: [PATCH] Make extension settings button inline --- .../extension/ExtensionDetailsController.kt | 19 ++++++------- .../util/preference/PreferenceDSL.kt | 5 ++++ .../preference/SwitchSettingsPreference.kt | 27 +++++++++++++++++++ app/src/main/res/layout/pref_settings.xml | 25 +++++++++++++++++ 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchSettingsPreference.kt create mode 100644 app/src/main/res/layout/pref_settings.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt index 177843df34..b50c5e8729 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt @@ -15,6 +15,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceGroupAdapter import androidx.preference.PreferenceManager import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration.VERTICAL import androidx.recyclerview.widget.LinearLayoutManager @@ -29,12 +30,11 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.util.preference.DSL import eu.kanade.tachiyomi.util.preference.onChange -import eu.kanade.tachiyomi.util.preference.onClick -import eu.kanade.tachiyomi.util.preference.preference import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference -import eu.kanade.tachiyomi.util.preference.titleRes +import eu.kanade.tachiyomi.util.preference.switchSettingsPreference import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.view.visible import kotlinx.coroutines.flow.launchIn @@ -129,8 +129,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : .forEach { source -> val sourcePrefs = mutableListOf() - // Source enable/disable - switchPreference { + val block: (@DSL SwitchPreferenceCompat).() -> Unit = { key = getSourceKey(source.id) title = if (isMultiSource) { source.toString() @@ -156,14 +155,16 @@ class ExtensionDetailsController(bundle: Bundle? = null) : .launchIn(scope) } - // Source preferences + // Source enable/disable if (source is ConfigurableSource) { - preference { - titleRes = R.string.label_settings - onClick { + switchSettingsPreference { + block() + onSettingsClick = View.OnClickListener { router.pushController(SourcePreferencesController(source.id).withFadeTransaction()) } } + } else { + switchPreference(block) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index c690dafa1d..3252b7f8f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory +import eu.kanade.tachiyomi.widget.preference.SwitchSettingsPreference @DslMarker @Target(AnnotationTarget.TYPE) @@ -51,6 +52,10 @@ inline fun PreferenceGroup.switchPreferenceCategory(block: (@DSL SwitchPreferenc return initThenAdd(SwitchPreferenceCategory(context), block) } +inline fun PreferenceGroup.switchSettingsPreference(block: (@DSL SwitchSettingsPreference).() -> Unit): SwitchSettingsPreference { + return initThenAdd(SwitchSettingsPreference(context), block) +} + inline fun PreferenceGroup.checkBoxPreference(block: (@DSL CheckBoxPreference).() -> Unit): CheckBoxPreference { return initThenAdd(CheckBoxPreference(context), block) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchSettingsPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchSettingsPreference.kt new file mode 100644 index 0000000000..f5e746af51 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchSettingsPreference.kt @@ -0,0 +1,27 @@ +package eu.kanade.tachiyomi.widget.preference + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import androidx.preference.PreferenceViewHolder +import androidx.preference.SwitchPreferenceCompat +import eu.kanade.tachiyomi.R +import kotlinx.android.synthetic.main.pref_settings.view.button + +class SwitchSettingsPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + SwitchPreferenceCompat(context, attrs) { + + var onSettingsClick: View.OnClickListener? = null + + init { + widgetLayoutResource = R.layout.pref_settings + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + + holder.itemView.button.setOnClickListener { + onSettingsClick?.onClick(it) + } + } +} diff --git a/app/src/main/res/layout/pref_settings.xml b/app/src/main/res/layout/pref_settings.xml new file mode 100644 index 0000000000..9d250e327f --- /dev/null +++ b/app/src/main/res/layout/pref_settings.xml @@ -0,0 +1,25 @@ + + + + + + + + +