优化主题

pull/310/head
gedoor 5 years ago
parent 523bb55c6d
commit ab36423722
  1. 22
      app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt
  2. 63
      app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt
  3. 8
      app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt
  4. 189
      app/src/main/res/values/attrs.xml
  5. 45
      app/src/main/res/xml/pref_config_read.xml

@ -6,19 +6,39 @@ import android.widget.TextView
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.utils.ColorUtils
class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
private val isBottomBackground: Boolean
init { init {
layoutResource = R.layout.view_preference layoutResource = R.layout.view_preference
widgetLayoutResource = R.layout.item_fillet_text widgetLayoutResource = R.layout.item_fillet_text
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Preference)
isBottomBackground = typedArray.getBoolean(R.styleable.Preference_bottomBackground, false)
typedArray.recycle()
} }
override fun onBindViewHolder(holder: PreferenceViewHolder?) { override fun onBindViewHolder(holder: PreferenceViewHolder?) {
val v = Preference.bindView<TextView>(context, holder, icon, title, summary, widgetLayoutResource, R.id.text_view) val v = Preference.bindView<TextView>(
context,
holder,
icon,
title,
summary,
widgetLayoutResource,
R.id.text_view,
isBottomBackground = isBottomBackground
)
if (v is TextView) { if (v is TextView) {
v.text = entry v.text = entry
val bgColor = context.bottomBackground
val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
v.setTextColor(pTextColor)
} }
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
} }

