From 706a7fd87873b16bf454a44cc51f211752a8d98f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 28 Mar 2022 17:07:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/utils/MenuExtensions.kt | 23 +++++++++++++++- .../main/java/io/legado/app/utils/UIUtils.kt | 27 ------------------- 2 files changed, 22 insertions(+), 28 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/utils/UIUtils.kt diff --git a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt index 188bb23f4..8bcd1223c 100644 --- a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt @@ -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 + } + } + +} diff --git a/app/src/main/java/io/legado/app/utils/UIUtils.kt b/app/src/main/java/io/legado/app/utils/UIUtils.kt deleted file mode 100644 index 059f94a07..000000000 --- a/app/src/main/java/io/legado/app/utils/UIUtils.kt +++ /dev/null @@ -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 - } - } - -} \ No newline at end of file