From 4d3106f5bc73498a1f8d74ca0d89752f3ae2b6d9 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Mon, 17 Apr 2023 23:46:55 +0800 Subject: [PATCH] Added new module version update notification function --- .../notify/hook/entity/SystemUIHooker.kt | 14 ++-- .../notify/utils/tool/ActivationPromptTool.kt | 84 +++++++++++++++++++ .../main/res/drawable/ic_notify_update.xml | 9 ++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/fankes/coloros/notify/utils/tool/ActivationPromptTool.kt create mode 100644 app/src/main/res/drawable/ic_notify_update.xml 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 46379a8..8d7263e 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 @@ -52,6 +52,7 @@ import com.fankes.coloros.notify.param.IconPackParams import com.fankes.coloros.notify.param.factory.isAppNotifyHookAllOf import com.fankes.coloros.notify.param.factory.isAppNotifyHookOf import com.fankes.coloros.notify.utils.factory.* +import com.fankes.coloros.notify.utils.tool.ActivationPromptTool import com.fankes.coloros.notify.utils.tool.BitmapCompatTool import com.fankes.coloros.notify.utils.tool.IconAdaptationTool import com.fankes.coloros.notify.utils.tool.SystemUITool @@ -556,11 +557,12 @@ object SystemUIHooker : YukiBaseHooker() { addAction(Intent.ACTION_PACKAGE_REPLACED) addAction(Intent.ACTION_PACKAGE_REMOVED) }) { context, intent -> - if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() && - intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) - ) return@registerReceiver - if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify) - intent.data?.schemeSpecificPart?.also { packageName -> + intent.data?.schemeSpecificPart?.also { packageName -> + if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED)) ActivationPromptTool.prompt(context, packageName) + if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() && + intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) + ) return@registerReceiver + if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify) when (intent.action) { Intent.ACTION_PACKAGE_ADDED -> { if (iconDatas.takeIf { e -> e.isNotEmpty() } @@ -570,7 +572,7 @@ object SystemUIHooker : YukiBaseHooker() { } Intent.ACTION_PACKAGE_REMOVED -> IconAdaptationTool.removeNewAppSupportNotify(context, packageName) } - } + } } /** 注入模块资源 */ onCreate { injectModuleAppResources() } diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/tool/ActivationPromptTool.kt b/app/src/main/java/com/fankes/coloros/notify/utils/tool/ActivationPromptTool.kt new file mode 100644 index 0000000..593476d --- /dev/null +++ b/app/src/main/java/com/fankes/coloros/notify/utils/tool/ActivationPromptTool.kt @@ -0,0 +1,84 @@ +/* + * ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications. + * Copyright (C) 2017-2023 Fankes Studio(qzmmcn@163.com) + * https://github.com/fankes/ColorOSNotifyIcon + * + * This software is non-free but opensource software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + *

+ * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * and eula along with this software. If not, see + * + * + * This file is Created by fankes on 2023/4/17. + */ +package com.fankes.coloros.notify.utils.tool + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.graphics.drawable.Icon +import android.os.Build +import androidx.core.graphics.drawable.toBitmap +import com.fankes.coloros.notify.BuildConfig +import com.fankes.coloros.notify.R +import com.fankes.coloros.notify.utils.factory.appIconOf + +/** + * 模块更新激活提醒通知工具类 + */ +object ActivationPromptTool { + + /** 当前模块的包名 */ + private const val MODULE_PACKAGE_NAME = BuildConfig.APPLICATION_ID + + /** 推送通知的渠道名称 */ + private const val NOTIFY_CHANNEL = "activationPromptId" + + /** + * 推送提醒通知 + * @param context 当前实例 + * @param packageName 当前 APP 包名 + */ + fun prompt(context: Context, packageName: String) { + if (packageName != BuildConfig.APPLICATION_ID) return + context.getSystemService(NotificationManager::class.java)?.apply { + createNotificationChannel( + NotificationChannel( + NOTIFY_CHANNEL, "ColorOS 通知图标增强 - 版本更新", + NotificationManager.IMPORTANCE_DEFAULT + ).apply { enableLights(false) } + ) + notify(packageName.hashCode(), Notification.Builder(context, NOTIFY_CHANNEL).apply { + setShowWhen(true) + setContentTitle("模块已更新") + setContentText("点按通知打开模块以完成新版本激活。") + setColor(0xFF4E8A5A.toInt()) + setAutoCancel(true) + setSmallIcon(Icon.createWithResource(MODULE_PACKAGE_NAME, R.drawable.ic_notify_update)) + setLargeIcon(context.appIconOf(packageName)?.toBitmap()) + setContentIntent( + PendingIntent.getActivity( + context, packageName.hashCode(), + Intent().apply { + component = ComponentName(MODULE_PACKAGE_NAME, "${MODULE_PACKAGE_NAME}.ui.activity.MainActivity") + flags = Intent.FLAG_ACTIVITY_NEW_TASK + }, if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE + ) + ) + }.build()) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_notify_update.xml b/app/src/main/res/drawable/ic_notify_update.xml new file mode 100644 index 0000000..3f22d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_notify_update.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file