mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-04 01:35:26 +08:00
Modify remove grayscale notification icons caching because some system has bugs in SystemUIHooker
This commit is contained in:
@@ -140,9 +140,6 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
/** 缓存的通知图标优化数组 */
|
||||
private var iconDatas = ArrayList<IconDataBean>()
|
||||
|
||||
/** 已缓存的灰度图标 (单色图标) 判断结果数组 */
|
||||
private val grayscaleIconResults = HashMap<String, Boolean>()
|
||||
|
||||
/** 当前是否处于深色图标模式 - 跟随 Hook 保存 */
|
||||
private var isDarkIconMode = false
|
||||
|
||||
@@ -249,22 +246,15 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为灰度图标 (单色图标)
|
||||
* - 这个是修复彩色图标的关键核心代码判断
|
||||
*
|
||||
* 判断是否为灰度图标 - 反射执行系统方法
|
||||
* @param context 实例
|
||||
* @param drawable 要判断的图标
|
||||
* @param instance 用于标识缓存的实例
|
||||
* @return [Boolean]
|
||||
*/
|
||||
private fun isGrayscaleIcon(context: Context, drawable: Drawable, instance: Any): Boolean {
|
||||
/** 从缓存中读取的结果 */
|
||||
val cachedResult = when (instance) {
|
||||
is StatusBarNotification -> grayscaleIconResults[instance.notification.toString()]
|
||||
is Notification -> grayscaleIconResults[instance.toString()]
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** 当前实时获取的结果 */
|
||||
val currentResult = if (ConfigData.isEnableColorIconCompat.not()) safeOfFalse {
|
||||
private fun isGrayscaleIcon(context: Context, drawable: Drawable) =
|
||||
if (ConfigData.isEnableColorIconCompat.not()) safeOfFalse {
|
||||
ContrastColorUtilClass.toClass().let {
|
||||
it.method {
|
||||
name = "isGrayscaleIcon"
|
||||
@@ -275,13 +265,6 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
}.get().invoke(context)).boolean(drawable)
|
||||
}
|
||||
} else BitmapCompatTool.isGrayscaleDrawable(drawable)
|
||||
return cachedResult ?: currentResult.also {
|
||||
when (instance) {
|
||||
is StatusBarNotification -> grayscaleIconResults[instance.notification.toString()] = it
|
||||
is Notification -> grayscaleIconResults[instance.toString()] = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理为圆角图标
|
||||
@@ -377,7 +360,7 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
private fun compatStatusIcon(context: Context, nf: StatusBarNotification?, iconDrawable: Drawable?) = nf?.let { notifyInstance ->
|
||||
if (iconDrawable == null) return@let Pair(null, false)
|
||||
/** 判断是否不是灰度图标 */
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable, notifyInstance)
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)
|
||||
|
||||
/** 目标彩色通知 APP 图标 */
|
||||
val customTriple = compatCustomIcon(context, isGrayscaleIcon, notifyInstance.nfPkgName)
|
||||
@@ -471,7 +454,7 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
?: return@let loggerW(msg = "compatNotifyIcon got null smallIcon")
|
||||
|
||||
/** 判断图标风格 */
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable, notifyInstance)
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)
|
||||
|
||||
/** 自定义默认小图标 */
|
||||
var customIcon: Drawable? = null
|
||||
@@ -551,7 +534,7 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
?: return loggerW(msg = "isGrayscaleIcon got null smallIcon").let { false }
|
||||
|
||||
/** 判断是否不是灰度图标 */
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable, notifyInstance)
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)
|
||||
|
||||
/** 获取目标修复彩色图标的 APP */
|
||||
val isTargetFixApp = compatCustomIcon(context, isGrayscaleIcon, notifyInstance.nfPkgName).first != null
|
||||
@@ -704,7 +687,6 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
/** 缓存图标数据 */
|
||||
private fun cachingIconDatas() {
|
||||
iconDatas.clear()
|
||||
grayscaleIconResults.clear()
|
||||
IconPackParams(param = this).iconDatas.apply { if (isNotEmpty()) forEach { iconDatas.add(it) } }
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user