From 201fbe843e6c23696acd610e64d34a650afd3952 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Thu, 19 Mar 2020 17:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4"=E6=88=91=E7=9A=84"UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/prefs/ColorPreference.kt | 19 +++- .../app/ui/widget/prefs/EditTextPreference.kt | 22 ++++ .../app/ui/widget/prefs/IconListPreference.kt | 11 +- .../app/ui/widget/prefs/NameListPreference.kt | 7 +- .../legado/app/ui/widget/prefs/Preference.kt | 101 ++++++++++++++++++ .../app/ui/widget/prefs/PreferenceCategory.kt | 29 ++++- .../app/ui/widget/prefs/SwitchPreference.kt | 12 ++- app/src/main/res/drawable/bg_prefs_color.xml | 10 ++ app/src/main/res/drawable/ic_cfg_about.xml | 15 +++ app/src/main/res/drawable/ic_cfg_backup.xml | 9 ++ app/src/main/res/drawable/ic_cfg_e_lnk.xml | 5 + app/src/main/res/drawable/ic_cfg_jz.xml | 12 +++ app/src/main/res/drawable/ic_cfg_other.xml | 12 +++ app/src/main/res/drawable/ic_cfg_replace.xml | 12 +++ app/src/main/res/drawable/ic_cfg_source.xml | 12 +++ app/src/main/res/drawable/ic_cfg_theme.xml | 9 ++ app/src/main/res/drawable/ic_cfg_web.xml | 9 ++ app/src/main/res/layout/view_preference.xml | 67 ++++++++++++ .../res/layout/view_preference_category.xml | 29 +++++ app/src/main/res/layout/view_preference_s.xml | 66 ++++++++++++ app/src/main/res/values-night/colors.xml | 1 + app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 5 + app/src/main/res/xml/about.xml | 30 ++++-- app/src/main/res/xml/donate.xml | 25 +++-- app/src/main/res/xml/pref_config_backup.xml | 24 +++-- app/src/main/res/xml/pref_config_other.xml | 8 ++ app/src/main/res/xml/pref_config_theme.xml | 14 ++- app/src/main/res/xml/pref_main.xml | 44 ++++++-- 29 files changed, 569 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt create mode 100644 app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt create mode 100644 app/src/main/res/drawable/bg_prefs_color.xml create mode 100644 app/src/main/res/drawable/ic_cfg_about.xml create mode 100644 app/src/main/res/drawable/ic_cfg_backup.xml create mode 100644 app/src/main/res/drawable/ic_cfg_e_lnk.xml create mode 100644 app/src/main/res/drawable/ic_cfg_jz.xml create mode 100644 app/src/main/res/drawable/ic_cfg_other.xml create mode 100644 app/src/main/res/drawable/ic_cfg_replace.xml create mode 100644 app/src/main/res/drawable/ic_cfg_source.xml create mode 100644 app/src/main/res/drawable/ic_cfg_theme.xml create mode 100644 app/src/main/res/drawable/ic_cfg_web.xml create mode 100644 app/src/main/res/layout/view_preference.xml create mode 100644 app/src/main/res/layout/view_preference_category.xml create mode 100644 app/src/main/res/layout/view_preference_s.xml diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt index 6bea75a51..998e9c7c4 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt @@ -6,14 +6,24 @@ import android.content.res.TypedArray import android.graphics.Color import android.os.Bundle import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView import androidx.annotation.ColorInt import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog +import androidx.appcompat.widget.SwitchCompat +import androidx.core.view.isVisible import androidx.fragment.app.FragmentActivity import androidx.preference.Preference import androidx.preference.PreferenceViewHolder import com.jaredrummler.android.colorpicker.* import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.accentColor +import org.jetbrains.anko.layoutInflater +import org.jetbrains.anko.px2dip class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), ColorPickerDialogListener { @@ -37,6 +47,8 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex init { isPersistent = true + layoutResource = io.legado.app.R.layout.view_preference_s + val a = context.obtainStyledAttributes(attrs, R.styleable.ColorPreference) showDialog = a.getBoolean(R.styleable.ColorPreference_cpv_showDialog, true) @@ -110,8 +122,11 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) - val preview = holder.itemView.findViewById(R.id.cpv_preference_preview_color_panel) as ColorPanelView - preview.color = color + val v = io.legado.app.ui.widget.prefs.Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, + io.legado.app.R.id.cpv_preference_preview_color_panel, 30, 30) + if (v is ColorPanelView) { + v?.color = color + } } override fun onSetInitialValue(defaultValue: Any?) { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt new file mode 100644 index 000000000..b914afcf5 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt @@ -0,0 +1,22 @@ +package io.legado.app.ui.widget.prefs + +import android.content.Context +import android.util.AttributeSet +import android.widget.TextView +import androidx.preference.PreferenceViewHolder +import io.legado.app.R + +class EditTextPreference(context: Context, attrs: AttributeSet) : androidx.preference.EditTextPreference(context, attrs) { + + init { + // isPersistent = true + layoutResource = R.layout.view_preference + } + + override fun onBindViewHolder(holder: PreferenceViewHolder?) { + super.onBindViewHolder(holder) + val txt = if (text == null || text.isEmpty()) summary else text + val v = Preference.bindView(context, holder, icon, title, txt, null, null) + } + +} 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 index b295e5ad3..2e043b4c3 100644 --- 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 @@ -10,17 +10,22 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView +import android.widget.TextView +import androidx.core.view.isVisible import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentActivity import androidx.preference.ListPreference import androidx.preference.PreferenceViewHolder import androidx.recyclerview.widget.LinearLayoutManager +import com.jaredrummler.android.colorpicker.ColorPanelView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatDrawable import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_icon_preference.view.* +import org.jetbrains.anko.layoutInflater import org.jetbrains.anko.sdk27.listeners.onClick @@ -29,6 +34,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference private val mEntryDrawables = arrayListOf() init { + layoutResource = io.legado.app.R.layout.view_preference widgetLayoutResource = R.layout.view_icon val a = context.theme.obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0) @@ -52,11 +58,12 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference override fun onBindViewHolder(holder: PreferenceViewHolder?) { super.onBindViewHolder(holder) - holder?.itemView?.findViewById(R.id.preview)?.let { + val v = Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, R.id.preview, 50, 50) + if (v is ImageView) { val selectedIndex = findIndexOfValue(value) if (selectedIndex >= 0) { val drawable = mEntryDrawables[selectedIndex] - it.setImageDrawable(drawable) + v?.setImageDrawable(drawable) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt index d8b51e90f..f4c1ccac2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt @@ -11,12 +11,15 @@ import io.legado.app.R class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { init { + layoutResource = R.layout.view_preference widgetLayoutResource = R.layout.item_fillet_text } override fun onBindViewHolder(holder: PreferenceViewHolder?) { super.onBindViewHolder(holder) - val textView = holder?.itemView?.findViewById(R.id.text_view) - textView?.text = entry + val v = Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, R.id.text_view) + if (v is TextView) { + v?.text = entry + } } } \ No newline at end of file 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 new file mode 100644 index 000000000..30603c89d --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -0,0 +1,101 @@ +package io.legado.app.ui.widget.prefs + +import android.content.Context +import android.content.ContextWrapper +import android.content.res.TypedArray +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.media.Image +import android.os.Bundle +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout +import android.widget.ImageView +import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.annotation.StringRes +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.widget.SwitchCompat +import androidx.core.view.isVisible +import androidx.core.view.updateLayoutParams +import androidx.fragment.app.FragmentActivity +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import com.jaredrummler.android.colorpicker.* +import io.legado.app.lib.theme.ATH +import io.legado.app.R +import io.legado.app.lib.theme.accentColor +import org.jetbrains.anko.imageBitmap +import org.jetbrains.anko.layoutInflater +import kotlin.math.roundToInt + +class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Preference(context, attrs) { + + init { + // isPersistent = true + layoutResource = R.layout.view_preference + } + + 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? { + if (it == null) return null + val view = it.findViewById(R.id.preference_title) + if (view is TextView) { // && !view.isInEditMode + view.text = title + view.isVisible = title != null && title.isNotEmpty() + + val tv_summary = it.findViewById(R.id.preference_desc) + if(tv_summary is TextView) { + tv_summary.text = summary + tv_summary.isVisible = summary != null && summary.isNotEmpty() + } + + val _icon = it.findViewById(R.id.preference_icon) + if (_icon is ImageView) { + _icon.isVisible = icon != null && icon.isVisible + _icon.setImageDrawable(icon) + _icon.setColorFilter(context.accentColor) + } + } + + if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) { + val lay = it.findViewById(R.id.preference_widget) + if (lay is FrameLayout) { + var v = it.itemView.findViewById(viewId) + if (v == null) { + val inflater: LayoutInflater = context.layoutInflater + val childView = inflater.inflate(weightLayoutRes, null) + lay.removeAllViews() + lay.addView(childView) + lay.isVisible = true + v = lay.findViewById(viewId) + } + + if (weightWidth > 0 || weightHeight > 0) { + val lp = lay.layoutParams + if (weightHeight > 0) + lp.height = (context.resources.displayMetrics.density * weightHeight).roundToInt() + if (weightWidth > 0) + lp.width = (context.resources.displayMetrics.density * weightWidth).roundToInt() + lay.layoutParams = lp + } + + return v + } + } + + return null + } + + } + + override fun onBindViewHolder(holder: PreferenceViewHolder?) { + super.onBindViewHolder(holder) + bindView(context, holder, icon, title, summary, null, null) + } + +} 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 e1458b76e..a7dcd2e6c 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 @@ -1,22 +1,41 @@ package io.legado.app.ui.widget.prefs import android.content.Context +import android.graphics.Color import android.util.AttributeSet +import android.view.View import android.widget.TextView +import androidx.core.view.isVisible import androidx.preference.PreferenceCategory import androidx.preference.PreferenceViewHolder +import io.legado.app.R import io.legado.app.lib.theme.accentColor -class PreferenceCategory(context: Context, attrs: AttributeSet) : - PreferenceCategory(context, attrs) { +class PreferenceCategory(context: Context, attrs: AttributeSet) : PreferenceCategory(context, attrs) { + + init { + isPersistent = true + layoutResource = R.layout.view_preference_category + } override fun onBindViewHolder(holder: PreferenceViewHolder?) { super.onBindViewHolder(holder) holder?.let { - val view = it.findViewById(android.R.id.title) - if (view is TextView && !view.isInEditMode) { - view.setTextColor(context.accentColor)//设置title文本的颜色 + val view = it.findViewById(R.id.preference_title) + if (view is TextView) { // && !view.isInEditMode + view.text = title + view.setTextColor(context.accentColor) //设置title文本的颜色 + view.isVisible = title != null && title.isNotEmpty() + + val da = it.findViewById(R.id.preference_divider_above) + if (da is View) { + da.isVisible = it.isDividerAllowedAbove + } + val db = it.findViewById(R.id.preference_divider_below) + if (db is View) { + db.isVisible = it.isDividerAllowedBelow + } } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt index 4fe66af7b..91532bbb5 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt @@ -12,13 +12,15 @@ import io.legado.app.lib.theme.accentColor class SwitchPreference(context: Context, attrs: AttributeSet) : SwitchPreferenceCompat(context, attrs) { + init { + layoutResource = R.layout.view_preference + } + override fun onBindViewHolder(holder: PreferenceViewHolder?) { super.onBindViewHolder(holder) - holder?.let { - val view = it.findViewById(R.id.switchWidget) - if (view is SwitchCompat) { - ATH.setTint(view, context.accentColor) - } + val v = Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, R.id.switchWidget) + if (v is SwitchCompat) { + ATH.setTint(v, context.accentColor) } } diff --git a/app/src/main/res/drawable/bg_prefs_color.xml b/app/src/main/res/drawable/bg_prefs_color.xml new file mode 100644 index 000000000..ff4a5de4e --- /dev/null +++ b/app/src/main/res/drawable/bg_prefs_color.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_cfg_about.xml b/app/src/main/res/drawable/ic_cfg_about.xml new file mode 100644 index 000000000..42e3d30d3 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_about.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_cfg_backup.xml b/app/src/main/res/drawable/ic_cfg_backup.xml new file mode 100644 index 000000000..9c647c009 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_backup.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_cfg_e_lnk.xml b/app/src/main/res/drawable/ic_cfg_e_lnk.xml new file mode 100644 index 000000000..b94a8eb4d --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_e_lnk.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_jz.xml b/app/src/main/res/drawable/ic_cfg_jz.xml new file mode 100644 index 000000000..710bae7fd --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_jz.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_other.xml b/app/src/main/res/drawable/ic_cfg_other.xml new file mode 100644 index 000000000..a3d26b642 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_other.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_replace.xml b/app/src/main/res/drawable/ic_cfg_replace.xml new file mode 100644 index 000000000..53c9d1d04 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_replace.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_source.xml b/app/src/main/res/drawable/ic_cfg_source.xml new file mode 100644 index 000000000..e71bb109d --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_source.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_theme.xml b/app/src/main/res/drawable/ic_cfg_theme.xml new file mode 100644 index 000000000..2fe949d19 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_theme.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_cfg_web.xml b/app/src/main/res/drawable/ic_cfg_web.xml new file mode 100644 index 000000000..7a34ae004 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_web.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/view_preference.xml b/app/src/main/res/layout/view_preference.xml new file mode 100644 index 000000000..203241bf0 --- /dev/null +++ b/app/src/main/res/layout/view_preference.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_preference_category.xml b/app/src/main/res/layout/view_preference_category.xml new file mode 100644 index 000000000..28f4e73ff --- /dev/null +++ b/app/src/main/res/layout/view_preference_category.xml @@ -0,0 +1,29 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_preference_s.xml b/app/src/main/res/layout/view_preference_s.xml new file mode 100644 index 000000000..37a354c52 --- /dev/null +++ b/app/src/main/res/layout/view_preference_s.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 78d372bbd..8ac7aa66a 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -7,6 +7,7 @@ @color/md_grey_900 @color/md_grey_850 @color/md_grey_800 + #10303030 #69000000 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 58f27cdec..0fe64b7ca 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -16,6 +16,7 @@ @color/md_grey_50 @color/md_grey_100 @color/md_grey_200 + @color/md_grey_50 #00000000 #10000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 558e90cbe..bc219ab39 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,6 +29,7 @@ 删除 替换 替换净化 + 配置替换净化规则 暂无 启用 替换净化-搜索 @@ -58,6 +59,7 @@ 添加本地 书源 书源管理 + 新建/导入/编辑/管理书源 设置 主题设置 与界面/颜色相关的一些设置 @@ -80,6 +82,7 @@ 加载中… 重试 Web 服务 + 启用Web服务 web编辑书源 http://%1$s:%2$d 离线下载 @@ -442,6 +445,7 @@ 选中时点击可弹出菜单 主题 主题模式 + 选择主题模式 默认主题 恢复主题为默认配色 加入QQ群 @@ -457,6 +461,7 @@ 导入本地书籍需存储权限 夜间模式 E-Ink 模式 + 电子墨水屏模式 本软件需要存储权限来存储备份书籍信息 再按一次退出程序 导入本地书籍需存储权限 diff --git a/app/src/main/res/xml/about.xml b/app/src/main/res/xml/about.xml index 130e16e60..2970ab12b 100644 --- a/app/src/main/res/xml/about.xml +++ b/app/src/main/res/xml/about.xml @@ -2,68 +2,78 @@ - - - - - - - - - - diff --git a/app/src/main/res/xml/donate.xml b/app/src/main/res/xml/donate.xml index 13d448544..8732f864c 100644 --- a/app/src/main/res/xml/donate.xml +++ b/app/src/main/res/xml/donate.xml @@ -4,51 +4,64 @@ - - - - - - - - - - + - - - - diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index b049bcf22..2f6d23f9c 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -4,6 +4,9 @@ - - + xmlns:app="http://schemas.android.com/apk/res-auto" + android:divider="@color/transparent" + app:allowDividerBelow="false" + app:allowDividerAbove="false" + > - - + app:iconSpaceReserved="false" + app:allowDividerAbove="true" + app:allowDividerBelow="false" > - - - - -