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.WindowManager
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 io.legado.app.R
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.getPrimaryTextColor
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.setIconColor
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
@ -37,21 +32,8 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
final override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return menu?.let {
if (it is MenuBuilder) {
it.setOptionalIconsVisible(true)
}
val bool = onCompatCreateOptionsMenu(it)
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(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
)
}
}
it.setIconColor(this)
bool
} ?: super.onCreateOptionsMenu(menu)
}

@ -6,8 +6,9 @@ import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R
import io.legado.app.utils.initIconColor
import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.view_titlebar.*
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)
Log.e("TAG", "BookshelfFragment")
toolbar.inflateMenu(R.menu.bookshelf)
toolbar.menu.initIconColor
toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this)
}

@ -6,8 +6,9 @@ import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R
import io.legado.app.utils.initIconColor
import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.view_titlebar.*
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)
Log.e("TAG", "BookSourceFragment")
toolbar.inflateMenu(R.menu.book_source)
toolbar.menu.initIconColor
toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this)
}

@ -6,8 +6,9 @@ import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import io.legado.app.App
import io.legado.app.R
import io.legado.app.utils.initIconColor
import io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.view_titlebar.*
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)
Log.e("TAG", "FindBookFragment")
toolbar.inflateMenu(R.menu.find_book)
toolbar.menu.initIconColor
toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this)
}

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

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

Loading…
Cancel
Save