Merge pull request #3 from gedoor/master

up
pull/60/head
口口吕 5 years ago committed by GitHub
commit 8784fbcddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      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 android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
@ -46,7 +47,7 @@ abstract class BaseActivity(
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.applyTint(this) it.applyTint(this, theme)
bool bool
} ?: super.onCreateOptionsMenu(menu) } ?: super.onCreateOptionsMenu(menu)
} }
@ -98,6 +99,11 @@ abstract class BaseActivity(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
} }
ATH.setStatusBarColorAuto(this, fullScreen) ATH.setStatusBarColorAuto(this, fullScreen)
if (theme == Theme.Dark) {
ATH.setLightStatusBar(this, false)
} else if (theme == Theme.Light) {
ATH.setLightStatusBar(this, true)
}
} }
open fun observeLiveBus() { open fun observeLiveBus() {
@ -107,8 +113,4 @@ abstract class BaseActivity(
currentFocus?.hideSoftInput() currentFocus?.hideSoftInput()
super.finish() super.finish()
} }
enum class Theme {
Dark, Light, Auto
}
} }

@ -1,6 +1,7 @@
package io.legado.app.base package io.legado.app.base
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import io.legado.app.constant.Theme
abstract class VMBaseActivity<VM : ViewModel>( abstract class VMBaseActivity<VM : ViewModel>(
layoutID: Int, 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.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.BookType 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.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookGroup 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.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.Theme
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@ -76,7 +77,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() { private fun initData() {
tool_bar.title = getString(R.string.group_select) tool_bar.title = getString(R.string.group_select)
tool_bar.inflateMenu(R.menu.book_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.setOnMenuItemClickListener(this)
tool_bar.menu.findItem(R.id.menu_group_local).isVisible = false tool_bar.menu.findItem(R.id.menu_group_local).isVisible = false
tool_bar.menu.findItem(R.id.menu_group_audio).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.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter 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.alert
import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
@ -60,7 +61,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() { private fun initData() {
tool_bar.title = getString(R.string.group_manage) tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.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) tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext()) adapter = GroupAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext())

@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.FileAdapter
import io.legado.app.ui.filechooser.adapter.PathAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter
@ -133,7 +134,7 @@ class FileChooserDialog : DialogFragment(),
tool_bar.menu.add(menuTitle) tool_bar.menu.add(menuTitle)
} }
} }
tool_bar.menu.applyTint(requireContext(), false) tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this) 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.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.Theme
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@ -65,7 +66,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() { private fun initData() {
tool_bar.title = getString(R.string.group_manage) tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.book_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.setOnMenuItemClickListener(this)
tool_bar.menu.findItem(R.id.menu_group_local) tool_bar.menu.findItem(R.id.menu_group_local)
.isChecked = AppConst.bookGroupLocalShow .isChecked = AppConst.bookGroupLocalShow

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

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

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

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

Loading…
Cancel
Save