() {
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX, b)
binding.notifyIconFixButton.isVisible = b
+ binding.notifyIconFixNotifyItem.isVisible = b
+ SystemUITool.showNeedRestartSnake(context = this)
+ }
+ binding.notifyIconFixNotifySwitch.setOnCheckedChangeListener { btn, b ->
+ if (!btn.isPressed) return@setOnCheckedChangeListener
+ modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
SystemUITool.showNeedRestartSnake(context = this)
}
/** 通知图标优化名单按钮点击事件 */
diff --git a/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt
index 77f4f28..12c12c4 100644
--- a/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt
+++ b/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt
@@ -43,6 +43,7 @@ import android.util.Base64
import android.widget.Toast
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService
+import androidx.core.graphics.drawable.toBitmap
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
import com.google.android.material.snackbar.Snackbar
import com.highcapable.yukihookapi.hook.factory.classOf
@@ -217,6 +218,22 @@ val Context.versionName get() = packageInfo.versionName ?: ""
*/
val Context.versionCode get() = packageInfo.versionCode
+/**
+ * 得到 APP 名称
+ * @param name APP 包名
+ * @return [String]
+ */
+fun Context.findAppName(name: String) =
+ safeOfNothing { packageManager.getPackageInfo(name, 0).applicationInfo.loadLabel(packageManager).toString() }
+
+/**
+ * 得到 APP 图标
+ * @param name APP 包名
+ * @return [Bitmap] or null
+ */
+fun Context.findAppIcon(name: String) =
+ safeOfNull { packageManager.getPackageInfo(name, 0).applicationInfo.loadIcon(packageManager).toBitmap() }
+
/**
* 是否关闭了通知权限
* @return [Boolean]
diff --git a/app/src/main/java/com/fankes/miui/notify/utils/tool/IconAdaptationTool.kt b/app/src/main/java/com/fankes/miui/notify/utils/tool/IconAdaptationTool.kt
new file mode 100644
index 0000000..f37ca1b
--- /dev/null
+++ b/app/src/main/java/com/fankes/miui/notify/utils/tool/IconAdaptationTool.kt
@@ -0,0 +1,129 @@
+/*
+ * MIUINativeNotifyIcon - Fix the native notification bar icon function abandoned by the MIUI development team.
+ * Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
+ * https://github.com/fankes/MIUINativeNotifyIcon
+ *
+ * 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 2022/3/21.
+ */
+package com.fankes.miui.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.Bitmap
+import android.graphics.drawable.Icon
+import android.os.Build
+import com.fankes.miui.notify.BuildConfig
+import com.fankes.miui.notify.hook.HookEntry
+import com.fankes.miui.notify.utils.factory.bitmap
+import com.fankes.miui.notify.utils.factory.findAppIcon
+import com.fankes.miui.notify.utils.factory.findAppName
+import com.fankes.miui.notify.utils.factory.runInSafe
+
+/**
+ * 通知图标适配推送通知类
+ *
+ * 这个类需要在 [HookEntry] 中调用
+ */
+object IconAdaptationTool {
+
+ /** 当前模块的包名 */
+ private const val PACKAGE_NAME = BuildConfig.APPLICATION_ID
+
+ /**
+ * 使用的小图标
+ * @return [Bitmap]
+ */
+ private val smallIcon by lazy {
+ ("iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ix\n" +
+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+
+ "PAP+yaBZJgqr5C2C1pTkuZmb0KTE612V7glCT/rGXZIAnGXyP464TB7BqwWNLXAyBOAtM\n" +
+ "Gcf7Km9+SfsmlqQWSYLzeeh54LnXkvwMOAb6b+zn+hpnZHqC3g9Bdkto7lpW5aoNUyWRm\n" +
+ "vjjc7NJ3iLmtm19l7JZPt0CqLg4HJc2KAHQbpOrCgKSsyc0Kis5YYLn+39+RjwE/TQ5lG\n" +
+ "yW13rUM5Xvb9926IyOBX4FWJ2UwkZd91ZP0d4ggOXcFJC2/T6c20N10PiPpSA6Ex3QNJM\n" +
+ "FMAPzFkP+1w6/fAC8kl9dtE3UVJHe2q8TdB6kyS930uQ7NEhVCNv0J7AAAAABJRU5ErkJ\n" +
+ "ggg==").bitmap
+ }
+
+ /**
+ * 推送新 APP 安装适配通知
+ * @param context 实例
+ * @param packageName 安装的 APP 包名
+ */
+ fun pushNewAppSupportNotify(context: Context, packageName: String) {
+ context.getSystemService(NotificationManager::class.java)?.apply {
+ createNotificationChannel(
+ NotificationChannel(
+ "notifyRuleAdaptId", "通知图标优化适配",
+ NotificationManager.IMPORTANCE_DEFAULT
+ ).apply { enableLights(false) }
+ )
+ notify(packageName.hashCode(), Notification.Builder(context, "notifyRuleAdaptId").apply {
+ setShowWhen(true)
+ setContentTitle("您已安装 ${context.findAppName(packageName)}")
+ setContentText("尚未适配此应用,点按打开在线规则。")
+ setColor(0xFF2993F0.toInt())
+ setAutoCancel(true)
+ setSmallIcon(Icon.createWithBitmap(smallIcon))
+ setLargeIcon(context.findAppIcon(packageName))
+ setContentIntent(
+ PendingIntent.getActivity(
+ context, packageName.hashCode(),
+ Intent().apply {
+ component = ComponentName(
+ PACKAGE_NAME,
+ "$PACKAGE_NAME.ui.activity.ConfigureActivity"
+ )
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ }.apply {
+ putExtra("isNewAppSupport", true)
+ putExtra("appName", context.findAppName(packageName))
+ putExtra("pkgName", packageName)
+ }, if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
+ )
+ )
+ }.build())
+ }
+ }
+
+ /**
+ * 检测 APP 卸载后移除相关通知
+ * @param context 实例
+ * @param packageName 卸载的 APP 包名
+ */
+ fun removeNewAppSupportNotify(context: Context, packageName: String) = runInSafe {
+ context.getSystemService(NotificationManager::class.java)?.cancel(packageName.hashCode())
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/fankes/miui/notify/utils/tool/IconRuleManagerTool.kt b/app/src/main/java/com/fankes/miui/notify/utils/tool/IconRuleManagerTool.kt
index b72265a..3b27c2c 100644
--- a/app/src/main/java/com/fankes/miui/notify/utils/tool/IconRuleManagerTool.kt
+++ b/app/src/main/java/com/fankes/miui/notify/utils/tool/IconRuleManagerTool.kt
@@ -48,7 +48,6 @@ import com.fankes.miui.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_2
import com.fankes.miui.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_3
import com.fankes.miui.notify.params.IconPackParams
import com.fankes.miui.notify.ui.activity.ConfigureActivity
-import com.fankes.miui.notify.utils.factory.openBrowser
import com.fankes.miui.notify.utils.factory.safeOfNull
import com.fankes.miui.notify.utils.factory.showDialog
import com.fankes.miui.notify.utils.factory.snake
@@ -218,9 +217,7 @@ object IconRuleManagerTool {
context.showDialog {
title = "连接失败"
msg = "连接失败,错误如下:\n${if (!isDone1) ctOS else ctAPP}"
- confirmButton(text = "解决方案") {
- context.openBrowser(url = "https://www.baidu.com/s?wd=github%2Braw%2B%E6%97%A0%E6%B3%95%E8%AE%BF%E9%97%AE")
- }
+ confirmButton(text = "再试一次") { syncByHand(context, it) }
cancelButton()
}
else -> pushNotify(context, title = "同步地址不可用", msg = if (!isDone1) ctOS else ctAPP)
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 6fbd83b..373e396 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -447,6 +447,36 @@
android:text="此选项默认开启,开启后将对优化名单内的 APP 通知小图标使用单色调进行修复,特别是通过 MIPUSH 推送的通知,它们始终是 APP 默认图标(彩色的 APP 图标),修复后使得它们的图标看起来更加符合 Android 原生的统一规范。"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
+
+
+
+
+
+
+