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