@ -13,6 +13,10 @@ import androidx.core.view.isVisible
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor
import io.legado.app.utils.ColorUtils
import org.jetbrains.anko.layoutInflater import org.jetbrains.anko.layoutInflater
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -21,10 +25,13 @@ class Preference(context: Context, attrs: AttributeSet) :
androidx.preference.Preference(context, attrs) { androidx.preference.Preference(context, attrs) {
var onLongClick: (() -> Unit)? = null var onLongClick: (() -> Unit)? = null
private val isBottomBackground: Boolean
init { init {
// isPersistent = true
layoutResource = R.layout.view_preference layoutResource = R.layout.view_preference
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Preference)
isBottomBackground = typedArray.getBoolean(R.styleable.Preference_bottomBackground, false)
typedArray.recycle()
} }
companion object { companion object {
@ -35,30 +42,33 @@ class Preference(context: Context, attrs: AttributeSet) :
icon: Drawable?, icon: Drawable?,
title: CharSequence?, title: CharSequence?,
summary: CharSequence?, summary: CharSequence?,
weightLayoutRes: Int?, weightLayoutRes: Int? = null,
viewId: Int?, viewId: Int? = null,
weightWidth: Int = 0, weightWidth: Int = 0,
weightHeight: Int = 0 weightHeight: Int = 0,
isBottomBackground: Boolean = false
): T? { ): T? {
if (it == null) return null if (it == null) return null
val view = it.findViewById(R.id.preference_title) val tvTitle = it.findViewById(R.id.preference_title) as TextView
if (view is TextView) { tvTitle.text = title
view.text = title tvTitle.isVisible = title != null && title.isNotEmpty()
view.isVisible = title != null && title.isNotEmpty() val tvSummary = it.findViewById(R.id.preference_desc) as? TextView
tvSummary?.let {
val tvSummary = it.findViewById(R.id.preference_desc) tvSummary.text = summary
if (tvSummary is TextView) { tvSummary.isGone = summary.isNullOrEmpty()
tvSummary.text = summary }
tvSummary.isGone = summary.isNullOrEmpty() if (isBottomBackground && !tvTitle.isInEditMode) {
} val bgColor = context.bottomBackground
val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
val iconView = it.findViewById(R.id.preference_icon) tvTitle.setTextColor(pTextColor)
if (iconView is ImageView) { val sTextColor = context.getSecondaryTextColor(ColorUtils.isColorLight(bgColor))
iconView.isVisible = icon != null && icon.isVisible tvSummary?.setTextColor(sTextColor)
iconView.setImageDrawable(icon) }
iconView.setColorFilter(context.accentColor) val iconView = it.findViewById(R.id.preference_icon)
} if (iconView is ImageView) {
iconView.isVisible = icon != null && icon.isVisible
iconView.setImageDrawable(icon)
iconView.setColorFilter(context.accentColor)
} }
if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) { if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) {
@ -98,7 +108,14 @@ class Preference(context: Context, attrs: AttributeSet) :
} }
override fun onBindViewHolder(holder: PreferenceViewHolder?) { override fun onBindViewHolder(holder: PreferenceViewHolder?) {
bindView<View>(context, holder, icon, title, summary, null, null) bindView<View>(
context,
holder,
icon,
title,
summary,
isBottomBackground = isBottomBackground
)
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
holder?.itemView?.onLongClick { holder?.itemView?.onLongClick {
onLongClick?.invoke() onLongClick?.invoke()

@ -12,8 +12,13 @@ import io.legado.app.lib.theme.accentColor
class SwitchPreference(context: Context, attrs: AttributeSet) : class SwitchPreference(context: Context, attrs: AttributeSet) :
SwitchPreferenceCompat(context, attrs) { SwitchPreferenceCompat(context, attrs) {
private val isBottomBackground: Boolean
init { init {
layoutResource = R.layout.view_preference layoutResource = R.layout.view_preference
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Preference)
isBottomBackground = typedArray.getBoolean(R.styleable.Preference_bottomBackground, false)
typedArray.recycle()
} }
override fun onBindViewHolder(holder: PreferenceViewHolder?) { override fun onBindViewHolder(holder: PreferenceViewHolder?) {
@ -24,7 +29,8 @@ class SwitchPreference(context: Context, attrs: AttributeSet) :
title, title,
summary, summary,
widgetLayoutResource, widgetLayoutResource,
R.id.switchWidget R.id.switchWidget,
isBottomBackground = isBottomBackground
) )
if (v is SwitchCompat && !v.isInEditMode) { if (v is SwitchCompat && !v.isInEditMode) {
ATH.setTint(v, context.accentColor) ATH.setTint(v, context.accentColor)

@ -4,67 +4,67 @@
<attr name="radius" format="dimension" /> <attr name="radius" format="dimension" />
<declare-styleable name="TitleBar"> <declare-styleable name="TitleBar">
<attr name="title"/> <attr name="title" />
<attr name="subtitle"/> <attr name="subtitle" />
<attr name="titleTextAppearance"/> <attr name="titleTextAppearance" />
<attr name="titleTextColor"/> <attr name="titleTextColor" />
<attr name="subtitleTextAppearance"/> <attr name="subtitleTextAppearance" />
<attr name="subtitleTextColor"/> <attr name="subtitleTextColor" />
<attr name="contentInsetEnd"/> <attr name="contentInsetEnd" />
<attr name="contentInsetEndWithActions"/> <attr name="contentInsetEndWithActions" />
<attr name="contentInsetStart"/> <attr name="contentInsetStart" />
<attr name="contentInsetStartWithNavigation"/> <attr name="contentInsetStartWithNavigation" />
<attr name="contentInsetLeft"/> <attr name="contentInsetLeft" />
<attr name="contentInsetRight"/> <attr name="contentInsetRight" />
<attr name="contentLayout" format="reference"/> <attr name="contentLayout" format="reference" />
<attr name="attachToActivity" format="boolean"/> <attr name="attachToActivity" format="boolean" />
<attr name="displayHomeAsUp" format="boolean"/> <attr name="displayHomeAsUp" format="boolean" />
<attr name="navigationIcon" format="reference"/> <attr name="navigationIcon" format="reference" />
<attr name="fitStatusBar" format="boolean"/> <attr name="fitStatusBar" format="boolean" />
<attr name="fitNavigationBar" format="boolean"/> <attr name="fitNavigationBar" format="boolean" />
<attr name="navigationContentDescription" format="reference|string"/> <attr name="navigationContentDescription" format="reference|string" />
<attr name="navigationIconTint" format="color|reference"/> <attr name="navigationIconTint" format="color|reference" />
<attr name="navigationIconTintMode" format="enum"> <attr name="navigationIconTintMode" format="enum">
<enum name="clear" value="0"/> <enum name="clear" value="0" />
<enum name="src" value="1"/> <enum name="src" value="1" />
<enum name="dst" value="2"/> <enum name="dst" value="2" />
<enum name="src_over" value="3"/> <enum name="src_over" value="3" />
<enum name="dst_over" value="4"/> <enum name="dst_over" value="4" />
<enum name="src_in" value="5"/> <enum name="src_in" value="5" />
<enum name="dst_in" value="6"/> <enum name="dst_in" value="6" />
<enum name="src_out" value="7"/> <enum name="src_out" value="7" />
<enum name="dst_out" value="8"/> <enum name="dst_out" value="8" />
<enum name="src_atop" value="9"/> <enum name="src_atop" value="9" />
<enum name="dst_atop" value="10"/> <enum name="dst_atop" value="10" />
<enum name="xor" value="11"/> <enum name="xor" value="11" />
<enum name="darken" value="16"/> <enum name="darken" value="16" />
<enum name="lighten" value="17"/> <enum name="lighten" value="17" />
<enum name="multiply" value="13"/> <enum name="multiply" value="13" />
<enum name="screen" value="14"/> <enum name="screen" value="14" />
<enum name="add" value="12"/> <enum name="add" value="12" />
<enum name="overlay" value="15"/> <enum name="overlay" value="15" />
</attr> </attr>
</declare-styleable> </declare-styleable>
<attr name="titleBarStyle" format="reference"/> <attr name="titleBarStyle" format="reference" />
<declare-styleable name="DynamicFrameLayout"> <declare-styleable name="DynamicFrameLayout">
<attr name="errorSrc" format="reference"/> <attr name="errorSrc" format="reference" />
<attr name="emptySrc" format="reference"/> <attr name="emptySrc" format="reference" />
<attr name="errorActionDescription" format="string|reference"/> <attr name="errorActionDescription" format="string|reference" />
<attr name="emptyActionDescription" format="string|reference"/> <attr name="emptyActionDescription" format="string|reference" />
<attr name="emptyDescription" format="string|reference"/> <attr name="emptyDescription" format="string|reference" />
</declare-styleable> </declare-styleable>
<declare-styleable name="RefreshProgressBar"> <declare-styleable name="RefreshProgressBar">
<attr name="max_progress" format="integer"/> <attr name="max_progress" format="integer" />
<attr name="dur_progress" format="integer"/> <attr name="dur_progress" format="integer" />
<attr name="second_dur_progress" format="dimension"/> <attr name="second_dur_progress" format="dimension" />
<attr name="second_max_progress" format="dimension"/> <attr name="second_max_progress" format="dimension" />
<attr name="bg_color" format="color"/> <attr name="bg_color" format="color" />
<attr name="second_color" format="color"/> <attr name="second_color" format="color" />
<attr name="font_color" format="color"/> <attr name="font_color" format="color" />
<attr name="speed" format="dimension"/> <attr name="speed" format="dimension" />
</declare-styleable> </declare-styleable>
<declare-styleable name="DetailSeekBar"> <declare-styleable name="DetailSeekBar">
@ -73,53 +73,53 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="SmoothCheckBox"> <declare-styleable name="SmoothCheckBox">
<attr name="duration" format="integer"/> <attr name="duration" format="integer" />
<attr name="stroke_width" format="dimension"/> <attr name="stroke_width" format="dimension" />
<attr name="color_tick" format="color"/> <attr name="color_tick" format="color" />
<attr name="color_checked" format="color"/> <attr name="color_checked" format="color" />
<attr name="color_unchecked" format="color"/> <attr name="color_unchecked" format="color" />
<attr name="color_unchecked_stroke" format="color"/> <attr name="color_unchecked_stroke" format="color" />
</declare-styleable> </declare-styleable>
<declare-styleable name="NumberPickerPreference"> <declare-styleable name="NumberPickerPreference">
<attr name="MinValue" format="integer"/> <attr name="MinValue" format="integer" />
<attr name="MaxValue" format="integer"/> <attr name="MaxValue" format="integer" />
<attr name="android:summary"/> <attr name="android:summary" />
</declare-styleable> </declare-styleable>
<declare-styleable name="RefreshLayout"> <declare-styleable name="RefreshLayout">
<attr name="layout_refresh_empty" format="reference"/> <attr name="layout_refresh_empty" format="reference" />
<attr name="layout_refresh_error" format="reference"/> <attr name="layout_refresh_error" format="reference" />
<attr name="layout_refresh_loading" format="reference"/> <attr name="layout_refresh_loading" format="reference" />
</declare-styleable> </declare-styleable>
<declare-styleable name="FastScroller"> <declare-styleable name="FastScroller">
<attr name="fadeScrollbar" format="boolean"/> <attr name="fadeScrollbar" format="boolean" />
<attr name="showBubble" format="boolean"/> <attr name="showBubble" format="boolean" />
<attr name="showTrack" format="boolean"/> <attr name="showTrack" format="boolean" />
<attr name="trackColor" format="color"/> <attr name="trackColor" format="color" />
<attr name="handleColor" format="color"/> <attr name="handleColor" format="color" />
<attr name="bubbleColor" format="color"/> <attr name="bubbleColor" format="color" />
<attr name="bubbleTextColor" format="color"/> <attr name="bubbleTextColor" format="color" />
</declare-styleable> </declare-styleable>
<declare-styleable name="FilletImageView"> <declare-styleable name="FilletImageView">
<attr name="radius" /> <attr name="radius" />
<attr name="left_top_radius" format="dimension"/> <attr name="left_top_radius" format="dimension" />
<attr name="right_top_radius" format="dimension"/> <attr name="right_top_radius" format="dimension" />
<attr name="right_bottom_radius" format="dimension"/> <attr name="right_bottom_radius" format="dimension" />
<attr name="left_bottom_radius" format="dimension"/> <attr name="left_bottom_radius" format="dimension" />
</declare-styleable> </declare-styleable>
<declare-styleable name="IconListPreference"> <declare-styleable name="IconListPreference">
<attr name="icons" format="reference"/> <attr name="icons" format="reference" />
</declare-styleable> </declare-styleable>
<declare-styleable name="RotateLoading"> <declare-styleable name="RotateLoading">
<attr name="loading_width" format="dimension"/> <attr name="loading_width" format="dimension" />
<attr name="loading_color" format="color"/> <attr name="loading_color" format="color" />
<attr name="shadow_position" format="integer"/> <attr name="shadow_position" format="integer" />
<attr name="loading_speed" format="integer"/> <attr name="loading_speed" format="integer" />
<attr name="hide_mode"> <attr name="hide_mode">
<!-- Not displayed, but taken into account during layout (space is left for it). --> <!-- Not displayed, but taken into account during layout (space is left for it). -->
<enum name="invisible" value="1" /> <enum name="invisible" value="1" />
@ -174,16 +174,25 @@
<attr name="arcDirectionTop" format="boolean" /> <attr name="arcDirectionTop" format="boolean" />
</declare-styleable> </declare-styleable>
<declare-styleable name="ShadowLayout">
<declare-styleable name="ShadowLayout"><attr format="color" name="shadowColor"/><attr format="dimension" name="shadowRadius"/><attr format="dimension" name="shadowDx"/><attr format="dimension" name="shadowDy"/><attr name="shadowShape"> <attr name="shadowColor" format="color" />
<flag name="rectangle" value="0x0001"/> <attr name="shadowRadius" format="dimension" />
<flag name="oval" value="0x0010"/> <attr name="shadowDx" format="dimension" />
</attr><attr name="shadowSide"> <attr name="shadowDy" format="dimension" />
<flag name="all" value="0x1111"/> <attr name="shadowShape">
<flag name="left" value="0x0001"/> <flag name="rectangle" value="0x0001" />
<flag name="top" value="0x0010"/> <flag name="oval" value="0x0010" />
<flag name="right" value="0x0100"/> </attr>
<flag name="bottom" value="0x1000"/> <attr name="shadowSide">
<flag name="all" value="0x1111" />
<flag name="left" value="0x0001" />
<flag name="top" value="0x0010" />
<flag name="right" value="0x0100" />
<flag name="bottom" value="0x1000" />
</attr> </attr>
</declare-styleable> </declare-styleable>
<declare-styleable name="Preference">
<attr name="bottomBackground" format="boolean" />
</declare-styleable>
</resources> </resources>

@ -8,7 +8,8 @@
android:title="@string/screen_direction" android:title="@string/screen_direction"
android:entries="@array/screen_direction_title" android:entries="@array/screen_direction_title"
android:entryValues="@array/screen_direction_value" android:entryValues="@array/screen_direction_value"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.NameListPreference <io.legado.app.ui.widget.prefs.NameListPreference
android:key="keep_light" android:key="keep_light"
@ -16,83 +17,97 @@
android:entryValues="@array/screen_time_out_value" android:entryValues="@array/screen_time_out_value"
android:entries="@array/screen_time_out" android:entries="@array/screen_time_out"
android:title="@string/keep_light" android:title="@string/keep_light"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/pt_hide_status_bar" android:title="@string/pt_hide_status_bar"
android:key="hideStatusBar" android:key="hideStatusBar"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/read_body_to_lh" android:title="@string/read_body_to_lh"
android:key="readBodyToLh" android:key="readBodyToLh"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/pt_hide_navigation_bar" android:title="@string/pt_hide_navigation_bar"
android:key="hideNavigationBar" android:key="hideNavigationBar"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/text_full_justify" android:title="@string/text_full_justify"
android:key="textFullJustify" android:key="textFullJustify"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/text_bottom_justify" android:title="@string/text_bottom_justify"
android:key="textBottomJustify" android:key="textBottomJustify"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/volume_key_page" android:title="@string/volume_key_page"
android:key="volumeKeyPage" android:key="volumeKeyPage"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/click_turn_page" android:title="@string/click_turn_page"
android:key="clickTurnPage" android:key="clickTurnPage"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/click_all_next_page" android:title="@string/click_all_next_page"
android:key="clickAllNext" android:key="clickAllNext"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/volume_key_page_on_play" android:title="@string/volume_key_page_on_play"
android:key="volumeKeyPageOnPlay" android:key="volumeKeyPageOnPlay"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/auto_change_source" android:title="@string/auto_change_source"
android:key="autoChangeSource" android:key="autoChangeSource"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/selectText" android:title="@string/selectText"
android:key="selectText" android:key="selectText"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/show_brightness_view" android:title="@string/show_brightness_view"
android:key="showBrightnessView" android:key="showBrightnessView"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="customPageKey" android:key="customPageKey"
android:title="@string/custom_page_key" android:title="@string/custom_page_key"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false"
app:bottomBackground="true" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>
Loading…
Cancel
Save