From a44d2da989857212b8058400df24a479773be954 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 25 Mar 2020 22:31:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/widget/prefs/Preference.kt | 30 +++++++++++++++---- .../app/ui/widget/prefs/PreferenceCategory.kt | 5 ++++ .../res/layout/view_preference_category.xml | 4 +-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt index 0190dcd9f..5e87ed3dd 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.widget.prefs import android.content.Context +import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.LayoutInflater @@ -11,11 +12,15 @@ import android.widget.TextView import androidx.core.view.isVisible import androidx.preference.PreferenceViewHolder import io.legado.app.R +import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.accentColor +import io.legado.app.lib.theme.backgroundColor +import io.legado.app.utils.getCompatColor import org.jetbrains.anko.layoutInflater import kotlin.math.roundToInt -class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Preference(context, attrs) { +class Preference(context: Context, attrs: AttributeSet) : + androidx.preference.Preference(context, attrs) { init { // isPersistent = true @@ -24,9 +29,22 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr companion object { - fun bindView(context: Context, it: PreferenceViewHolder?, icon: Drawable?, title: CharSequence?, summary: CharSequence?, weightLayoutRes: Int?, viewId: Int?, - weightWidth: Int = 0, weightHeight: Int = 0): T? { + fun bindView( + context: Context, + it: PreferenceViewHolder?, + icon: Drawable?, + title: CharSequence?, + summary: CharSequence?, + weightLayoutRes: Int?, + viewId: Int?, + weightWidth: Int = 0, + weightHeight: Int = 0 + ): T? { if (it == null) return null + it.itemView.background = Selector.drawableBuild() + .setDefaultDrawable(ColorDrawable(context.backgroundColor)) + .setPressedDrawable(ColorDrawable(context.getCompatColor(R.color.btn_bg_press))) + .create() val view = it.findViewById(R.id.preference_title) if (view is TextView) { view.text = title @@ -62,9 +80,11 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr if (weightWidth > 0 || weightHeight > 0) { val lp = lay.layoutParams if (weightHeight > 0) - lp.height = (context.resources.displayMetrics.density * weightHeight).roundToInt() + lp.height = + (context.resources.displayMetrics.density * weightHeight).roundToInt() if (weightWidth > 0) - lp.width = (context.resources.displayMetrics.density * weightWidth).roundToInt() + lp.width = + (context.resources.displayMetrics.density * weightWidth).roundToInt() lay.layoutParams = lp } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt index 494eff35a..9b1436ba8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt @@ -8,7 +8,9 @@ import androidx.core.view.isVisible import androidx.preference.PreferenceCategory import androidx.preference.PreferenceViewHolder import io.legado.app.R +import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.accentColor +import io.legado.app.lib.theme.backgroundColor import io.legado.app.utils.getCompatColor @@ -28,16 +30,19 @@ class PreferenceCategory(context: Context, attrs: AttributeSet) : PreferenceCate if (view.isInEditMode) { view.setTextColor(context.getCompatColor(R.color.colorAccent)) } else { + view.setBackgroundColor(context.backgroundColor) view.setTextColor(context.accentColor) } view.isVisible = title != null && title.isNotEmpty() val da = it.findViewById(R.id.preference_divider_above) if (da is View) { + da.setBackgroundColor(ColorUtils.darkenColor(context.backgroundColor)) da.isVisible = it.isDividerAllowedAbove } val db = it.findViewById(R.id.preference_divider_below) if (db is View) { + db.setBackgroundColor(ColorUtils.darkenColor(context.backgroundColor)) db.isVisible = it.isDividerAllowedBelow } } diff --git a/app/src/main/res/layout/view_preference_category.xml b/app/src/main/res/layout/view_preference_category.xml index 087a43e76..72cf9b5ca 100644 --- a/app/src/main/res/layout/view_preference_category.xml +++ b/app/src/main/res/layout/view_preference_category.xml @@ -13,8 +13,8 @@