pull/1395/head
gedoor 3 years ago
parent 33a7b83b27
commit 0500061d28
  1. 14
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  2. 4
      app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt
  3. 6
      app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt
  4. 4
      app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt
  5. 4
      app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt
  6. 4
      app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  10. 17
      app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
  11. 6
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  12. 3
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  13. 7
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  14. 2
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  15. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  16. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt
  17. 6
      app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt
  18. 5
      app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt
  19. 6
      app/src/main/java/io/legado/app/ui/widget/text/EditText.kt
  20. 17
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt

@ -19,14 +19,6 @@ import splitties.init.appCtx
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
object ATH { object ATH {
fun setTint(
view: View,
@ColorInt color: Int,
isDark: Boolean = AppConfig.isNightTheme(view.context)
) {
TintHelper.setTintAuto(view, color, false, isDark)
}
fun setBackgroundTint( fun setBackgroundTint(
view: View, @ColorInt color: Int, view: View, @ColorInt color: Int,
isDark: Boolean = AppConfig.isNightTheme isDark: Boolean = AppConfig.isNightTheme
@ -86,12 +78,6 @@ object ATH {
} }
} }
fun applyAccentTint(view: View?) {
view?.apply {
setTint(this, context.accentColor)
}
}
fun applyBackgroundTint(view: View?) { fun applyBackgroundTint(view: View?) {
view?.apply { view?.apply {
if (background == null) { if (background == null) {

@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatCheckBox import androidx.appcompat.widget.AppCompatCheckBox
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
@ -13,7 +13,7 @@ class ATECheckBox(context: Context, attrs: AttributeSet) : AppCompatCheckBox(con
init { init {
if (!isInEditMode) { if (!isInEditMode) {
ATH.setTint(this, context.accentColor) applyTint(context.accentColor)
} }
} }
} }

@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.ProgressBar import android.widget.ProgressBar
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.applyTint
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
@ -13,7 +13,7 @@ class ATEProgressBar(context: Context, attrs: AttributeSet) : ProgressBar(contex
init { init {
if (!isInEditMode) { if (!isInEditMode) {
ATH.setTint(this, ThemeStore.accentColor(context)) applyTint(context.accentColor)
} }
} }
} }

@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatRadioButton import androidx.appcompat.widget.AppCompatRadioButton
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
@ -13,7 +13,7 @@ class ATERadioButton(context: Context, attrs: AttributeSet) : AppCompatRadioButt
init { init {
if (!isInEditMode) { if (!isInEditMode) {
ATH.setTint(this@ATERadioButton, context.accentColor) applyTint(context.accentColor)
} }
} }
} }

@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatSeekBar import androidx.appcompat.widget.AppCompatSeekBar
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
@ -13,7 +13,7 @@ class ATESeekBar(context: Context, attrs: AttributeSet) : AppCompatSeekBar(conte
init { init {
if (!isInEditMode) { if (!isInEditMode) {
ATH.setTint(this, context.accentColor) applyTint(context.accentColor)
} }
} }
} }

@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.SwitchCompat
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
@ -13,7 +13,7 @@ class ATESwitch(context: Context, attrs: AttributeSet) : SwitchCompat(context, a
init { init {
if (!isInEditMode) { if (!isInEditMode) {
ATH.setTint(this, context.accentColor) applyTint(context.accentColor)
} }
} }

@ -107,7 +107,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(searchView, primaryTextColor) searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.isSubmitButtonEnabled = true searchView.isSubmitButtonEnabled = true
searchView.queryHint = getString(R.string.search_book_key) searchView.queryHint = getString(R.string.search_book_key)

@ -15,13 +15,13 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ActivitySearchContentBinding import io.legado.app.databinding.ActivitySearchContentBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.lib.theme.ATH
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.getPrimaryTextColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.applyTint
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -62,7 +62,7 @@ class SearchContentActivity :
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(searchView, primaryTextColor) searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.isSubmitButtonEnabled = true searchView.isSubmitButtonEnabled = true
searchView.queryHint = getString(R.string.search) searchView.queryHint = getString(R.string.search)

@ -198,7 +198,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(searchView, primaryTextColor) searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.queryHint = getString(R.string.search_book_source) searchView.queryHint = getString(R.string.search_book_source)
searchView.clearFocus() searchView.clearFocus()

@ -15,9 +15,9 @@ import com.google.android.material.tabs.TabLayout
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityChapterListBinding import io.legado.app.databinding.ActivityChapterListBinding
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.applyTint
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible import io.legado.app.utils.visible
@ -45,16 +45,16 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_toc, menu) menuInflater.inflate(R.menu.book_toc, menu)
val search = menu.findItem(R.id.menu_search) val search = menu.findItem(R.id.menu_search)
searchView = search.actionView as SearchView searchView = (search.actionView as SearchView).apply {
ATH.setTint(searchView!!, primaryTextColor) applyTint(primaryTextColor)
searchView?.maxWidth = resources.displayMetrics.widthPixels maxWidth = resources.displayMetrics.widthPixels
searchView?.onActionViewCollapsed() onActionViewCollapsed()
searchView?.setOnCloseListener { setOnCloseListener {
tabLayout.visible() tabLayout.visible()
false false
} }
searchView?.setOnSearchClickListener { tabLayout.gone() } setOnSearchClickListener { tabLayout.gone() }
searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean { override fun onQueryTextSubmit(query: String): Boolean {
return false return false
} }
@ -68,6 +68,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
return false return false
} }
}) })
}
return super.onCompatCreateOptionsMenu(menu) return super.onCompatCreateOptionsMenu(menu)
} }

