优化主题

pull/310/head
gedoor 4 years ago
parent f778e8dd2c
commit dc0e2a4c3c
  1. 48
      app/src/main/java/io/legado/app/lib/theme/view/ATERadioNoButton.kt
  2. 22
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  3. 15
      app/src/main/res/layout/dialog_read_book_style.xml
  4. 4
      app/src/main/res/values/attrs.xml

@ -5,7 +5,10 @@ import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatRadioButton import androidx.appcompat.widget.AppCompatRadioButton
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore 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.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
@ -15,13 +18,42 @@ import io.legado.app.utils.getCompatColor
class ATERadioNoButton(context: Context, attrs: AttributeSet) : class ATERadioNoButton(context: Context, attrs: AttributeSet) :
AppCompatRadioButton(context, attrs) { AppCompatRadioButton(context, attrs) {
private val isBottomBackground: Boolean
init { init {
background = Selector.shapeBuild() val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ATERadioNoButton)
.setCornerRadius(2.dp) isBottomBackground =
.setStrokeWidth(2.dp) typedArray.getBoolean(R.styleable.ATERadioNoButton_isBottomBackground, false)
.setCheckedBgColor(ThemeStore.accentColor(context)) typedArray.recycle()
.setCheckedStrokeColor(ThemeStore.accentColor(context)) initTheme()
.setDefaultStrokeColor(context.getCompatColor(R.color.primaryText))
.create()
} }
private fun initTheme() {
when {
isInEditMode -> Unit
isBottomBackground -> {
val isLight = ColorUtils.isColorLight(context.bottomBackground)
val textColor = context.getPrimaryTextColor(isLight)
setTextColor(textColor)
background = Selector.shapeBuild()
.setCornerRadius(2.dp)
.setStrokeWidth(2.dp)
.setCheckedBgColor(context.accentColor)
.setCheckedStrokeColor(context.accentColor)
.setDefaultStrokeColor(textColor)
.create()
}
else -> {
background = Selector.shapeBuild()
.setCornerRadius(2.dp)
.setStrokeWidth(2.dp)
.setCheckedBgColor(context.accentColor)
.setCheckedStrokeColor(context.accentColor)
.setDefaultStrokeColor(context.getCompatColor(R.color.primaryText))
.create()
}
}
}
} }

@ -1,11 +1,13 @@
package io.legado.app.ui.book.read.config package io.legado.app.ui.book.read.config
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.* import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.get import androidx.core.view.get
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
@ -17,6 +19,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
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.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.Help
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
@ -51,16 +54,6 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
} }
} }
override fun onAttach(context: Context) {
val bg = requireContext().bottomBackground
val contextThemeWrapper = if (ColorUtils.isColorLight(bg)) {
ContextThemeWrapper(requireContext(), R.style.AppTheme_Light)
} else {
ContextThemeWrapper(requireContext(), R.style.AppTheme_Dark)
}
super.onAttach(contextThemeWrapper)
}
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
@ -81,6 +74,11 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
} }
private fun initView() { private fun initView() {
val isLight = ColorUtils.isColorLight(requireContext().bottomBackground)
val textColor = requireContext().getPrimaryTextColor(isLight)
tv_page_anim.setTextColor(textColor)
tv_bg_ts.setTextColor(textColor)
tv_share_layout.setTextColor(textColor)
root_view.setBackgroundColor(requireContext().bottomBackground) root_view.setBackgroundColor(requireContext().bottomBackground)
dsb_text_size.valueFormat = { dsb_text_size.valueFormat = {
(it + 5).toString() (it + 5).toString()

@ -228,7 +228,8 @@
android:button="@null" android:button="@null"
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/page_anim_cover" /> android:text="@string/page_anim_cover"
app:isBottomBackground="true" />
<io.legado.app.lib.theme.view.ATERadioNoButton <io.legado.app.lib.theme.view.ATERadioNoButton
android:id="@+id/rb_anim1" android:id="@+id/rb_anim1"
@ -240,7 +241,8 @@
android:button="@null" android:button="@null"
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/page_anim_slide" /> android:text="@string/page_anim_slide"
app:isBottomBackground="true" />
<io.legado.app.lib.theme.view.ATERadioNoButton <io.legado.app.lib.theme.view.ATERadioNoButton
android:id="@+id/rb_simulation_anim" android:id="@+id/rb_simulation_anim"
@ -252,7 +254,8 @@
android:button="@null" android:button="@null"
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/page_anim_simulation" /> android:text="@string/page_anim_simulation"
app:isBottomBackground="true" />
<io.legado.app.lib.theme.view.ATERadioNoButton <io.legado.app.lib.theme.view.ATERadioNoButton
android:id="@+id/rb_scroll_anim" android:id="@+id/rb_scroll_anim"
@ -264,7 +267,8 @@
android:button="@null" android:button="@null"
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/page_anim_scroll" /> android:text="@string/page_anim_scroll"
app:isBottomBackground="true" />
<io.legado.app.lib.theme.view.ATERadioNoButton <io.legado.app.lib.theme.view.ATERadioNoButton
android:id="@+id/rb_no_anim" android:id="@+id/rb_no_anim"
@ -276,7 +280,8 @@
android:button="@null" android:button="@null"
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/page_anim_none" /> android:text="@string/page_anim_none"
app:isBottomBackground="true" />
</RadioGroup> </RadioGroup>

@ -195,6 +195,10 @@
</attr> </attr>
</declare-styleable> </declare-styleable>
<declare-styleable name="ATERadioNoButton">
<attr name="isBottomBackground" />
</declare-styleable>
<declare-styleable name="Preference"> <declare-styleable name="Preference">
<attr name="isBottomBackground" /> <attr name="isBottomBackground" />
</declare-styleable> </declare-styleable>

Loading…
Cancel
Save