From 0500061d28b51ae7e97cddb1055db9272d899f54 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 3 Oct 2021 17:04:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/lib/theme/ATH.kt | 14 ------ .../legado/app/lib/theme/view/ATECheckBox.kt | 4 +- .../app/lib/theme/view/ATEProgressBar.kt | 6 +-- .../app/lib/theme/view/ATERadioButton.kt | 4 +- .../legado/app/lib/theme/view/ATESeekBar.kt | 4 +- .../io/legado/app/lib/theme/view/ATESwitch.kt | 4 +- .../app/ui/book/search/SearchActivity.kt | 2 +- .../searchContent/SearchContentActivity.kt | 4 +- .../book/source/manage/BookSourceActivity.kt | 2 +- .../io/legado/app/ui/book/toc/TocActivity.kt | 43 ++++++++++--------- .../app/ui/config/BackupConfigFragment.kt | 6 +-- .../app/ui/main/explore/ExploreFragment.kt | 3 +- .../io/legado/app/ui/main/rss/RssFragment.kt | 7 +-- .../app/ui/replace/ReplaceRuleActivity.kt | 2 +- .../ui/rss/source/manage/RssSourceActivity.kt | 2 +- .../app/ui/widget/prefs/SwitchPreference.kt | 4 +- .../app/ui/widget/seekbar/VerticalSeekBar.kt | 6 +-- .../ui/widget/text/AutoCompleteTextView.kt | 5 ++- .../io/legado/app/ui/widget/text/EditText.kt | 6 +-- .../io/legado/app/utils/ViewExtensions.kt | 17 ++++++++ 20 files changed, 74 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index 6b0873258..279bb9b59 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -19,14 +19,6 @@ import splitties.init.appCtx @Suppress("unused", "MemberVisibilityCanBePrivate") object ATH { - fun setTint( - view: View, - @ColorInt color: Int, - isDark: Boolean = AppConfig.isNightTheme(view.context) - ) { - TintHelper.setTintAuto(view, color, false, isDark) - } - fun setBackgroundTint( view: View, @ColorInt color: Int, isDark: Boolean = AppConfig.isNightTheme @@ -86,12 +78,6 @@ object ATH { } } - fun applyAccentTint(view: View?) { - view?.apply { - setTint(this, context.accentColor) - } - } - fun applyBackgroundTint(view: View?) { view?.apply { if (background == null) { diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt index daa41d6cd..344bfd0a6 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt @@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.AppCompatCheckBox -import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint /** * @author Aidan Follestad (afollestad) @@ -13,7 +13,7 @@ class ATECheckBox(context: Context, attrs: AttributeSet) : AppCompatCheckBox(con init { if (!isInEditMode) { - ATH.setTint(this, context.accentColor) + applyTint(context.accentColor) } } } diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt index 090c66f80..db2f8adbe 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt @@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view import android.content.Context import android.util.AttributeSet import android.widget.ProgressBar -import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore +import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint /** * @author Aidan Follestad (afollestad) @@ -13,7 +13,7 @@ class ATEProgressBar(context: Context, attrs: AttributeSet) : ProgressBar(contex init { if (!isInEditMode) { - ATH.setTint(this, ThemeStore.accentColor(context)) + applyTint(context.accentColor) } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt index 8654e1554..ff563e63f 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt @@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.AppCompatRadioButton -import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint /** * @author Aidan Follestad (afollestad) @@ -13,7 +13,7 @@ class ATERadioButton(context: Context, attrs: AttributeSet) : AppCompatRadioButt init { if (!isInEditMode) { - ATH.setTint(this@ATERadioButton, context.accentColor) + applyTint(context.accentColor) } } } diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt index 3b8f046aa..5feb38f0f 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt @@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.AppCompatSeekBar -import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint /** * @author Aidan Follestad (afollestad) @@ -13,7 +13,7 @@ class ATESeekBar(context: Context, attrs: AttributeSet) : AppCompatSeekBar(conte init { if (!isInEditMode) { - ATH.setTint(this, context.accentColor) + applyTint(context.accentColor) } } } diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt index f121c35b0..488d2bb33 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt @@ -3,8 +3,8 @@ package io.legado.app.lib.theme.view import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.SwitchCompat -import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint /** * @author Aidan Follestad (afollestad) @@ -13,7 +13,7 @@ class ATESwitch(context: Context, attrs: AttributeSet) : SwitchCompat(context, a init { if (!isInEditMode) { - ATH.setTint(this, context.accentColor) + applyTint(context.accentColor) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 04da90cc4..42db894d8 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -107,7 +107,7 @@ class SearchActivity : VMBaseActivity() { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.book_toc, menu) val search = menu.findItem(R.id.menu_search) - searchView = search.actionView as SearchView - ATH.setTint(searchView!!, primaryTextColor) - searchView?.maxWidth = resources.displayMetrics.widthPixels - searchView?.onActionViewCollapsed() - searchView?.setOnCloseListener { - tabLayout.visible() - false - } - searchView?.setOnSearchClickListener { tabLayout.gone() } - searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(query: String): Boolean { - return false + searchView = (search.actionView as SearchView).apply { + applyTint(primaryTextColor) + maxWidth = resources.displayMetrics.widthPixels + onActionViewCollapsed() + setOnCloseListener { + tabLayout.visible() + false } + setOnSearchClickListener { tabLayout.gone() } + setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String): Boolean { + return false + } - override fun onQueryTextChange(newText: String): Boolean { - if (tabLayout.selectedTabPosition == 1) { - viewModel.startBookmarkSearch(newText) - } else { - viewModel.startChapterListSearch(newText) + override fun onQueryTextChange(newText: String): Boolean { + if (tabLayout.selectedTabPosition == 1) { + viewModel.startBookmarkSearch(newText) + } else { + viewModel.startChapterListSearch(newText) + } + return false } - return false - } - }) + }) + } return super.onCompatCreateOptionsMenu(menu) } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 25f76d6b8..84fb72258 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -96,18 +96,18 @@ class BackupConfigFragment : BasePreferenceFragment(), addPreferencesFromResource(R.xml.pref_config_backup) findPreference(PreferKey.webDavUrl)?.let { it.setOnBindEditTextListener { editText -> - ATH.setTint(editText, requireContext().accentColor) + editText.applyTint(requireContext().accentColor) } } findPreference(PreferKey.webDavAccount)?.let { it.setOnBindEditTextListener { editText -> - ATH.setTint(editText, requireContext().accentColor) + editText.applyTint(requireContext().accentColor) } } findPreference(PreferKey.webDavPassword)?.let { it.setOnBindEditTextListener { editText -> - ATH.setTint(editText, requireContext().accentColor) + editText.applyTint(requireContext().accentColor) editText.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 05da34d6f..144efd8d0 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -23,6 +23,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.book.explore.ExploreShowActivity 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.splitNotBlank import io.legado.app.utils.startActivity @@ -68,7 +69,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo } private fun initSearchView() { - ATH.setTint(searchView, primaryTextColor) + searchView.applyTint(primaryTextColor) searchView.onActionViewExpanded() searchView.isSubmitButtonEnabled = true searchView.queryHint = getString(R.string.screen_find) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 1b3d6fbf4..f4150041a 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -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.RssSourceViewModel import io.legado.app.ui.rss.subscription.RuleSubActivity -import io.legado.app.utils.cnCompare -import io.legado.app.utils.openUrl -import io.legado.app.utils.splitNotBlank -import io.legado.app.utils.startActivity +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect @@ -88,7 +85,7 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), } private fun initSearchView() { - ATH.setTint(searchView, primaryTextColor) + searchView.applyTint(primaryTextColor) searchView.onActionViewExpanded() searchView.isSubmitButtonEnabled = true searchView.queryHint = getString(R.string.rss) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 356600c98..bd5a45c96 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -138,7 +138,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.id.search_view).let { - ATH.setTint(it, primaryTextColor) + it.applyTint(primaryTextColor) it.onActionViewExpanded() it.queryHint = getString(R.string.search_rss_source) it.clearFocus() diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt index 3ff87e05b..2cb47346b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt @@ -6,8 +6,8 @@ import androidx.appcompat.widget.SwitchCompat import androidx.preference.PreferenceViewHolder import androidx.preference.SwitchPreferenceCompat 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 class SwitchPreference(context: Context, attrs: AttributeSet) : SwitchPreferenceCompat(context, attrs) { @@ -33,7 +33,7 @@ class SwitchPreference(context: Context, attrs: AttributeSet) : isBottomBackground = isBottomBackground ) if (v is SwitchCompat && !v.isInEditMode) { - ATH.setTint(v, context.accentColor) + v.applyTint(context.accentColor) } super.onBindViewHolder(holder) } diff --git a/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt index 736b9eb3a..b6761a7a0 100644 --- a/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt @@ -11,8 +11,8 @@ import android.widget.ProgressBar import androidx.appcompat.widget.AppCompatSeekBar import androidx.core.view.ViewCompat import io.legado.app.R -import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore +import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method @@ -56,7 +56,7 @@ class VerticalSeekBar @JvmOverloads constructor(context: Context, attrs: Attribu } init { - ATH.setTint(this, ThemeStore.accentColor(context)) + applyTint(context.accentColor) ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR) if (attrs != null) { diff --git a/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt index fbf4ac26c..f42cda253 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt @@ -12,7 +12,8 @@ import android.widget.ImageView import android.widget.TextView import androidx.appcompat.widget.AppCompatAutoCompleteTextView 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.visible @@ -26,7 +27,7 @@ class AutoCompleteTextView @JvmOverloads constructor( var delCallBack: ((value: String) -> Unit)? = null init { - ATH.applyAccentTint(this) + applyTint(context.accentColor) } override fun enoughToFilter(): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/widget/text/EditText.kt b/app/src/main/java/io/legado/app/ui/widget/text/EditText.kt index ad1b979ff..c1d0676bb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/EditText.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/EditText.kt @@ -3,8 +3,8 @@ package io.legado.app.ui.widget.text import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.AppCompatEditText -import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore +import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint /** * @author Aidan Follestad (afollestad) @@ -13,7 +13,7 @@ class EditText(context: Context, attrs: AttributeSet) : AppCompatEditText(contex init { if (!isInEditMode) { - ATH.setTint(this, ThemeStore.accentColor(context)) + applyTint(context.accentColor) } } } diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 8c2660242..d0c9af3f5 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -12,10 +12,13 @@ import android.view.inputmethod.InputMethodManager import android.widget.RadioGroup import android.widget.SeekBar import android.widget.TextView +import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.menu.MenuPopupHelper import androidx.appcompat.widget.PopupMenu import androidx.core.view.get +import io.legado.app.help.AppConfig +import io.legado.app.lib.theme.TintHelper import splitties.init.appCtx 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() { if (visibility != GONE) { visibility = GONE