From 55e7256dbbfb788849e29c6a7611fcb58042f627 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Tue, 22 Mar 2022 21:07:35 +0800 Subject: [PATCH] Merge code --- .../fankes/coloros/notify/hook/HookEntry.kt | 22 ++++++++++++++----- .../notify/utils/tool/IconAdaptationTool.kt | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt b/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt index 0a722d6..9ee783b 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt @@ -140,6 +140,14 @@ class HookEntry : YukiHookXposedInitProxy { /** 缓存的通知优化图标数组 */ private var iconDatas = ArrayList() + /** + * 是否启用忽略彩色图标和启用通知图标优化功能 + * @return [Boolean] + */ + private val PackageParam.isEnableHookColorNotifyIcon + get() = prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) && + prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true) + /** * 打印日志 * @param tag 标识 @@ -282,7 +290,13 @@ class HookEntry : YukiHookXposedInitProxy { /** 缓存图标数据 */ private fun PackageParam.cachingIconDatas() { - iconDatas = IconPackParams(param = this).iconDatas + iconDatas.clear() + IconPackParams(param = this).iconDatas.apply { + when { + isNotEmpty() -> forEach { iconDatas.add(it) } + isEmpty() && isEnableHookColorNotifyIcon -> loggerW(msg = "NotifyIconSupportData is empty!") + } + } } override fun onInit() = configs { @@ -427,9 +441,7 @@ class HookEntry : YukiHookXposedInitProxy { param(ContextClass, IntentClass) } afterHook { - if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) && - prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true) - ) (lastArgs as? Intent)?.also { + if (isEnableHookColorNotifyIcon) (lastArgs as? Intent)?.also { if (!it.action.equals(Intent.ACTION_PACKAGE_REPLACED) && it.getBooleanExtra(Intent.EXTRA_REPLACING, false) ) return@also @@ -451,7 +463,7 @@ class HookEntry : YukiHookXposedInitProxy { } } } - /** 自动检查通知优化图标更新的注入监听 */ + /** 自动检查通知图标优化更新的注入监听 */ AbstractReceiverClass.hook { injectMember { method { diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt b/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt index 060f8cd..519bc14 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt @@ -83,11 +83,11 @@ object IconAdaptationTool { context.getSystemService(NotificationManager::class.java)?.apply { createNotificationChannel( NotificationChannel( - "notifyRuleAdaptId", "通知图标优化适配", + IconRuleManagerTool.NOTIFY_CHANNEL, "通知图标优化适配", NotificationManager.IMPORTANCE_DEFAULT ).apply { enableLights(false) } ) - notify(packageName.hashCode(), Notification.Builder(context, "notifyRuleAdaptId").apply { + notify(packageName.hashCode(), Notification.Builder(context, IconRuleManagerTool.NOTIFY_CHANNEL).apply { setShowWhen(true) setContentTitle("您已安装 ${context.findAppName(packageName)}") setContentText("尚未适配此应用,点按打开在线规则。")