优化主题

pull/310/head
gedoor 4 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.PreferenceViewHolder
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) {
private val isBottomBackground: Boolean
init {
layoutResource = R.layout.view_preference
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?) {
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) {
v.text = entry
val bgColor = context.bottomBackground
val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
v.setTextColor(pTextColor)
}
super.onBindViewHolder(holder)
}

@ -13,6 +13,10 @@ import androidx.core.view.isVisible
import androidx.preference.PreferenceViewHolder
import io.legado.app.R
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.sdk27.listeners.onLongClick
import kotlin.math.roundToInt
@ -21,10 +25,13 @@ class Preference(context: Context, attrs: AttributeSet) :
androidx.preference.Preference(context, attrs) {
var onLongClick: (() -> Unit)? = null
private val isBottomBackground: Boolean
init {
// isPersistent = true
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 {
@ -35,30 +42,33 @@ class Preference(context: Context, attrs: AttributeSet) :
icon: Drawable?,
title: CharSequence?,
summary: CharSequence?,
weightLayoutRes: Int?,
viewId: Int?,
weightLayoutRes: Int? = null,
viewId: Int? = null,
weightWidth: Int = 0,
weightHeight: Int = 0
weightHeight: Int = 0,
isBottomBackground: Boolean = false
): T? {
if (it == null) return null
val view = it.findViewById(R.id.preference_title)
if (view is TextView) {
view.text = title
view.isVisible = title != null && title.isNotEmpty()
val tvSummary = it.findViewById(R.id.preference_desc)
if (tvSummary is TextView) {
tvSummary.text = summary
tvSummary.isGone = summary.isNullOrEmpty()
}
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)
}
val tvTitle = it.findViewById(R.id.preference_title) as TextView
tvTitle.text = title
tvTitle.isVisible = title != null && title.isNotEmpty()
val tvSummary = it.findViewById(R.id.preference_desc) as? TextView
tvSummary?.let {
tvSummary.text = summary
tvSummary.isGone = summary.isNullOrEmpty()
}
if (isBottomBackground && !tvTitle.isInEditMode) {
val bgColor = context.bottomBackground
val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
tvTitle.setTextColor(pTextColor)
val sTextColor = context.getSecondaryTextColor(ColorUtils.isColorLight(bgColor))
tvSummary?.setTextColor(sTextColor)
}
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) {
@ -98,7 +108,14 @@ class Preference(context: Context, attrs: AttributeSet) :
}
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)
holder?.itemView?.onLongClick {
onLongClick?.invoke()

@ -12,8 +12,13 @@ import io.legado.app.lib.theme.accentColor
class SwitchPreference(context: Context, attrs: AttributeSet) :
SwitchPreferenceCompat(context, attrs) {
private val isBottomBackground: Boolean
init {
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?) {
@ -24,7 +29,8 @@ class SwitchPreference(context: Context, attrs: AttributeSet) :
title,
summary,
widgetLayoutResource,
R.id.switchWidget
R.id.switchWidget,
isBottomBackground = isBottomBackground
)
if (v is SwitchCompat && !v.isInEditMode) {
ATH.setTint(v, context.accentColor)

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

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