mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-05 18:25:23 +08:00
Update YukiHookAPI
This commit is contained in:
@@ -72,8 +72,8 @@ tasks.whenTaskAdded {
|
||||
|
||||
dependencies {
|
||||
compileOnly 'de.robv.android.xposed:api:82'
|
||||
implementation 'com.highcapable.yukihookapi:api:1.0.66'
|
||||
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.66'
|
||||
implementation 'com.highcapable.yukihookapi:api:1.0.67'
|
||||
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.67'
|
||||
implementation "com.github.topjohnwu.libsu:core:3.1.2"
|
||||
implementation 'androidx.annotation:annotation:1.3.0'
|
||||
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.0'
|
||||
|
44
app/src/main/java/com/fankes/miui/notify/data/DataConst.kt
Normal file
44
app/src/main/java/com/fankes/miui/notify/data/DataConst.kt
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
* <p>
|
||||
*
|
||||
* 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
|
||||
* <https://www.gnu.org/licenses/>
|
||||
*
|
||||
* This file is Created by fankes on 2022/3/26.
|
||||
*/
|
||||
package com.fankes.miui.notify.data
|
||||
|
||||
import com.fankes.miui.notify.hook.HookConst
|
||||
import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
|
||||
|
||||
object DataConst {
|
||||
|
||||
val ENABLE_MODULE = PrefsData("_enable_module", true)
|
||||
val ENABLE_MODULE_LOG = PrefsData("_enable_module_log", false)
|
||||
val ENABLE_HIDE_ICON = PrefsData("_hide_icon", false)
|
||||
val ENABLE_COLOR_ICON_COMPAT = PrefsData("_color_icon_compat", false)
|
||||
val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true)
|
||||
val ENABLE_NOTIFY_ICON_FIX_NOTIFY = PrefsData("_notify_icon_fix_notify", true)
|
||||
val ENABLE_HOOK_STATUS_ICON_COUNT = PrefsData("_enable_hook_status_icon_count", true)
|
||||
val ENABLE_NOTIFY_ICON_FIX_AUTO = PrefsData("_enable_notify_icon_fix_auto", true)
|
||||
val NOTIFY_ICON_DATAS = PrefsData("_notify_icon_datas", "")
|
||||
val NOTIFY_ICON_FIX_AUTO_TIME = PrefsData("_notify_icon_fix_auto_time", "07:00")
|
||||
val HOOK_STATUS_ICON_COUNT = PrefsData("_hook_status_icon_count", 5)
|
||||
|
||||
val SOURCE_SYNC_WAY = PrefsData("_rule_source_sync_way", HookConst.TYPE_SOURCE_SYNC_WAY_1)
|
||||
val SOURCE_SYNC_WAY_CUSTOM_URL = PrefsData("_rule_source_sync_way_custom_url", "")
|
||||
}
|
@@ -26,21 +26,6 @@ package com.fankes.miui.notify.hook
|
||||
|
||||
object HookConst {
|
||||
|
||||
const val ENABLE_MODULE = "_enable_module"
|
||||
const val ENABLE_MODULE_LOG = "_enable_module_log"
|
||||
const val ENABLE_HIDE_ICON = "_hide_icon"
|
||||
const val ENABLE_COLOR_ICON_COMPAT = "_color_icon_compat"
|
||||
const val ENABLE_NOTIFY_ICON_FIX = "_notify_icon_fix"
|
||||
const val ENABLE_NOTIFY_ICON_FIX_NOTIFY = "_notify_icon_fix_notify"
|
||||
const val ENABLE_HOOK_STATUS_ICON_COUNT = "_enable_hook_status_icon_count"
|
||||
const val ENABLE_NOTIFY_ICON_FIX_AUTO = "_enable_notify_icon_fix_auto"
|
||||
const val NOTIFY_ICON_DATAS = "_notify_icon_datas"
|
||||
const val NOTIFY_ICON_FIX_AUTO_TIME = "_notify_icon_fix_auto_time"
|
||||
const val HOOK_STATUS_ICON_COUNT = "_hook_status_icon_count"
|
||||
|
||||
const val SOURCE_SYNC_WAY = "_rule_source_sync_way"
|
||||
const val SOURCE_SYNC_WAY_CUSTOM_URL = "_rule_source_sync_way_custom_url"
|
||||
|
||||
const val TYPE_SOURCE_SYNC_WAY_1 = 1000
|
||||
const val TYPE_SOURCE_SYNC_WAY_2 = 2000
|
||||
const val TYPE_SOURCE_SYNC_WAY_3 = 3000
|
||||
|
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
package com.fankes.miui.notify.hook
|
||||
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE
|
||||
import com.fankes.miui.notify.data.DataConst
|
||||
import com.fankes.miui.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
|
||||
import com.fankes.miui.notify.hook.entity.SystemUIHooker
|
||||
import com.fankes.miui.notify.utils.factory.isLowerAndroidP
|
||||
@@ -53,7 +53,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
||||
/** 不是支持的 MIUI 系统停止 Hook */
|
||||
isNotSupportMiuiVersion -> loggerW(msg = "Aborted Hook -> This MIUI Version $miuiVersion not supported")
|
||||
/** Hook 被手动关闭停止 Hook */
|
||||
!prefs.getBoolean(ENABLE_MODULE, default = true) -> loggerW(msg = "Aborted Hook -> Hook Closed")
|
||||
prefs.get(DataConst.ENABLE_MODULE).not() -> loggerW(msg = "Aborted Hook -> Hook Closed")
|
||||
/** 开始 Hook */
|
||||
else -> loadHooker(SystemUIHooker())
|
||||
}
|
||||
|
@@ -42,13 +42,7 @@ import android.widget.ImageView
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.fankes.miui.notify.bean.IconDataBean
|
||||
import com.fankes.miui.notify.const.Const
|
||||
import com.fankes.miui.notify.hook.HookConst
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_COMPAT
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE_LOG
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_AUTO
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY
|
||||
import com.fankes.miui.notify.hook.HookConst.NOTIFY_ICON_FIX_AUTO_TIME
|
||||
import com.fankes.miui.notify.data.DataConst
|
||||
import com.fankes.miui.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
|
||||
import com.fankes.miui.notify.hook.factory.isAppNotifyHookAllOf
|
||||
import com.fankes.miui.notify.hook.factory.isAppNotifyHookOf
|
||||
@@ -212,8 +206,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
* @return [Boolean]
|
||||
*/
|
||||
private fun isEnableHookColorNotifyIcon(isHooking: Boolean = true) =
|
||||
prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) &&
|
||||
(if (isHooking) prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true) else true)
|
||||
prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) && (if (isHooking) prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY) else true)
|
||||
|
||||
/**
|
||||
* - 这个是修复彩色图标的关键核心代码判断
|
||||
@@ -224,7 +217,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
* @return [Boolean]
|
||||
*/
|
||||
private fun isGrayscaleIcon(context: Context, drawable: Drawable) =
|
||||
if (!prefs.getBoolean(ENABLE_COLOR_ICON_COMPAT)) safeOfFalse {
|
||||
if (prefs.get(DataConst.ENABLE_COLOR_ICON_COMPAT).not()) safeOfFalse {
|
||||
ContrastColorUtilClass.clazz.let {
|
||||
it.method {
|
||||
name = "isGrayscaleIcon"
|
||||
@@ -243,7 +236,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
* @return [Boolean]
|
||||
*/
|
||||
private val hasHandleHeaderViews
|
||||
get() = safeOfFalse { NotificationHeaderViewWrapperClass.clazz.hasMethod(name = "handleHeaderViews") }
|
||||
get() = safeOfFalse { NotificationHeaderViewWrapperClass.clazz.hasMethod { name = "handleHeaderViews" } }
|
||||
|
||||
/**
|
||||
* 获取当前通知栏的样式
|
||||
@@ -271,7 +264,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
*/
|
||||
private fun StatusBarNotification.compatPushingIcon(context: Context, iconDrawable: Drawable) = safeOf(iconDrawable) {
|
||||
/** 给 MIPUSH 设置 APP 自己的图标 */
|
||||
if (isXmsf && opPkgName.isNotBlank())
|
||||
if (isXmsf && nfPkgName.isNotBlank())
|
||||
context.findAppIcon(xmsfPkgName) ?: iconDrawable
|
||||
else iconDrawable
|
||||
}
|
||||
@@ -291,8 +284,8 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
isCustom: Boolean,
|
||||
isGrayscale: Boolean
|
||||
) {
|
||||
if (prefs.getBoolean(ENABLE_MODULE_LOG)) loggerD(
|
||||
msg = "$tag --> [${context.findAppName(name = expandedNf?.compatOpPkgName ?: "")}][${expandedNf?.opPkgName}] " +
|
||||
if (prefs.get(DataConst.ENABLE_MODULE_LOG)) loggerD(
|
||||
msg = "$tag --> [${context.findAppName(name = expandedNf?.nfPkgName ?: "")}][${expandedNf?.nfPkgName}] " +
|
||||
"custom [$isCustom] " +
|
||||
"grayscale [$isGrayscale] " +
|
||||
"xmsf [${expandedNf?.isXmsf}]"
|
||||
@@ -320,7 +313,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
* 自动判断 MIPUSH
|
||||
* @return [String]
|
||||
*/
|
||||
private val StatusBarNotification.opPkgName get() = if (isXmsf) xmsfPkgName else compatOpPkgName
|
||||
private val StatusBarNotification.nfPkgName get() = if (isXmsf) xmsfPkgName else packageName
|
||||
|
||||
/**
|
||||
* 获取 MIPUSH 通知真实包名
|
||||
@@ -373,11 +366,11 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
*/
|
||||
private fun compatCustomIcon(isGrayscaleIcon: Boolean, packageName: String): Pair<Bitmap?, Int> {
|
||||
var customPair: Pair<Bitmap?, Int>? = null
|
||||
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)) run {
|
||||
if (prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)) run {
|
||||
if (iconDatas.isNotEmpty())
|
||||
iconDatas.forEach {
|
||||
if (packageName == it.packageName && isAppNotifyHookOf(it)) {
|
||||
if (!isGrayscaleIcon || isAppNotifyHookAllOf(it))
|
||||
if (isGrayscaleIcon.not() || isAppNotifyHookAllOf(it))
|
||||
customPair = Pair(it.iconBitmap, it.iconColor)
|
||||
return@run
|
||||
}
|
||||
@@ -406,16 +399,16 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
expandedNf?.also { notifyInstance ->
|
||||
/** 判断是 MIUI 样式就停止 Hook */
|
||||
if (context.isMiuiNotifyStyle) {
|
||||
it(context.findAppIcon(notifyInstance.compatOpPkgName) ?: iconDrawable, true)
|
||||
it(context.findAppIcon(notifyInstance.nfPkgName) ?: iconDrawable, true)
|
||||
return@runInSafe
|
||||
}
|
||||
/** 判断是否不是灰度图标 */
|
||||
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
|
||||
val isNotGrayscaleIcon = notifyInstance.isXmsf || isGrayscaleIcon(context, iconDrawable).not()
|
||||
|
||||
/** 目标彩色通知 APP 图标 */
|
||||
val customIcon = compatCustomIcon(!isNotGrayscaleIcon, notifyInstance.opPkgName).first
|
||||
val customIcon = compatCustomIcon(isNotGrayscaleIcon.not(), notifyInstance.nfPkgName).first
|
||||
/** 打印日志 */
|
||||
printLogcat(tag = "StatusIcon", context, notifyInstance, isCustom = customIcon != null, !isNotGrayscaleIcon)
|
||||
printLogcat(tag = "StatusIcon", context, notifyInstance, isCustom = customIcon != null, isNotGrayscaleIcon.not())
|
||||
when {
|
||||
/** 处理自定义通知图标优化 */
|
||||
customIcon != null -> it(BitmapDrawable(context.resources, customIcon), true)
|
||||
@@ -463,7 +456,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
val supportColor = iconColor.let {
|
||||
when {
|
||||
isUpperOfAndroidS -> newStyle
|
||||
it == 0 || !isExpanded -> oldStyle
|
||||
it == 0 || isExpanded.not() -> oldStyle
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
@@ -472,14 +465,14 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
|
||||
|
||||
/** 判断图标风格 */
|
||||
val isGrayscaleIcon = !notifyInstance.isXmsf && isGrayscaleIcon(context, iconDrawable)
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)
|
||||
|
||||
/** 自定义默认小图标 */
|
||||
var customIcon: Bitmap?
|
||||
|
||||
/** 自定义默认小图标颜色 */
|
||||
var customIconColor: Int
|
||||
compatCustomIcon(isGrayscaleIcon, notifyInstance.opPkgName).also {
|
||||
compatCustomIcon(isGrayscaleIcon, notifyInstance.nfPkgName).also {
|
||||
customIcon = it.first
|
||||
customIconColor = if (isUpperOfAndroidS || isExpanded)
|
||||
(it.second.takeIf { e -> e != 0 } ?: context.systemAccentColor) else 0
|
||||
@@ -549,23 +542,23 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
* @return [Boolean] 是否忽略通知图标颜色
|
||||
*/
|
||||
private fun hasIgnoreStatusBarIconColor(context: Context, expandedNf: StatusBarNotification?) =
|
||||
if (!context.isMiuiNotifyStyle) safeOfFalse {
|
||||
if (context.isMiuiNotifyStyle.not()) safeOfFalse {
|
||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||
expandedNf?.let { notifyInstance ->
|
||||
/** 获取通知小图标 */
|
||||
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
|
||||
|
||||
/** 判断是否不是灰度图标 */
|
||||
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
|
||||
val isNotGrayscaleIcon = notifyInstance.isXmsf || isGrayscaleIcon(context, iconDrawable).not()
|
||||
|
||||
/** 获取目标修复彩色图标的 APP */
|
||||
val isTargetFixApp = compatCustomIcon(!isNotGrayscaleIcon, notifyInstance.opPkgName).first != null
|
||||
val isTargetFixApp = compatCustomIcon(isNotGrayscaleIcon.not(), notifyInstance.nfPkgName).first != null
|
||||
/**
|
||||
* 只要不是灰度就返回彩色图标
|
||||
* 否则不对颜色进行反色处理防止一些系统图标出现异常
|
||||
*/
|
||||
(if (isTargetFixApp) false else isNotGrayscaleIcon).also {
|
||||
printLogcat(tag = "IconColor", context, expandedNf, isTargetFixApp, !isNotGrayscaleIcon)
|
||||
printLogcat(tag = "IconColor", context, expandedNf, isTargetFixApp, isNotGrayscaleIcon.not())
|
||||
}
|
||||
} ?: true.also { printLogcat(tag = "IconColor", context, expandedNf = null, isCustom = false, isGrayscale = false) }
|
||||
} else true.also { printLogcat(tag = "IconColor", context, expandedNf, isCustom = false, isGrayscale = false) }
|
||||
@@ -658,10 +651,10 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
*/
|
||||
field { name = "mCurrentSetColor" }.ofInt(instance).also { color ->
|
||||
if (safeOfFalse {
|
||||
NotificationUtilClass.clazz.hasMethod(
|
||||
name = "ignoreStatusBarIconColor",
|
||||
ExpandedNotificationClass.clazz
|
||||
)
|
||||
NotificationUtilClass.clazz.hasMethod {
|
||||
name = "ignoreStatusBarIconColor"
|
||||
param(ExpandedNotificationClass.clazz)
|
||||
}
|
||||
}) {
|
||||
alpha = if (color.isWhite) 0.95f else 0.8f
|
||||
setColorFilter(if (color.isWhite) color else Color.BLACK)
|
||||
@@ -705,9 +698,9 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
method { name = "updateState" }
|
||||
beforeHook {
|
||||
/** 解除状态栏通知图标个数限制 */
|
||||
if (isShowNotificationIcons && prefs.getBoolean(HookConst.ENABLE_HOOK_STATUS_ICON_COUNT, default = true))
|
||||
if (isShowNotificationIcons && prefs.get(DataConst.ENABLE_HOOK_STATUS_ICON_COUNT))
|
||||
field { name = "MAX_STATIC_ICONS" }
|
||||
.get(instance).set(prefs.getInt(HookConst.HOOK_STATUS_ICON_COUNT, default = 5)
|
||||
.get(instance).set(prefs.get(DataConst.HOOK_STATUS_ICON_COUNT)
|
||||
.let { if (it in 0..100) it else 5 })
|
||||
}
|
||||
}
|
||||
@@ -727,7 +720,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
}
|
||||
beforeHook { isShowNotificationIcons = firstArgs<Boolean>() ?: false }
|
||||
}.ignoredNoSuchMemberFailure()
|
||||
}.by { NotificationIconContainerClass.clazz.hasField(name = "MAX_STATIC_ICONS") }
|
||||
}.by { NotificationIconContainerClass.clazz.hasField { name = "MAX_STATIC_ICONS" } }
|
||||
NotificationHeaderViewWrapperClass.hook {
|
||||
/** 修复下拉通知图标自动设置回 APP 图标的方法 */
|
||||
injectMember {
|
||||
@@ -812,7 +805,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
}
|
||||
afterHook {
|
||||
if (isEnableHookColorNotifyIcon()) (lastArgs as? Intent)?.also {
|
||||
if (!it.action.equals(Intent.ACTION_PACKAGE_REPLACED) &&
|
||||
if (it.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() &&
|
||||
it.getBooleanExtra(Intent.EXTRA_REPLACING, false)
|
||||
) return@also
|
||||
when (it.action) {
|
||||
@@ -838,11 +831,11 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
injectMember {
|
||||
method { name = "updateTime" }
|
||||
afterHook {
|
||||
if (isEnableHookColorNotifyIcon() && prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_AUTO, default = true))
|
||||
if (isEnableHookColorNotifyIcon() && prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO))
|
||||
IconAdaptationTool.prepareAutoUpdateIconRule(
|
||||
context = instance<View>().context,
|
||||
// TODO 设置 UI 界面设置定时更新规则
|
||||
timeSet = prefs.getString(NOTIFY_ICON_FIX_AUTO_TIME, default = "07:00")
|
||||
timeSet = prefs.get(DataConst.NOTIFY_ICON_FIX_AUTO_TIME)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -31,13 +31,13 @@ import com.highcapable.yukihookapi.hook.param.PackageParam
|
||||
* 获取此 APP 的通知图标是否被 Hook
|
||||
* @param bean 图标 bean
|
||||
*/
|
||||
fun PackageParam.isAppNotifyHookOf(bean: IconDataBean) = prefs.getBoolean(key = bean.toEnabledName(), default = bean.isEnabled)
|
||||
fun PackageParam.isAppNotifyHookOf(bean: IconDataBean) = prefs.getBoolean(bean.toEnabledName(), bean.isEnabled)
|
||||
|
||||
/**
|
||||
* 获取此 APP 的通知图标是否被 Hook
|
||||
* @param bean 图标 bean
|
||||
*/
|
||||
fun Context.isAppNotifyHookOf(bean: IconDataBean) = modulePrefs.getBoolean(key = bean.toEnabledName(), default = bean.isEnabled)
|
||||
fun Context.isAppNotifyHookOf(bean: IconDataBean) = modulePrefs.getBoolean(bean.toEnabledName(), bean.isEnabled)
|
||||
|
||||
/**
|
||||
* 设置 Hook 此 APP 的通知图标
|
||||
@@ -45,21 +45,21 @@ fun Context.isAppNotifyHookOf(bean: IconDataBean) = modulePrefs.getBoolean(key =
|
||||
* @param isHook 是否 Hook
|
||||
*/
|
||||
fun Context.putAppNotifyHookOf(bean: IconDataBean, isHook: Boolean) =
|
||||
modulePrefs.putBoolean(key = bean.toEnabledName(), value = isHook)
|
||||
modulePrefs.putBoolean(bean.toEnabledName(), isHook)
|
||||
|
||||
/**
|
||||
* 获取此 APP 的通知图标是否被全部 Hook
|
||||
* @param bean 图标 bean
|
||||
*/
|
||||
fun PackageParam.isAppNotifyHookAllOf(bean: IconDataBean) =
|
||||
prefs.getBoolean(key = bean.toEnabledAllName(), default = bean.isEnabledAll)
|
||||
prefs.getBoolean(bean.toEnabledAllName(), bean.isEnabledAll)
|
||||
|
||||
/**
|
||||
* 获取此 APP 的通知图标是否被全部 Hook
|
||||
* @param bean 图标 bean
|
||||
*/
|
||||
fun Context.isAppNotifyHookAllOf(bean: IconDataBean) =
|
||||
modulePrefs.getBoolean(key = bean.toEnabledAllName(), default = bean.isEnabledAll)
|
||||
modulePrefs.getBoolean(bean.toEnabledAllName(), bean.isEnabledAll)
|
||||
|
||||
/**
|
||||
* 设置全部 Hook 此 APP 的通知图标
|
||||
@@ -67,4 +67,4 @@ fun Context.isAppNotifyHookAllOf(bean: IconDataBean) =
|
||||
* @param isHook 是否 Hook
|
||||
*/
|
||||
fun Context.putAppNotifyHookAllOf(bean: IconDataBean, isHook: Boolean) =
|
||||
modulePrefs.putBoolean(key = bean.toEnabledAllName(), value = isHook)
|
||||
modulePrefs.putBoolean(bean.toEnabledAllName(), isHook)
|
@@ -27,7 +27,7 @@ package com.fankes.miui.notify.params
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import com.fankes.miui.notify.bean.IconDataBean
|
||||
import com.fankes.miui.notify.hook.HookConst.NOTIFY_ICON_DATAS
|
||||
import com.fankes.miui.notify.data.DataConst
|
||||
import com.fankes.miui.notify.utils.factory.*
|
||||
import com.highcapable.yukihookapi.hook.factory.modulePrefs
|
||||
import com.highcapable.yukihookapi.hook.param.PackageParam
|
||||
@@ -47,7 +47,7 @@ class IconPackParams(private val context: Context? = null, private val param: Pa
|
||||
* 已存储的 JSON 数据
|
||||
* @return [String]
|
||||
*/
|
||||
internal val storageDataJson get() = (context?.modulePrefs ?: param?.prefs)?.direct()?.getString(NOTIFY_ICON_DATAS)
|
||||
internal val storageDataJson get() = (context?.modulePrefs ?: param?.prefs)?.direct()?.get(DataConst.NOTIFY_ICON_DATAS)
|
||||
|
||||
/**
|
||||
* 获取图标数据
|
||||
@@ -134,5 +134,5 @@ class IconPackParams(private val context: Context? = null, private val param: Pa
|
||||
* 保存图标数据
|
||||
* @param dataJson 图标数据 JSON
|
||||
*/
|
||||
fun save(dataJson: String) = context?.modulePrefs?.putString(NOTIFY_ICON_DATAS, dataJson)
|
||||
fun save(dataJson: String) = context?.modulePrefs?.put(DataConst.NOTIFY_ICON_DATAS, dataJson)
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
|
||||
|
||||
override fun onCreate() {
|
||||
/** 检查激活状态 */
|
||||
if (!isXposedModuleActive) {
|
||||
if (isXposedModuleActive.not()) {
|
||||
showDialog {
|
||||
title = "模块没有激活"
|
||||
msg = "模块没有激活,你无法使用这里的功能,请先激活模块。"
|
||||
@@ -146,14 +146,14 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
|
||||
holder.adpAppAllSwitch.isEnabled = e
|
||||
}
|
||||
holder.adpAppOpenSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
putAppNotifyHookOf(it, b)
|
||||
holder.adpAppAllSwitch.isEnabled = b
|
||||
SystemUITool.refreshSystemUI(context = this@ConfigureActivity)
|
||||
}
|
||||
holder.adpAppAllSwitch.isChecked = isAppNotifyHookAllOf(it)
|
||||
holder.adpAppAllSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
putAppNotifyHookAllOf(it, b)
|
||||
SystemUITool.refreshSystemUI(context = this@ConfigureActivity)
|
||||
}
|
||||
|
@@ -31,16 +31,9 @@ import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import com.fankes.miui.notify.R
|
||||
import com.fankes.miui.notify.const.Const
|
||||
import com.fankes.miui.notify.data.DataConst
|
||||
import com.fankes.miui.notify.databinding.ActivityMainBinding
|
||||
import com.fankes.miui.notify.databinding.DiaStatusIconCountBinding
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_COMPAT
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_HIDE_ICON
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_HOOK_STATUS_ICON_COUNT
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE_LOG
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX
|
||||
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY
|
||||
import com.fankes.miui.notify.hook.HookConst.HOOK_STATUS_ICON_COUNT
|
||||
import com.fankes.miui.notify.params.IconPackParams
|
||||
import com.fankes.miui.notify.ui.activity.base.BaseActivity
|
||||
import com.fankes.miui.notify.utils.factory.*
|
||||
@@ -113,7 +106,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
/** 判断是否 Hook */
|
||||
isXposedModuleActive -> {
|
||||
if (IconPackParams(context = this).iconDatas.isEmpty()
|
||||
&& modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
|
||||
&& modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
|
||||
) showDialog {
|
||||
title = "配置通知图标优化名单"
|
||||
msg = "模块需要获取在线规则以更新“通知图标优化名单”,它现在是空的,这看起来是你第一次使用模块,请首先进行配置才可以使用相关功能。\n" +
|
||||
@@ -122,7 +115,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
cancelButton()
|
||||
noCancelable()
|
||||
}
|
||||
if (isNotNoificationEnabled && modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true))
|
||||
if (isNotNoificationEnabled && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX))
|
||||
showDialog {
|
||||
title = "模块的通知权限已关闭"
|
||||
msg = "请开启通知权限,以确保你能收到通知图标优化在线规则的更新。"
|
||||
@@ -143,24 +136,24 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
}
|
||||
/** 获取 Sp 存储的信息 */
|
||||
var statusBarIconCount = modulePrefs.getInt(HOOK_STATUS_ICON_COUNT, default = 5)
|
||||
binding.colorIconHookItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
|
||||
binding.statusIconCountItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
|
||||
binding.notifyIconConfigItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
|
||||
binding.notifyIconFixButton.isVisible = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
|
||||
binding.notifyIconFixNotifyItem.isVisible = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
|
||||
binding.statusIconCountSwitch.isChecked = modulePrefs.getBoolean(ENABLE_HOOK_STATUS_ICON_COUNT, default = true)
|
||||
binding.statusIconCountChildItem.isVisible = modulePrefs.getBoolean(ENABLE_HOOK_STATUS_ICON_COUNT, default = true)
|
||||
binding.moduleEnableSwitch.isChecked = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
|
||||
binding.moduleEnableLogSwitch.isChecked = modulePrefs.getBoolean(ENABLE_MODULE_LOG)
|
||||
binding.hideIconInLauncherSwitch.isChecked = modulePrefs.getBoolean(ENABLE_HIDE_ICON)
|
||||
binding.colorIconCompatSwitch.isChecked = modulePrefs.getBoolean(ENABLE_COLOR_ICON_COMPAT)
|
||||
binding.notifyIconFixSwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
|
||||
binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true)
|
||||
var statusBarIconCount = modulePrefs.get(DataConst.HOOK_STATUS_ICON_COUNT)
|
||||
binding.colorIconHookItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE)
|
||||
binding.statusIconCountItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE)
|
||||
binding.notifyIconConfigItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE)
|
||||
binding.notifyIconFixButton.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
|
||||
binding.notifyIconFixNotifyItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
|
||||
binding.statusIconCountSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HOOK_STATUS_ICON_COUNT)
|
||||
binding.statusIconCountChildItem.isVisible = modulePrefs.get(DataConst.ENABLE_HOOK_STATUS_ICON_COUNT)
|
||||
binding.moduleEnableSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE)
|
||||
binding.moduleEnableLogSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE_LOG)
|
||||
binding.hideIconInLauncherSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HIDE_ICON)
|
||||
binding.colorIconCompatSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_COLOR_ICON_COMPAT)
|
||||
binding.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
|
||||
binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY)
|
||||
binding.statusIconCountText.text = statusBarIconCount.toString()
|
||||
binding.moduleEnableSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_MODULE, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_MODULE, b)
|
||||
binding.moduleEnableLogSwitch.isVisible = b
|
||||
binding.colorIconHookItem.isVisible = b
|
||||
binding.statusIconCountItem.isVisible = b
|
||||
@@ -168,13 +161,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
SystemUITool.showNeedRestartSnake(context = this)
|
||||
}
|
||||
binding.moduleEnableLogSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_MODULE_LOG, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_MODULE_LOG, b)
|
||||
SystemUITool.showNeedRestartSnake(context = this)
|
||||
}
|
||||
binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_HIDE_ICON, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_HIDE_ICON, b)
|
||||
packageManager.setComponentEnabledSetting(
|
||||
ComponentName(this@MainActivity, "com.fankes.miui.notify.Home"),
|
||||
if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||
@@ -182,26 +175,26 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
)
|
||||
}
|
||||
binding.statusIconCountSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_HOOK_STATUS_ICON_COUNT, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_HOOK_STATUS_ICON_COUNT, b)
|
||||
binding.statusIconCountChildItem.isVisible = b
|
||||
SystemUITool.showNeedRestartSnake(context = this)
|
||||
}
|
||||
binding.colorIconCompatSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_COLOR_ICON_COMPAT, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_COLOR_ICON_COMPAT, b)
|
||||
SystemUITool.refreshSystemUI(context = this)
|
||||
}
|
||||
binding.notifyIconFixSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX, b)
|
||||
binding.notifyIconFixButton.isVisible = b
|
||||
binding.notifyIconFixNotifyItem.isVisible = b
|
||||
SystemUITool.refreshSystemUI(context = this)
|
||||
}
|
||||
binding.notifyIconFixNotifySwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
|
||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||
modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
|
||||
SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
|
||||
}
|
||||
/** 通知图标优化名单按钮点击事件 */
|
||||
@@ -224,7 +217,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
!in 0..100 -> snake(msg = "请输入有效数值")
|
||||
editText.text.toString().isNotBlank() -> runCatching {
|
||||
statusBarIconCount = editText.text.toString().trim().toInt()
|
||||
modulePrefs.putInt(HOOK_STATUS_ICON_COUNT, statusBarIconCount)
|
||||
modulePrefs.put(DataConst.HOOK_STATUS_ICON_COUNT, statusBarIconCount)
|
||||
binding.statusIconCountText.text = statusBarIconCount.toString()
|
||||
SystemUITool.showNeedRestartSnake(context)
|
||||
}.onFailure { snake(msg = "数值格式无效") }
|
||||
@@ -249,24 +242,23 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
binding.mainLinStatus.setBackgroundResource(
|
||||
when {
|
||||
(isXposedModuleActive && isMiuiNotifyStyle) ||
|
||||
(isXposedModuleActive && (!isModuleRegular || !isModuleValied)) -> R.drawable.bg_yellow_round
|
||||
(isXposedModuleActive && (isModuleRegular.not() || isModuleValied.not())) -> R.drawable.bg_yellow_round
|
||||
isXposedModuleActive -> R.drawable.bg_green_round
|
||||
else -> R.drawable.bg_dark_round
|
||||
}
|
||||
)
|
||||
binding.mainImgStatus.setImageResource(
|
||||
when {
|
||||
isXposedModuleActive && !isMiuiNotifyStyle -> R.mipmap.ic_success
|
||||
isXposedModuleActive && isMiuiNotifyStyle.not() -> R.mipmap.ic_success
|
||||
else -> R.mipmap.ic_warn
|
||||
}
|
||||
)
|
||||
binding.mainTextStatus.text =
|
||||
when {
|
||||
isXposedModuleActive && isMiuiNotifyStyle -> "模块已激活,但未在工作"
|
||||
isXposedModuleActive && !isModuleRegular &&
|
||||
!modulePrefs.getBoolean(ENABLE_MODULE, default = true) -> "模块已停用"
|
||||
isXposedModuleActive && !isModuleRegular -> "模块已激活,请重启系统界面"
|
||||
isXposedModuleActive && !isModuleValied -> "模块已更新,请重启系统界面"
|
||||
isXposedModuleActive && isModuleRegular.not() && modulePrefs.get(DataConst.ENABLE_MODULE).not() -> "模块已停用"
|
||||
isXposedModuleActive && isModuleRegular.not() -> "模块已激活,请重启系统界面"
|
||||
isXposedModuleActive && isModuleValied.not() -> "模块已更新,请重启系统界面"
|
||||
isXposedModuleActive -> "模块已激活"
|
||||
else -> "模块未激活"
|
||||
}
|
||||
@@ -285,7 +277,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
refreshModuleStatus()
|
||||
}
|
||||
/** 经典样式启用后给出警告 */
|
||||
if (!isWarnDialogShowing && isXposedModuleActive && isMiuiNotifyStyle)
|
||||
if (isWarnDialogShowing.not() && isXposedModuleActive && isMiuiNotifyStyle)
|
||||
showDialog {
|
||||
isWarnDialogShowing = true
|
||||
title = "经典通知栏样式已启用"
|
||||
|
@@ -88,7 +88,7 @@ object BitmapCompatTool {
|
||||
ensureBufferSize(size)
|
||||
tempCompactBitmap?.getPixels(tempBuffer, 0, width, 0, 0, width, height)
|
||||
for (i in 0 until size)
|
||||
if (!isGrayscaleColor(tempBuffer[i])) {
|
||||
if (isGrayscaleColor(tempBuffer[i]).not()) {
|
||||
cachedBitmapGrayscales[bitmap.generationId] = false
|
||||
return@let false
|
||||
}
|
||||
|
@@ -39,10 +39,9 @@ import androidx.core.content.getSystemService
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import com.fankes.miui.notify.R
|
||||
import com.fankes.miui.notify.data.DataConst
|
||||
import com.fankes.miui.notify.databinding.DiaSourceFromBinding
|
||||
import com.fankes.miui.notify.databinding.DiaSourceFromStringBinding
|
||||
import com.fankes.miui.notify.hook.HookConst.SOURCE_SYNC_WAY
|
||||
import com.fankes.miui.notify.hook.HookConst.SOURCE_SYNC_WAY_CUSTOM_URL
|
||||
import com.fankes.miui.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_1
|
||||
import com.fankes.miui.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_2
|
||||
import com.fankes.miui.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_3
|
||||
@@ -81,8 +80,8 @@ object IconRuleManagerTool {
|
||||
fun syncByHand(context: Context, it: () -> Unit) =
|
||||
context.showDialog {
|
||||
title = "同步列表"
|
||||
var sourceType = context.modulePrefs.getInt(SOURCE_SYNC_WAY, TYPE_SOURCE_SYNC_WAY_1)
|
||||
var customUrl = context.modulePrefs.getString(SOURCE_SYNC_WAY_CUSTOM_URL)
|
||||
var sourceType = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY)
|
||||
var customUrl = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY_CUSTOM_URL)
|
||||
bind<DiaSourceFromBinding>().apply {
|
||||
diaSfText.apply {
|
||||
if (customUrl.isNotBlank()) {
|
||||
@@ -115,8 +114,8 @@ object IconRuleManagerTool {
|
||||
}
|
||||
}
|
||||
confirmButton {
|
||||
context.modulePrefs.putInt(SOURCE_SYNC_WAY, sourceType)
|
||||
context.modulePrefs.putString(SOURCE_SYNC_WAY_CUSTOM_URL, customUrl)
|
||||
context.modulePrefs.put(DataConst.SOURCE_SYNC_WAY, sourceType)
|
||||
context.modulePrefs.put(DataConst.SOURCE_SYNC_WAY_CUSTOM_URL, customUrl)
|
||||
sync(context, sourceType, customUrl, it)
|
||||
}
|
||||
cancelButton()
|
||||
@@ -174,8 +173,8 @@ object IconRuleManagerTool {
|
||||
*/
|
||||
fun sync(
|
||||
context: Context,
|
||||
sourceType: Int = context.modulePrefs.getInt(SOURCE_SYNC_WAY, TYPE_SOURCE_SYNC_WAY_1),
|
||||
customUrl: String = context.modulePrefs.getString(SOURCE_SYNC_WAY_CUSTOM_URL),
|
||||
sourceType: Int = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY),
|
||||
customUrl: String = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY_CUSTOM_URL),
|
||||
it: () -> Unit
|
||||
) {
|
||||
when (sourceType) {
|
||||
@@ -225,11 +224,11 @@ object IconRuleManagerTool {
|
||||
context is AppCompatActivity ->
|
||||
context.showDialog {
|
||||
title = "连接失败"
|
||||
msg = "连接失败,错误如下:\n${if (!isDone1) ctOS else ctAPP}"
|
||||
msg = "连接失败,错误如下:\n${if (isDone1.not()) ctOS else ctAPP}"
|
||||
confirmButton(text = "再试一次") { syncByHand(context, it) }
|
||||
cancelButton()
|
||||
}
|
||||
else -> pushNotify(context, title = "同步地址不可用", msg = if (!isDone1) ctOS else ctAPP)
|
||||
else -> pushNotify(context, title = "同步地址不可用", msg = if (isDone1.not()) ctOS else ctAPP)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user