pull/32/head
GKF 6 years ago
parent 90c98f2012
commit d64a7cafb8
  1. 22
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 5
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt
  4. 5
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt
  5. 5
      app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt
  6. 10
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt

@ -7,16 +7,11 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.view.forEach
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.utils.setIconColor
import io.legado.app.utils.getCompatColor
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
@ -37,21 +32,8 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
final override fun onCreateOptionsMenu(menu: Menu?): Boolean { final override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return menu?.let { return menu?.let {
if (it is MenuBuilder) {
it.setOptionalIconsVisible(true)
}
val bool = onCompatCreateOptionsMenu(it) val bool = onCompatCreateOptionsMenu(it)
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) it.setIconColor(this)
val defaultTextColor = getCompatColor(R.color.tv_text_default)
menu.forEach { item ->
(item as MenuItemImpl).let { impl ->
//overflow:展开的item
DrawableUtils.setTint(
impl.icon,
if (impl.requiresOverflow()) defaultTextColor else primaryTextColor
)
}
}
bool bool
} ?: super.onCreateOptionsMenu(menu) } ?: super.onCreateOptionsMenu(menu)
} }

@ -6,8 +6,9 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.initIconColor import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.view_titlebar.* import kotlinx.android.synthetic.main.view_titlebar.*
class BookshelfFragment : Fragment(R.layout.fragment_bookshelf), Toolbar.OnMenuItemClickListener { class BookshelfFragment : Fragment(R.layout.fragment_bookshelf), Toolbar.OnMenuItemClickListener {
@ -16,7 +17,7 @@ class BookshelfFragment : Fragment(R.layout.fragment_bookshelf), Toolbar.OnMenuI
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "BookshelfFragment") Log.e("TAG", "BookshelfFragment")
toolbar.inflateMenu(R.menu.bookshelf) toolbar.inflateMenu(R.menu.bookshelf)
toolbar.menu.initIconColor toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this) toolbar.setOnMenuItemClickListener(this)
} }

@ -6,8 +6,9 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.initIconColor import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.view_titlebar.* import kotlinx.android.synthetic.main.view_titlebar.*
class BookSourceFragment : Fragment(R.layout.fragment_book_source), Toolbar.OnMenuItemClickListener { class BookSourceFragment : Fragment(R.layout.fragment_book_source), Toolbar.OnMenuItemClickListener {
@ -16,7 +17,7 @@ class BookSourceFragment : Fragment(R.layout.fragment_book_source), Toolbar.OnMe
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "BookSourceFragment") Log.e("TAG", "BookSourceFragment")
toolbar.inflateMenu(R.menu.book_source) toolbar.inflateMenu(R.menu.book_source)
toolbar.menu.initIconColor toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this) toolbar.setOnMenuItemClickListener(this)
} }

@ -6,8 +6,9 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.initIconColor import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.view_titlebar.* import kotlinx.android.synthetic.main.view_titlebar.*
class FindBookFragment : Fragment(R.layout.fragment_find_book), Toolbar.OnMenuItemClickListener { class FindBookFragment : Fragment(R.layout.fragment_find_book), Toolbar.OnMenuItemClickListener {
@ -16,7 +17,7 @@ class FindBookFragment : Fragment(R.layout.fragment_find_book), Toolbar.OnMenuIt
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "FindBookFragment") Log.e("TAG", "FindBookFragment")
toolbar.inflateMenu(R.menu.find_book) toolbar.inflateMenu(R.menu.find_book)
toolbar.menu.initIconColor toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this) toolbar.setOnMenuItemClickListener(this)
} }

@ -7,10 +7,11 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigActivity
import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.config.ConfigViewModel
import io.legado.app.utils.initIconColor import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.fragment_my_config.* import kotlinx.android.synthetic.main.fragment_my_config.*
import kotlinx.android.synthetic.main.view_titlebar.* import kotlinx.android.synthetic.main.view_titlebar.*
@ -20,7 +21,7 @@ class MyConfigFragment : Fragment(R.layout.fragment_my_config), Toolbar.OnMenuIt
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "MyConfigFragment") Log.e("TAG", "MyConfigFragment")
toolbar.inflateMenu(R.menu.my_config) toolbar.inflateMenu(R.menu.my_config)
toolbar.menu.initIconColor toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this) toolbar.setOnMenuItemClickListener(this)
tv_theme_config.setOnClickListener(View.OnClickListener { tv_theme_config.setOnClickListener(View.OnClickListener {
val intent = Intent(context, ConfigActivity::class.java) val intent = Intent(context, ConfigActivity::class.java)

@ -1,24 +1,22 @@
package io.legado.app.utils package io.legado.app.utils
import android.content.Context
import android.view.Menu import android.view.Menu
import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.view.forEach import androidx.core.view.forEach
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
val Menu.initIconColor: Menu fun Menu.setIconColor(context: Context): Menu = this.let { menu ->
get() = this.let { menu ->
if (menu is MenuBuilder) { if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true) menu.setOptionalIconsVisible(true)
} }
val primaryTextColor = val primaryTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(context)))
App.INSTANCE.getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(App.INSTANCE))) val defaultTextColor = context.getCompatColor(R.color.tv_text_default)
val defaultTextColor = App.INSTANCE.getCompatColor(R.color.tv_text_default)
menu.forEach { item -> menu.forEach { item ->
(item as MenuItemImpl).let { impl -> (item as MenuItemImpl).let { impl ->
//overflow:展开的item //overflow:展开的item

Loading…
Cancel
Save