Skip to content

Commit 6fe1f05

Browse files
committed
Added new module version update notification function
1 parent be8f558 commit 6fe1f05

3 files changed

Lines changed: 101 additions & 6 deletions

File tree

app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import com.fankes.miui.notify.params.IconPackParams
5454
import com.fankes.miui.notify.params.factory.isAppNotifyHookAllOf
5555
import com.fankes.miui.notify.params.factory.isAppNotifyHookOf
5656
import com.fankes.miui.notify.utils.factory.*
57+
import com.fankes.miui.notify.utils.tool.ActivationPromptTool
5758
import com.fankes.miui.notify.utils.tool.BitmapCompatTool
5859
import com.fankes.miui.notify.utils.tool.IconAdaptationTool
5960
import com.fankes.miui.notify.utils.tool.SystemUITool
@@ -693,11 +694,12 @@ object SystemUIHooker : YukiBaseHooker() {
693694
addAction(Intent.ACTION_PACKAGE_REPLACED)
694695
addAction(Intent.ACTION_PACKAGE_REMOVED)
695696
}) { context, intent ->
696-
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() &&
697-
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
698-
) return@registerReceiver
699-
if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify)
700-
intent.data?.schemeSpecificPart?.also { packageName ->
697+
intent.data?.schemeSpecificPart?.also { packageName ->
698+
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED)) ActivationPromptTool.prompt(context, packageName)
699+
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() &&
700+
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
701+
) return@registerReceiver
702+
if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify)
701703
when (intent.action) {
702704
Intent.ACTION_PACKAGE_ADDED -> {
703705
if (iconDatas.takeIf { e -> e.isNotEmpty() }
@@ -707,7 +709,7 @@ object SystemUIHooker : YukiBaseHooker() {
707709
}
708710
Intent.ACTION_PACKAGE_REMOVED -> IconAdaptationTool.removeNewAppSupportNotify(context, packageName)
709711
}
710-
}
712+
}
711713
}
712714
/** 注入模块资源 */
713715
onCreate { injectModuleAppResources() }
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* MIUINativeNotifyIcon - Fix the native notification bar icon function abandoned by the MIUI development team.
3+
* Copyright (C) 2017-2023 Fankes Studio(qzmmcn@163.com)
4+
* https://github.com/fankes/MIUINativeNotifyIcon
5+
*
6+
* This software is non-free but opensource software: you can redistribute it
7+
* and/or modify it under the terms of the GNU Affero General Public License
8+
* as published by the Free Software Foundation; either
9+
* version 3 of the License, or any later version.
10+
* <p>
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* and eula along with this software. If not, see
19+
* <https://www.gnu.org/licenses/>
20+
*
21+
* This file is Created by fankes on 2023/4/17.
22+
*/
23+
package com.fankes.miui.notify.utils.tool
24+
25+
import android.app.Notification
26+
import android.app.NotificationChannel
27+
import android.app.NotificationManager
28+
import android.app.PendingIntent
29+
import android.content.ComponentName
30+
import android.content.Context
31+
import android.content.Intent
32+
import android.graphics.drawable.Icon
33+
import android.os.Build
34+
import androidx.core.graphics.drawable.toBitmap
35+
import com.fankes.miui.notify.BuildConfig
36+
import com.fankes.miui.notify.R
37+
import com.fankes.miui.notify.utils.factory.appIconOf
38+
39+
/**
40+
* 模块更新激活提醒通知工具类
41+
*/
42+
object ActivationPromptTool {
43+
44+
/** 当前模块的包名 */
45+
private const val MODULE_PACKAGE_NAME = BuildConfig.APPLICATION_ID
46+
47+
/** 推送通知的渠道名称 */
48+
private const val NOTIFY_CHANNEL = "activationPromptId"
49+
50+
/**
51+
* 推送提醒通知
52+
* @param context 当前实例
53+
* @param packageName 当前 APP 包名
54+
*/
55+
fun prompt(context: Context, packageName: String) {
56+
if (packageName != BuildConfig.APPLICATION_ID) return
57+
context.getSystemService(NotificationManager::class.java)?.apply {
58+
createNotificationChannel(
59+
NotificationChannel(
60+
NOTIFY_CHANNEL, "MIUI 原生通知图标 - 版本更新",
61+
NotificationManager.IMPORTANCE_DEFAULT
62+
).apply { enableLights(false) }
63+
)
64+
notify(packageName.hashCode(), Notification.Builder(context, NOTIFY_CHANNEL).apply {
65+
setShowWhen(true)
66+
setContentTitle("模块已更新")
67+
setContentText("点按通知打开模块以完成新版本激活。")
68+
setColor(0xFFE06818.toInt())
69+
setAutoCancel(true)
70+
setSmallIcon(Icon.createWithResource(MODULE_PACKAGE_NAME, R.drawable.ic_notify_update))
71+
setLargeIcon(context.appIconOf(packageName)?.toBitmap())
72+
setContentIntent(
73+
PendingIntent.getActivity(
74+
context, packageName.hashCode(),
75+
Intent().apply {
76+
component = ComponentName(MODULE_PACKAGE_NAME, "${MODULE_PACKAGE_NAME}.ui.activity.MainActivity")
77+
flags = Intent.FLAG_ACTIVITY_NEW_TASK
78+
}, if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
79+
)
80+
)
81+
}.build())
82+
}
83+
}
84+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="50dp"
3+
android:height="50dp"
4+
android:viewportWidth="1024"
5+
android:viewportHeight="1024">
6+
<path
7+
android:fillColor="#ffffff"
8+
android:pathData="M906.4,791.6a247.9,247.9 0,0 0,-98.1 -186.5L808.3,399.4c0,-118.8 -85.1,-218.9 -197.4,-242.5v-4.7c0,-54.2 -44.5,-98.6 -98.8,-98.6 -54.3,0 -98.8,44.4 -98.8,98.6v4.7C300.8,180.5 215.7,280.4 215.7,399.4v205.8a247.7,247.7 0,0 0,-98.1 186.5h98.1v0.6h592.5v-0.6h98.1v-0.1zM491.1,970.4h24.5c64.3,0 117.8,-48.5 125.6,-110.7L383,859.8a126.8,126.8 0,0 0,125.6 110.7h-17.5z" />
9+
</vector>

0 commit comments

Comments
 (0)