优化主题

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. 47
      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. 15
      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,23 +42,28 @@ 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) {
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
@ -59,8 +71,6 @@ class Preference(context: Context, attrs: AttributeSet) :
iconView.setColorFilter(context.accentColor)
}
}
if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) {
val lay = it.findViewById(R.id.preference_widget)
if (lay is FrameLayout) {
@ -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)

@ -174,11 +174,16 @@
<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">
<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">
</attr>
<attr name="shadowSide">
<flag name="all" value="0x1111" />
<flag name="left" value="0x0001" />
<flag name="top" value="0x0010" />
@ -186,4 +191,8 @@
<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