From 6e97e11435c22e2c5e26d660d14dd2bda61275b0 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Fri, 20 Mar 2020 13:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=88=91=E7=9A=84UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/config/ThemeConfigFragment.kt | 7 +++++++ .../main/java/io/legado/app/ui/main/my/MyFragment.kt | 6 ------ .../java/io/legado/app/ui/widget/prefs/Preference.kt | 12 ++++++++++-- app/src/main/res/layout/view_preference.xml | 12 +++++++----- app/src/main/res/values/colors.xml | 2 +- app/src/main/res/xml/pref_config_read.xml | 2 +- app/src/main/res/xml/pref_config_theme.xml | 9 +++++++++ app/src/main/res/xml/pref_main.xml | 11 ----------- 8 files changed, 35 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index da2672841..7b163b3e6 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -19,6 +19,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ColorUtils import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.IconListPreference +import io.legado.app.ui.widget.prefs.NameListPreference import io.legado.app.utils.* @@ -33,6 +34,12 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar preferenceScreen.removePreference(it) } } + findPreference(PreferKey.themeMode)?.let { + it.setOnPreferenceChangeListener { _, _ -> + view?.post { App.INSTANCE.applyDayNight() } + true + } + } upPreferenceSummary("barElevation", AppConfig.elevation.toString()) } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index f3087f5e7..d948923e8 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -79,12 +79,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. observeEvent(EventBus.WEB_SERVICE_STOP) { webServicePre?.isChecked = false } - findPreference(PreferKey.themeMode)?.let { - it.setOnPreferenceChangeListener { _, _ -> - view?.post { App.INSTANCE.applyDayNight() } - true - } - } if (requireContext().channel == "google") { findPreference("aboutCategory") ?.removePreference(findPreference("donate")) 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..4bd3610b5 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 @@ -44,11 +44,17 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr iconView.setImageDrawable(icon) iconView.setColorFilter(context.accentColor) } + + val paddingView = it.findViewById(R.id.preference_padding) + if (paddingView != null) { + paddingView.isVisible = view.isVisible && tvSummary != null && tvSummary.isVisible + } } if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) { val lay = it.findViewById(R.id.preference_widget) if (lay is FrameLayout) { + var needRequestLayout = false var v = it.itemView.findViewById(viewId) if (v == null) { val inflater: LayoutInflater = context.layoutInflater @@ -57,7 +63,8 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr lay.addView(childView) lay.isVisible = true v = lay.findViewById(viewId) - } + } else + needRequestLayout = true if (weightWidth > 0 || weightHeight > 0) { val lp = lay.layoutParams @@ -66,7 +73,8 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr if (weightWidth > 0) lp.width = (context.resources.displayMetrics.density * weightWidth).roundToInt() lay.layoutParams = lp - } + } else if (needRequestLayout) + v.requestLayout() return v } diff --git a/app/src/main/res/layout/view_preference.xml b/app/src/main/res/layout/view_preference.xml index 87b10ef5b..2b67899f9 100644 --- a/app/src/main/res/layout/view_preference.xml +++ b/app/src/main/res/layout/view_preference.xml @@ -7,7 +7,7 @@ android:paddingLeft="16dp" android:paddingTop="10dp" android:paddingRight="16dp" - android:paddingBottom="4dp" + android:paddingBottom="10dp" android:minHeight="42dp" android:clickable="true" android:orientation="horizontal" @@ -27,11 +27,11 @@ android:orientation="vertical" android:layout_weight="1.0" android:layout_width="0dp" + android:layout_gravity="center_vertical" android:layout_height="wrap_content"> + + @color/md_grey_50 @color/md_grey_100 @color/md_grey_200 - @color/md_grey_50 + #7fffffff #00000000 #10000000 diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index ef360b43c..6be6d1e50 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -60,7 +60,7 @@ android:key="selectText" app:iconSpaceReserved="false" /> - diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index bf90dd7ab..ef95487f9 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -12,6 +12,15 @@ app:icons="@array/icons" app:iconSpaceReserved="false" /> + + - -