mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
71f56ae589
commit
706a7fd878
@ -14,6 +14,7 @@ import androidx.appcompat.view.menu.SubMenuBuilder
|
||||
import androidx.core.view.forEach
|
||||
import io.legado.app.R
|
||||
import io.legado.app.constant.Theme
|
||||
import io.legado.app.lib.theme.primaryTextColor
|
||||
import java.lang.reflect.Method
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@ -22,7 +23,7 @@ fun Menu.applyTint(context: Context, theme: Theme = Theme.Auto): Menu = this.let
|
||||
menu.setOptionalIconsVisible(true)
|
||||
}
|
||||
val defaultTextColor = context.getCompatColor(R.color.primaryText)
|
||||
val tintColor = UIUtils.getMenuColor(context, theme)
|
||||
val tintColor = MenuExtensions.getMenuColor(context, theme)
|
||||
menu.forEach { item ->
|
||||
(item as MenuItemImpl).let { impl ->
|
||||
//overflow:展开的item
|
||||
@ -70,3 +71,23 @@ fun Menu.iconItemOnLongClick(id: Int, function: (view: View) -> Unit) {
|
||||
item.actionView.setOnClickListener { performIdentifierAction(id, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
object MenuExtensions {
|
||||
|
||||
fun getMenuColor(
|
||||
context: Context,
|
||||
theme: Theme = Theme.Auto,
|
||||
requiresOverflow: Boolean = false
|
||||
): Int {
|
||||
val defaultTextColor = context.getCompatColor(R.color.primaryText)
|
||||
if (requiresOverflow)
|
||||
return defaultTextColor
|
||||
val primaryTextColor = context.primaryTextColor
|
||||
return when (theme) {
|
||||
Theme.Dark -> context.getCompatColor(R.color.md_white_1000)
|
||||
Theme.Light -> context.getCompatColor(R.color.md_black_1000)
|
||||
else -> primaryTextColor
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import android.content.Context
|
||||
import io.legado.app.R
|
||||
import io.legado.app.constant.Theme
|
||||
import io.legado.app.lib.theme.primaryTextColor
|
||||
|
||||
@Suppress("unused")
|
||||
object UIUtils {
|
||||
|
||||
fun getMenuColor(
|
||||
context: Context,
|
||||
theme: Theme = Theme.Auto,
|
||||
requiresOverflow: Boolean = false
|
||||
): Int {
|
||||
val defaultTextColor = context.getCompatColor(R.color.primaryText)
|
||||
if (requiresOverflow)
|
||||
return defaultTextColor
|
||||
val primaryTextColor = context.primaryTextColor
|
||||
return when (theme) {
|
||||
Theme.Dark -> context.getCompatColor(R.color.md_white_1000)
|
||||
Theme.Light -> context.getCompatColor(R.color.md_black_1000)
|
||||
else -> primaryTextColor
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user