pull/60/head^2
kunfei 5 years ago
parent 0de6928a8f
commit 2b88267297
  1. 7
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 1
      app/src/main/java/io/legado/app/base/VMBaseActivity.kt
  3. 16
      app/src/main/java/io/legado/app/constant/Theme.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/info/GroupSelectDialog.kt
  6. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  7. 3
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt
  8. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt
  9. 3
      app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt
  10. 3
      app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt
  11. 3
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  12. 26
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt

@ -7,6 +7,7 @@ import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.primaryColor
@ -46,7 +47,7 @@ abstract class BaseActivity(
final override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return menu?.let {
val bool = onCompatCreateOptionsMenu(it)
it.applyTint(this)
it.applyTint(this, theme)
bool
} ?: super.onCreateOptionsMenu(menu)
}
@ -107,8 +108,4 @@ abstract class BaseActivity(
currentFocus?.hideSoftInput()
super.finish()
}
enum class Theme {
Dark, Light, Auto
}
}

@ -1,6 +1,7 @@
package io.legado.app.base
import androidx.lifecycle.ViewModel
import io.legado.app.constant.Theme
abstract class VMBaseActivity<VM : ViewModel>(
layoutID: Int,

@ -0,0 +1,16 @@
package io.legado.app.constant
import io.legado.app.App
import io.legado.app.utils.isNightTheme
enum class Theme {
Dark, Light, Auto;
companion object {
fun getTheme(): Theme {
return if (App.INSTANCE.isNightTheme) {
Dark
} else Light
}
}
}

@ -14,6 +14,7 @@ import com.bumptech.glide.request.RequestOptions.bitmapTransform
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.BookType
import io.legado.app.constant.Theme
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookGroup

@ -21,6 +21,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.Theme
import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.alert
@ -76,7 +77,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() {
tool_bar.title = getString(R.string.group_select)
tool_bar.inflateMenu(R.menu.book_group_manage)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
tool_bar.menu.findItem(R.id.menu_group_local).isVisible = false
tool_bar.menu.findItem(R.id.menu_group_audio).isVisible = false

@ -19,6 +19,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.Theme
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
@ -60,7 +61,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() {
tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.group_manage)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(requireContext())

@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.filechooser.adapter.FileAdapter
import io.legado.app.ui.filechooser.adapter.PathAdapter
@ -133,7 +134,7 @@ class FileChooserDialog : DialogFragment(),
tool_bar.menu.add(menuTitle)
}
}
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
}

@ -21,6 +21,7 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.AppConst
import io.legado.app.constant.Theme
import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.alert
@ -65,7 +66,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() {
tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.book_group_manage)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
tool_bar.menu.findItem(R.id.menu_group_local)
.isChecked = AppConst.bookGroupLocalShow

@ -19,6 +19,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.Theme
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
@ -60,7 +61,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() {
tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.group_manage)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(requireContext())

@ -11,6 +11,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
@ -53,7 +54,7 @@ class ReplaceEditDialog : DialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tool_bar.inflateMenu(R.menu.replace_edit)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
viewModel.replaceRuleData.observe(this, Observer {
upReplaceView(it)

@ -19,6 +19,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.Theme
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
@ -60,7 +61,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() {
tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.group_manage)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(requireContext())

@ -1,32 +1,36 @@
package io.legado.app.utils
import android.content.Context
import android.graphics.PorterDuff
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.view.forEach
import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.primaryTextColor
import java.lang.reflect.Method
import java.util.*
fun Menu.applyTint(context: Context, inPrimary: Boolean = true): Menu = this.let { menu ->
fun Menu.applyTint(context: Context, theme: Theme = Theme.Auto): Menu = this.let { menu ->
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}
val primaryTextColor = context.primaryTextColor
val defaultTextColor = context.getCompatColor(R.color.tv_text_default)
val tintColor = when (theme) {
Theme.Dark -> context.getCompatColor(R.color.md_white_1000)
Theme.Light -> context.getCompatColor(R.color.md_black_1000)
else -> primaryTextColor
}
menu.forEach { item ->
(item as MenuItemImpl).let { impl ->
//overflow:展开的item
DrawableUtils.setTint(
impl.icon,
if (!inPrimary) defaultTextColor
else if (impl.requiresOverflow()) defaultTextColor
else primaryTextColor
if (impl.requiresOverflow()) defaultTextColor
else tintColor
)
}
}
@ -47,14 +51,10 @@ fun Menu.applyOpenTint(context: Context) {
if (menuItems is ArrayList<*>) {
for (menuItem in menuItems) {
if (menuItem is MenuItem) {
val drawable = menuItem.icon
if (drawable != null) {
drawable.mutate()
drawable.setColorFilter(
defaultTextColor,
PorterDuff.Mode.SRC_ATOP
)
}
DrawableUtils.setTint(
menuItem.icon,
defaultTextColor
)
}
}
}

Loading…
Cancel
Save