@ -96,18 +96,18 @@ class BackupConfigFragment : BasePreferenceFragment(),
addPreferencesFromResource(R.xml.pref_config_backup) addPreferencesFromResource(R.xml.pref_config_backup)
findPreference<EditTextPreference>(PreferKey.webDavUrl)?.let { findPreference<EditTextPreference>(PreferKey.webDavUrl)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) editText.applyTint(requireContext().accentColor)
} }
} }
findPreference<EditTextPreference>(PreferKey.webDavAccount)?.let { findPreference<EditTextPreference>(PreferKey.webDavAccount)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) editText.applyTint(requireContext().accentColor)
} }
} }
findPreference<EditTextPreference>(PreferKey.webDavPassword)?.let { findPreference<EditTextPreference>(PreferKey.webDavPassword)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) editText.applyTint(requireContext().accentColor)
editText.inputType = editText.inputType =
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
} }

@ -23,6 +23,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.explore.ExploreShowActivity import io.legado.app.ui.book.explore.ExploreShowActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.utils.applyTint
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
@ -68,7 +69,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(searchView, primaryTextColor) searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.isSubmitButtonEnabled = true searchView.isSubmitButtonEnabled = true
searchView.queryHint = getString(R.string.screen_find) searchView.queryHint = getString(R.string.screen_find)

@ -23,10 +23,7 @@ import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.ui.rss.source.manage.RssSourceActivity import io.legado.app.ui.rss.source.manage.RssSourceActivity
import io.legado.app.ui.rss.source.manage.RssSourceViewModel import io.legado.app.ui.rss.source.manage.RssSourceViewModel
import io.legado.app.ui.rss.subscription.RuleSubActivity import io.legado.app.ui.rss.subscription.RuleSubActivity
import io.legado.app.utils.cnCompare import io.legado.app.utils.*
import io.legado.app.utils.openUrl
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
@ -88,7 +85,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(searchView, primaryTextColor) searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.isSubmitButtonEnabled = true searchView.isSubmitButtonEnabled = true
searchView.queryHint = getString(R.string.rss) searchView.queryHint = getString(R.string.rss)

@ -138,7 +138,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(searchView, primaryTextColor) searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded() searchView.onActionViewExpanded()
searchView.queryHint = getString(R.string.replace_purify_search) searchView.queryHint = getString(R.string.replace_purify_search)
searchView.clearFocus() searchView.clearFocus()

