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. 21
      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 {
return menu?.let {
val bool = onCompatCreateOptionsMenu(it)
it.setIconColor(this)
it.applyTint(this)
bool
} ?: super.onCreateOptionsMenu(menu)
}

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

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

@ -147,7 +147,13 @@ object TintHelper {
is SwitchCompat -> setTint(view, color, isDark)
is SearchView -> {
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) {
val icon = view.findViewById<ImageView>(iconId)
if (icon != null) {

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

@ -9,6 +9,8 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import io.legado.app.R
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.visible
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)
val search = menu.findItem(R.id.action_search)
searchView = search.actionView as SearchView
ATH.setTint(searchView!!, primaryTextColor)
searchView?.maxWidth = resources.displayMetrics.widthPixels
searchView?.onActionViewCollapsed()
searchView?.setOnCloseListener {

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

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

@ -145,10 +145,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (attachToActivity) {
attachToActivity()
}
wrapTheme()
attachToActivity()
}
fun setNavigationOnClickListener(clickListener: ((View) -> Unit)) {
@ -179,7 +176,14 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
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
DrawableUtils.setTint(toolbar.overflowIcon, 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) {
if (drawable == null || tintList == null) return
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.primaryTextColor
fun Menu.setIconColor(context: Context): Menu = this.let { menu ->
fun Menu.applyTint(context: Context): Menu = this.let { menu ->
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}

Loading…
Cancel
Save