From 15cec309c26418800f41fd675eb6bd10423d0495 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Sep 2019 20:36:23 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/lib/theme/ATH.kt | 4 +- .../app/lib/theme/MaterialValueHelper.kt | 41 ++----------------- .../app/ui/main/explore/ExploreFragment.kt | 25 ++++++++++- app/src/main/res/drawable/ic_screen.xml | 11 +++++ app/src/main/res/menu/find_book.xml | 11 ----- app/src/main/res/values/strings.xml | 1 + 6 files changed, 42 insertions(+), 51 deletions(-) create mode 100644 app/src/main/res/drawable/ic_screen.xml delete mode 100644 app/src/main/res/menu/find_book.xml 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 ba1b0dc8e..19542ffc4 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 @@ -130,8 +130,8 @@ object ATH { fun setTint( view: View, - @ColorInt color: Int, isDark: - Boolean = view.context.isNightTheme + @ColorInt color: Int, + isDark: Boolean = view.context.isNightTheme ) { TintHelper.setTintAuto(view, color, false, isDark) } diff --git a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt index e611ac728..1618884b5 100644 --- a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt @@ -42,39 +42,6 @@ fun Context.getSecondaryDisabledTextColor(dark: Boolean): Int { } else ContextCompat.getColor(this, R.color.secondary_text_disabled_material_dark) } - -@SuppressLint("PrivateResource") -@ColorInt -fun Fragment.getPrimaryTextColor(dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(requireContext(), R.color.primary_text_default_material_light) - } else ContextCompat.getColor(requireContext(), R.color.primary_text_default_material_dark) -} - -@SuppressLint("PrivateResource") -@ColorInt -fun Fragment.getSecondaryTextColor(dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(requireContext(), R.color.secondary_text_default_material_light) - } else ContextCompat.getColor(requireContext(), R.color.secondary_text_default_material_dark) -} - -@SuppressLint("PrivateResource") -@ColorInt -fun Fragment.getPrimaryDisabledTextColor(dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(requireContext(), R.color.primary_text_disabled_material_light) - } else ContextCompat.getColor(requireContext(), R.color.primary_text_disabled_material_dark) -} - -@SuppressLint("PrivateResource") -@ColorInt -fun Fragment.getSecondaryDisabledTextColor(dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_light) - } else ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_dark) -} - val Context.primaryColor: Int get() = ThemeStore.primaryColor(this) @@ -112,16 +79,16 @@ val Fragment.backgroundColor: Int get() = ThemeStore.backgroundColor(requireContext()) val Fragment.primaryTextColor: Int - get() = getPrimaryTextColor(isDarkTheme) + get() = requireContext().getPrimaryTextColor(isDarkTheme) val Fragment.secondaryTextColor: Int - get() = getSecondaryTextColor(isDarkTheme) + get() = requireContext().getSecondaryTextColor(isDarkTheme) val Fragment.primaryDisabledTextColor: Int - get() = getPrimaryDisabledTextColor(isDarkTheme) + get() = requireContext().getPrimaryDisabledTextColor(isDarkTheme) val Fragment.secondaryDisabledTextColor: Int - get() = getSecondaryDisabledTextColor(isDarkTheme) + get() = requireContext().getSecondaryDisabledTextColor(isDarkTheme) val Context.buttonDisabledColor: Int get() = if (isDarkTheme) { 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 888dbe4ac..503cdc37a 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 @@ -3,6 +3,8 @@ package io.legado.app.ui.main.explore import android.os.Bundle import android.view.Menu import android.view.View +import androidx.appcompat.widget.AppCompatImageView +import androidx.appcompat.widget.SearchView import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App @@ -10,13 +12,16 @@ import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.BookSource import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.book.source.edit.SourceEditActivity import io.legado.app.ui.explore.ExploreShowActivity +import io.legado.app.utils.getCompatDrawable import io.legado.app.utils.getViewModel import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_find_book.* import kotlinx.android.synthetic.main.view_title_bar.* + class ExploreFragment : VMBaseFragment(R.layout.fragment_find_book), ExploreAdapter.CallBack { override val viewModel: ExploreViewModel @@ -24,6 +29,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ private lateinit var adapter: ExploreAdapter private lateinit var linearLayoutManager: LinearLayoutManager + private var searchView: SearchView? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -32,7 +38,24 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ } override fun onCompatCreateOptionsMenu(menu: Menu) { - menuInflater.inflate(R.menu.find_book, menu) + menuInflater.inflate(R.menu.search_view, menu) + val search = menu.findItem(R.id.menu_search) + searchView = search.actionView as SearchView + val bottom = + searchView?.findViewById(androidx.appcompat.R.id.search_button) as? AppCompatImageView + bottom?.setImageDrawable(getCompatDrawable(R.drawable.ic_screen)) + ATH.setTint(searchView!!, primaryTextColor) + searchView?.maxWidth = resources.displayMetrics.widthPixels + searchView?.onActionViewCollapsed() + searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String): Boolean { + return false + } + + override fun onQueryTextChange(newText: String): Boolean { + return false + } + }) } private fun initRecyclerView() { diff --git a/app/src/main/res/drawable/ic_screen.xml b/app/src/main/res/drawable/ic_screen.xml new file mode 100644 index 000000000..4a641e517 --- /dev/null +++ b/app/src/main/res/drawable/ic_screen.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/find_book.xml b/app/src/main/res/menu/find_book.xml deleted file mode 100644 index 72f4f570a..000000000 --- a/app/src/main/res/menu/find_book.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1d20b0eec..3cda2ca88 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -505,5 +505,6 @@ 输入你的服务器地址 输入你的WebDav账号 订阅源 + 筛选