@ -165,7 +165,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private fun initSearchView() { private fun initSearchView() {
binding.titleBar.findViewById<SearchView>(R.id.search_view).let { binding.titleBar.findViewById<SearchView>(R.id.search_view).let {
ATH.setTint(it, primaryTextColor) it.applyTint(primaryTextColor)
it.onActionViewExpanded() it.onActionViewExpanded()
it.queryHint = getString(R.string.search_rss_source) it.queryHint = getString(R.string.search_rss_source)
it.clearFocus() it.clearFocus()

@ -6,8 +6,8 @@ import androidx.appcompat.widget.SwitchCompat
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
class SwitchPreference(context: Context, attrs: AttributeSet) : class SwitchPreference(context: Context, attrs: AttributeSet) :
SwitchPreferenceCompat(context, attrs) { SwitchPreferenceCompat(context, attrs) {
@ -33,7 +33,7 @@ class SwitchPreference(context: Context, attrs: AttributeSet) :
isBottomBackground = isBottomBackground isBottomBackground = isBottomBackground
) )
if (v is SwitchCompat && !v.isInEditMode) { if (v is SwitchCompat && !v.isInEditMode) {
ATH.setTint(v, context.accentColor) v.applyTint(context.accentColor)
} }
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
} }

@ -11,8 +11,8 @@ import android.widget.ProgressBar
import androidx.appcompat.widget.AppCompatSeekBar import androidx.appcompat.widget.AppCompatSeekBar
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.applyTint
import java.lang.reflect.InvocationTargetException import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method import java.lang.reflect.Method
@ -56,7 +56,7 @@ class VerticalSeekBar @JvmOverloads constructor(context: Context, attrs: Attribu
} }
init { init {
ATH.setTint(this, ThemeStore.accentColor(context)) applyTint(context.accentColor)
ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR) ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR)
if (attrs != null) { if (attrs != null) {

@ -12,7 +12,8 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.widget.AppCompatAutoCompleteTextView import androidx.appcompat.widget.AppCompatAutoCompleteTextView
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
@ -26,7 +27,7 @@ class AutoCompleteTextView @JvmOverloads constructor(
var delCallBack: ((value: String) -> Unit)? = null var delCallBack: ((value: String) -> Unit)? = null
init { init {
ATH.applyAccentTint(this) applyTint(context.accentColor)
} }
override fun enoughToFilter(): Boolean { override fun enoughToFilter(): Boolean {

@ -3,8 +3,8 @@ package io.legado.app.ui.widget.text
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatEditText import androidx.appcompat.widget.AppCompatEditText
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.applyTint
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
@ -13,7 +13,7 @@ class EditText(context: Context, attrs: AttributeSet) : AppCompatEditText(contex
init { init {
if (!isInEditMode) { if (!isInEditMode) {
ATH.setTint(this, ThemeStore.accentColor(context)) applyTint(context.accentColor)
} }
} }
} }

@ -12,10 +12,13 @@ import android.view.inputmethod.InputMethodManager
import android.widget.RadioGroup import android.widget.RadioGroup
import android.widget.SeekBar import android.widget.SeekBar
import android.widget.TextView import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuPopupHelper import androidx.appcompat.view.menu.MenuPopupHelper
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.core.view.get import androidx.core.view.get
import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.TintHelper
import splitties.init.appCtx import splitties.init.appCtx
import java.lang.reflect.Field import java.lang.reflect.Field
@ -43,6 +46,20 @@ fun View.disableAutoFill() = run {
} }
} }
fun View.applyTint(
@ColorInt color: Int,
isDark: Boolean = AppConfig.isNightTheme(context)
) {
TintHelper.setTintAuto(this, color, false, isDark)
}
fun View.applyBackground(
@ColorInt color: Int,
isDark: Boolean = AppConfig.isNightTheme
) {
TintHelper.setTintAuto(this, color, true, isDark)
}
fun View.gone() { fun View.gone() {
if (visibility != GONE) { if (visibility != GONE) {
visibility = GONE visibility = GONE

Loading…
Cancel
Save