From f4bb9b604a30d8301f8eb58f44b2525898bf3133 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 23 Jan 2020 20:50:55 -0500 Subject: [PATCH] Fix sources/extension filters toggles being indented --- .../tachiyomi/ui/extension/ExtensionFilterController.kt | 4 ++-- .../java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt | 5 +++++ .../kanade/tachiyomi/ui/setting/SettingsSourcesController.kt | 5 ++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt index 7c2be136f..8e955967a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt @@ -1,12 +1,12 @@ package eu.kanade.tachiyomi.ui.extension import androidx.preference.PreferenceScreen -import androidx.preference.SwitchPreference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.onChange +import eu.kanade.tachiyomi.ui.setting.switchPreference import eu.kanade.tachiyomi.ui.setting.titleRes import eu.kanade.tachiyomi.util.LocaleHelper import uy.kohesive.injekt.Injekt @@ -29,7 +29,7 @@ class ExtensionFilterController: SettingsController() { } availableLangs.forEach { - SwitchPreference(context).apply { + switchPreference { preferenceScreen.addPreference(this) title = LocaleHelper.getDisplayName(it, context) isPersistent = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index af694bd1f..143a4eb09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -4,6 +4,7 @@ import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import androidx.core.graphics.drawable.DrawableCompat import androidx.preference.* import eu.kanade.tachiyomi.widget.preference.IntListPreference +import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory @DslMarker @Target(AnnotationTarget.TYPE) @@ -21,6 +22,10 @@ inline fun PreferenceGroup.switchPreference(block: (@DSL SwitchPreferenceCompat) return initThenAdd(SwitchPreferenceCompat(context), block) } +inline fun PreferenceGroup.switchPreferenceCategory(block: (@DSL SwitchPreferenceCategory).() -> Unit): SwitchPreferenceCategory { + return initThenAdd(SwitchPreferenceCategory(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/ui/setting/SettingsSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt index a7ace7c56..6b4543da7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt @@ -11,10 +11,9 @@ import eu.kanade.tachiyomi.source.online.LoginSource import eu.kanade.tachiyomi.util.LocaleHelper import eu.kanade.tachiyomi.widget.preference.LoginCheckBoxPreference import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog -import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import java.util.* +import java.util.TreeMap class SettingsSourcesController : SettingsController(), SourceLoginDialog.Listener { @@ -38,7 +37,7 @@ class SettingsSourcesController : SettingsController(), val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name } // Create a preference group and set initial state and change listener - SwitchPreferenceCategory(context).apply { + switchPreferenceCategory { preferenceScreen.addPreference(this) title = LocaleHelper.getDisplayName(lang, context) isPersistent = false