pull/32/head
Administrator 5 years ago
parent 5fc1808f29
commit 9768c0eed3
  1. 2
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 4
      app/src/main/java/io/legado/app/base/BaseFragment.kt
  3. 2
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  4. 8
      app/src/main/java/io/legado/app/lib/theme/TintHelper.kt
  5. 2
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  6. 3
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt
  7. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  8. 2
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  9. 19
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  10. 2
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt

@ -41,7 +41,7 @@ abstract class BaseActivity(private val layoutID: Int, private val fullScreen: B
final override fun onCreateOptionsMenu(menu: Menu?): Boolean { final override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return menu?.let { return menu?.let {
val bool = onCompatCreateOptionsMenu(it) val bool = onCompatCreateOptionsMenu(it)
it.setIconColor(this) it.applyTint(this)
bool bool
} ?: super.onCreateOptionsMenu(menu) } ?: super.onCreateOptionsMenu(menu)
} }

@ -6,7 +6,7 @@ import android.view.MenuItem
import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.utils.setIconColor import io.legado.app.utils.applyTint
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
@ -31,7 +31,7 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID),
supportToolbar?.let { supportToolbar?.let {
it.menu.apply { it.menu.apply {
onCompatCreateOptionsMenu(this) onCompatCreateOptionsMenu(this)
setIconColor(requireContext()) applyTint(requireContext())
} }
it.setOnMenuItemClickListener { item -> it.setOnMenuItemClickListener { item ->

@ -178,7 +178,7 @@ object ATH {
} }
} }
fun applyTint(view: View?) { fun applyAccentTint(view: View?) {
view?.apply { view?.apply {
setTint(this, context.accentColor) setTint(this, context.accentColor)
} }

@ -147,7 +147,13 @@ object TintHelper {
is SwitchCompat -> setTint(view, color, isDark) is SwitchCompat -> setTint(view, color, isDark)
is SearchView -> { is SearchView -> {
val iconIdS = val iconIdS =
intArrayOf(androidx.appcompat.R.id.search_button, androidx.appcompat.R.id.search_close_btn) intArrayOf(
androidx.appcompat.R.id.search_button,
androidx.appcompat.R.id.search_close_btn,
androidx.appcompat.R.id.search_go_btn,
androidx.appcompat.R.id.search_voice_btn,
androidx.appcompat.R.id.search_mag_icon
)
for (iconId in iconIdS) { for (iconId in iconIdS) {
val icon = view.findViewById<ImageView>(iconId) val icon = view.findViewById<ImageView>(iconId)
if (icon != null) { if (icon != null) {

@ -19,6 +19,7 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.ui.sourceedit.SourceEditActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
@ -94,6 +95,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(search_view, primaryTextColor)
search_view.onActionViewExpanded() search_view.onActionViewExpanded()
search_view.queryHint = getString(R.string.search_book_source) search_view.queryHint = getString(R.string.search_book_source)
search_view.clearFocus() search_view.clearFocus()

@ -9,6 +9,8 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.activity_chapter_list.* import kotlinx.android.synthetic.main.activity_chapter_list.*
@ -30,6 +32,7 @@ class ChapterListActivity : BaseActivity(R.layout.activity_chapter_list) {
menuInflater.inflate(R.menu.search_view, menu) menuInflater.inflate(R.menu.search_view, menu)
val search = menu.findItem(R.id.action_search) val search = menu.findItem(R.id.action_search)
searchView = search.actionView as SearchView searchView = search.actionView as SearchView
ATH.setTint(searchView!!, primaryTextColor)
searchView?.maxWidth = resources.displayMetrics.widthPixels searchView?.maxWidth = resources.displayMetrics.widthPixels
searchView?.onActionViewCollapsed() searchView?.onActionViewCollapsed()
searchView?.setOnCloseListener { searchView?.setOnCloseListener {

@ -29,7 +29,6 @@ import io.legado.app.ui.search.SearchActivity
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_edittext.view.* import kotlinx.android.synthetic.main.dialog_edittext.view.*
import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColor import org.jetbrains.anko.textColor
@ -135,7 +134,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
customView { customView {
layoutInflater.inflate(R.layout.dialog_edittext, null).apply { layoutInflater.inflate(R.layout.dialog_edittext, null).apply {
editText = edit_view.apply { editText = edit_view.apply {
ATH.applyTint(this) ATH.applyAccentTint(this)
hint = "分组名称" hint = "分组名称"
} }
} }

@ -13,6 +13,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.SearchShow import io.legado.app.data.entities.SearchShow
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_search.* import kotlinx.android.synthetic.main.activity_search.*
import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_search.*
@ -32,6 +33,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
} }
private fun initSearchView() { private fun initSearchView() {
ATH.setTint(search_view, primaryTextColor)
search_view.onActionViewExpanded() search_view.onActionViewExpanded()
search_view.isSubmitButtonEnabled = true search_view.isSubmitButtonEnabled = true
search_view.queryHint = getString(R.string.search_book_key) search_view.queryHint = getString(R.string.search_book_key)

@ -145,11 +145,8 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
if (attachToActivity) {
attachToActivity() attachToActivity()
} }
wrapTheme()
}
fun setNavigationOnClickListener(clickListener: ((View) -> Unit)) { fun setNavigationOnClickListener(clickListener: ((View) -> Unit)) {
toolbar.setNavigationOnClickListener(clickListener) toolbar.setNavigationOnClickListener(clickListener)
@ -179,7 +176,14 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
toolbar.setSubtitleTextAppearance(context, resId) toolbar.setSubtitleTextAppearance(context, resId)
} }
private fun wrapTheme() { private fun attachToActivity() {
if(attachToActivity) {
activity?.let {
it.setSupportActionBar(toolbar)
it.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUp)
}
}
val primaryTextColor = if (isInEditMode) Color.BLACK else context.primaryTextColor val primaryTextColor = if (isInEditMode) Color.BLACK else context.primaryTextColor
DrawableUtils.setTint(toolbar.overflowIcon, primaryTextColor) DrawableUtils.setTint(toolbar.overflowIcon, primaryTextColor)
toolbar.setTitleTextColor(primaryTextColor) toolbar.setTitleTextColor(primaryTextColor)
@ -191,13 +195,6 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
} }
} }
private fun attachToActivity() {
activity?.let {
it.setSupportActionBar(toolbar)
it.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUp)
}
}
private fun wrapDrawableTint(drawable: Drawable?, tintList: ColorStateList?, tintMode: Int) { private fun wrapDrawableTint(drawable: Drawable?, tintList: ColorStateList?, tintMode: Int) {
if (drawable == null || tintList == null) return if (drawable == null || tintList == null) return
val wrappedDrawable = DrawableCompat.wrap(drawable.mutate()) val wrappedDrawable = DrawableCompat.wrap(drawable.mutate())

@ -10,7 +10,7 @@ import io.legado.app.lib.theme.DrawableUtils
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
fun Menu.setIconColor(context: Context): Menu = this.let { menu -> fun Menu.applyTint(context: Context): Menu = this.let { menu ->
if (menu is MenuBuilder) { if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true) menu.setOptionalIconsVisible(true)
} }

Loading…
Cancel
Save