From 4079f2c247dfa0f2bbd55931d15441fde7497825 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 11 Feb 2020 19:23:38 +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 --- app/src/main/AndroidManifest.xml | 1 + .../widget/prefs/ColorPreference.kt} | 9 +-- .../app/ui/widget/prefs/IconListPreference.kt | 47 ++++++++++++ .../widget/prefs/NameListPreference.kt} | 4 +- .../main/res/drawable-v24/ic_launcher_1.xml | 71 +++++++++++++++++++ .../res/mipmap-anydpi-v26/ic_launcher_1.xml | 5 ++ app/src/main/res/xml/pref_config_read.xml | 2 +- app/src/main/res/xml/pref_config_theme.xml | 12 ++-- app/src/main/res/xml/pref_main.xml | 2 +- 9 files changed, 139 insertions(+), 14 deletions(-) rename app/src/main/java/io/legado/app/{lib/theme/prefs/ATEColorPreference.kt => ui/widget/prefs/ColorPreference.kt} (98%) create mode 100644 app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt rename app/src/main/java/io/legado/app/{lib/theme/prefs/ATEListPreference.kt => ui/widget/prefs/NameListPreference.kt} (78%) create mode 100644 app/src/main/res/drawable-v24/ic_launcher_1.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 09a0d5364..8bc68fcea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,6 +41,7 @@ diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt similarity index 98% rename from app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt rename to app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt index 02b5d2f45..a57b97e23 100644 --- a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt @@ -1,4 +1,4 @@ -package io.legado.app.lib.theme.prefs +package io.legado.app.ui.widget.prefs import android.content.Context import android.content.ContextWrapper @@ -15,7 +15,7 @@ import androidx.preference.PreferenceViewHolder import com.jaredrummler.android.colorpicker.* import io.legado.app.lib.theme.ATH -class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), +class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), ColorPickerDialogListener { private val sizeNormal = 0 @@ -86,7 +86,7 @@ class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(con } } - fun getActivity(): FragmentActivity { + private fun getActivity(): FragmentActivity { val context = context if (context is FragmentActivity) { return context @@ -397,7 +397,8 @@ class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(con * @see .show */ fun create(): ColorPickerDialog { - val dialog = ColorPickerDialogCompat() + val dialog = + ColorPickerDialogCompat() val args = Bundle() args.putInt(ARG_ID, dialogId) args.putInt(ARG_TYPE, dialogType) diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt new file mode 100644 index 000000000..14b1abb5e --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -0,0 +1,47 @@ +package io.legado.app.ui.widget.prefs + +import android.content.Context +import android.graphics.drawable.Drawable +import android.util.AttributeSet +import android.widget.ImageView +import androidx.preference.ListPreference +import androidx.preference.PreferenceViewHolder +import io.legado.app.R + + +class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { + + private val mEntryDrawables = arrayListOf() + + init { + widgetLayoutResource = R.layout.view_icon + + val a = context.theme.obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0) + + val drawables: Array + + drawables = try { + a.getTextArray(R.styleable.IconListPreference_icons) + } finally { + a.recycle() + } + + for (drawable in drawables) { + val resId = context.resources + .getIdentifier(drawable.toString(), "mipmap", context.packageName) + val d = context.resources.getDrawable(resId) + mEntryDrawables.add(d) + } + } + + override fun onBindViewHolder(holder: PreferenceViewHolder?) { + super.onBindViewHolder(holder) + holder?.itemView?.findViewById(R.id.preview)?.let { + val selectedIndex = findIndexOfValue(value) + val drawable = mEntryDrawables[selectedIndex] + it.setImageDrawable(drawable) + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt similarity index 78% rename from app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt rename to app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt index 3e81a1d1c..b51db7a19 100644 --- a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt @@ -1,4 +1,4 @@ -package io.legado.app.lib.theme.prefs +package io.legado.app.ui.widget.prefs import android.content.Context import android.util.AttributeSet @@ -8,7 +8,7 @@ import androidx.preference.PreferenceViewHolder import io.legado.app.R -class ATEListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { +class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { init { widgetLayoutResource = R.layout.item_text diff --git a/app/src/main/res/drawable-v24/ic_launcher_1.xml b/app/src/main/res/drawable-v24/ic_launcher_1.xml new file mode 100644 index 000000000..31d02eef6 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_1.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml new file mode 100644 index 000000000..ec6b59efa --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 2ab931c64..5aae899c8 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -2,7 +2,7 @@ - - - - - - - -