From 77ff08f6d7256059c999cd73c3882c0a3bec6324 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Wed, 1 Feb 2023 05:02:15 +0800 Subject: [PATCH] Modify merge to YukiHookAPI new usage --- .../notify/hook/entity/SystemUIHooker.kt | 50 ++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index 475673a..3179066 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -25,7 +25,6 @@ package com.fankes.coloros.notify.hook.entity import android.app.WallpaperManager -import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter @@ -540,36 +539,31 @@ object SystemUIHooker : YukiBaseHooker() { if (isEnableHookColorNotifyIcon() && prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO)) IconAdaptationTool.prepareAutoUpdateIconRule(context, prefs.get(DataConst.NOTIFY_ICON_FIX_AUTO_TIME)) } - onCreate { - /** 注入模块资源 */ - injectModuleAppResources() - /** 注册发送适配新的 APP 图标通知监听 */ - registerReceiver(object : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent?) { - if (isEnableHookColorNotifyIcon()) intent?.also { - if (it.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() && - it.getBooleanExtra(Intent.EXTRA_REPLACING, false) - ) return@also - it.data?.schemeSpecificPart?.also { packageName -> - when (it.action) { - Intent.ACTION_PACKAGE_ADDED -> { - if (iconDatas.takeIf { e -> e.isNotEmpty() } - ?.filter { e -> e.packageName == packageName } - .isNullOrEmpty() - ) IconAdaptationTool.pushNewAppSupportNotify(context, packageName) - } - Intent.ACTION_PACKAGE_REMOVED -> IconAdaptationTool.removeNewAppSupportNotify(context, packageName) - } - } + /** 注册发送适配新的 APP 图标通知监听 */ + registerReceiver(IntentFilter().apply { + addDataScheme("package") + addAction(Intent.ACTION_PACKAGE_ADDED) + addAction(Intent.ACTION_PACKAGE_REPLACED) + addAction(Intent.ACTION_PACKAGE_REMOVED) + }) { context, intent -> + if (isEnableHookColorNotifyIcon().not()) return@registerReceiver + if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() && + intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) + ) return@registerReceiver + intent.data?.schemeSpecificPart?.also { packageName -> + when (intent.action) { + Intent.ACTION_PACKAGE_ADDED -> { + if (iconDatas.takeIf { e -> e.isNotEmpty() } + ?.filter { e -> e.packageName == packageName } + .isNullOrEmpty() + ) IconAdaptationTool.pushNewAppSupportNotify(context, packageName) } + Intent.ACTION_PACKAGE_REMOVED -> IconAdaptationTool.removeNewAppSupportNotify(context, packageName) } - }, IntentFilter().apply { - addDataScheme("package") - addAction(Intent.ACTION_PACKAGE_ADDED) - addAction(Intent.ACTION_PACKAGE_REPLACED) - addAction(Intent.ACTION_PACKAGE_REMOVED) - }) + } } + /** 注入模块资源 */ + onCreate { injectModuleAppResources() } } /** 刷新图标缓存 */ SystemUITool.Host.onRefreshSystemUI(param = this) { recachingPrefs(it) }