From 5281464e4eb13e856d0b6727bde7a5d4b456eb76 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Mon, 28 Mar 2022 01:21:56 +0800 Subject: [PATCH] Update YukiHookAPI --- app/build.gradle | 4 +- .../fankes/coloros/notify/data/DataConst.kt | 46 ++++++++ .../fankes/coloros/notify/hook/HookConst.kt | 16 --- .../fankes/coloros/notify/hook/HookEntry.kt | 4 +- .../notify/hook/entity/SystemUIHooker.kt | 55 ++++----- .../notify/hook/factory/DataFactory.kt | 16 +-- .../coloros/notify/param/IconPackParams.kt | 6 +- .../notify/ui/activity/ConfigureActivity.kt | 6 +- .../notify/ui/activity/MainActivity.kt | 104 ++++++++---------- .../notify/utils/tool/IconRuleManagerTool.kt | 19 ++-- 10 files changed, 142 insertions(+), 134 deletions(-) create mode 100644 app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt diff --git a/app/build.gradle b/app/build.gradle index 240f4d2..42ba988 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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.tiann:FreeReflection:3.1.0' implementation "com.github.topjohnwu.libsu:core:3.1.2" implementation 'androidx.annotation:annotation:1.3.0' diff --git a/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt b/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt new file mode 100644 index 0000000..bbd2adf --- /dev/null +++ b/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt @@ -0,0 +1,46 @@ +/* + * ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications. + * Copyright (C) 2019-2022 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 2022/3/28. + */ +package com.fankes.coloros.notify.data + +import com.fankes.coloros.notify.hook.HookConst +import com.fankes.coloros.notify.utils.factory.isUpperOfAndroidS +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_ANDROID12_STYLE = PrefsData("_notify_android12_style", isUpperOfAndroidS) + val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true) + val ENABLE_NOTIFY_ICON_FIX_NOTIFY = PrefsData("_notify_icon_fix_notify", true) + val REMOVE_DEV_NOTIFY = PrefsData("_remove_dev_notify", true) + val REMOVE_CHANGECP_NOTIFY = PrefsData("_remove_charge_complete_notify", false) + val REMOVE_DNDALERT_NOTIFY = PrefsData("_remove_dndalert_notify", false) + 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 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", "") +} \ No newline at end of file diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt b/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt index f3120bc..d3d3dbb 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt @@ -24,22 +24,6 @@ package com.fankes.coloros.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_ANDROID12_STYLE = "_notify_android12_style" - const val ENABLE_NOTIFY_ICON_FIX = "_notify_icon_fix" - const val ENABLE_NOTIFY_ICON_FIX_NOTIFY = "_notify_icon_fix_notify" - const val REMOVE_DEV_NOTIFY = "_remove_dev_notify" - const val REMOVE_CHANGECP_NOTIFY = "_remove_charge_complete_notify" - const val REMOVE_DNDALERT_NOTIFY = "_remove_dndalert_notify" - 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 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 diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt b/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt index b15f4ec..3ad1a10 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt @@ -22,7 +22,7 @@ */ package com.fankes.coloros.notify.hook -import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE +import com.fankes.coloros.notify.data.DataConst import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME import com.fankes.coloros.notify.hook.entity.SystemUIHooker import com.fankes.coloros.notify.utils.factory.isNotColorOS @@ -46,7 +46,7 @@ class HookEntry : YukiHookXposedInitProxy { /** 不是 ColorOS 系统停止 Hook */ isNotColorOS -> loggerW(msg = "Aborted Hook -> This System is not ColorOS") /** 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()) } 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 f5e0be2..a212d0d 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 @@ -20,6 +20,8 @@ * * This file is Created by fankes on 2022/3/25. */ +@file:Suppress("Recycle") + package com.fankes.coloros.notify.hook.entity import android.app.WallpaperManager @@ -41,16 +43,8 @@ import android.widget.ImageView import androidx.core.graphics.drawable.toBitmap import com.fankes.coloros.notify.bean.IconDataBean import com.fankes.coloros.notify.const.Const +import com.fankes.coloros.notify.data.DataConst import com.fankes.coloros.notify.hook.HookConst.ANDROID_PACKAGE_NAME -import com.fankes.coloros.notify.hook.HookConst.ENABLE_ANDROID12_STYLE -import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE_LOG -import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX -import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_AUTO -import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY -import com.fankes.coloros.notify.hook.HookConst.NOTIFY_ICON_FIX_AUTO_TIME -import com.fankes.coloros.notify.hook.HookConst.REMOVE_CHANGECP_NOTIFY -import com.fankes.coloros.notify.hook.HookConst.REMOVE_DEV_NOTIFY -import com.fankes.coloros.notify.hook.HookConst.REMOVE_DNDALERT_NOTIFY import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME import com.fankes.coloros.notify.hook.factory.isAppNotifyHookAllOf import com.fankes.coloros.notify.hook.factory.isAppNotifyHookOf @@ -243,8 +237,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) /** * 判断通知是否来自系统推送 @@ -267,7 +260,7 @@ class SystemUIHooker : YukiBaseHooker() { isCustom: Boolean, isGrayscale: Boolean ) { - if (prefs.getBoolean(ENABLE_MODULE_LOG)) loggerD( + if (prefs.get(DataConst.ENABLE_MODULE_LOG)) loggerD( msg = "$tag --> [${context.findAppName(packageName)}][$packageName] " + "custom [$isCustom] " + "grayscale [$isGrayscale]" @@ -281,7 +274,7 @@ class SystemUIHooker : YukiBaseHooker() { * @param view 实例 */ private fun registerWallpaperColorChanged(view: View) = runInSafe { - if (!isWallpaperColorListenerSetUp && isUpperOfAndroidS) view.apply { + if (isWallpaperColorListenerSetUp.not() && isUpperOfAndroidS) view.apply { WallpaperManager.getInstance(context).addOnColorsChangedListener({ _, _ -> refreshNotificationIcons() }, handler) } isWallpaperColorListenerSetUp = true @@ -377,18 +370,17 @@ class SystemUIHooker : YukiBaseHooker() { var customPair: Pair? = null when { /** 替换系统图标为 Android 默认 */ - (packageName == ANDROID_PACKAGE_NAME || packageName == SYSTEMUI_PACKAGE_NAME) && !isGrayscaleIcon -> + (packageName == ANDROID_PACKAGE_NAME || packageName == SYSTEMUI_PACKAGE_NAME) && isGrayscaleIcon.not() -> customPair = Pair(if (isUpperOfAndroidS) IconPackParams.android12IconBitmap else IconPackParams.android11IconBitmap, 0) /** 替换自定义通知图标 */ - prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) -> run { - if (iconDatas.isNotEmpty()) - iconDatas.forEach { - if (packageName == it.packageName && isAppNotifyHookOf(it)) { - if (!isGrayscaleIcon || isAppNotifyHookAllOf(it)) - customPair = Pair(it.iconBitmap, it.iconColor) - return@run - } + prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) -> run { + iconDatas.takeIf { it.isNotEmpty() }?.forEach { + if (packageName == it.packageName && isAppNotifyHookOf(it)) { + if (isGrayscaleIcon.not() || isAppNotifyHookAllOf(it)) + customPair = Pair(it.iconBitmap, it.iconColor) + return@run } + } } } return customPair ?: Pair(null, 0) @@ -413,7 +405,7 @@ class SystemUIHooker : YukiBaseHooker() { /** 打印日志 */ printLogcat(tag = "StatusIcon", context, packageName, isCustom = it != null, isGrayscaleIcon) }?.let { Pair(BitmapDrawable(context.resources, it), true) } - ?: Pair(if (isGrayscaleIcon) drawable else nf.compatPushingIcon(drawable), !isGrayscaleIcon) + ?: Pair(if (isGrayscaleIcon) drawable else nf.compatPushingIcon(drawable), isGrayscaleIcon.not()) /** * 自动适配通知栏小图标 @@ -443,7 +435,7 @@ class SystemUIHooker : YukiBaseHooker() { setImageBitmap(customPair.first ?: drawable.toBitmap()) /** 是否开启 Android 12 风格 */ - val isA12Style = prefs.getBoolean(ENABLE_ANDROID12_STYLE, isUpperOfAndroidS) + val isA12Style = prefs.get(DataConst.ENABLE_ANDROID12_STYLE) /** 旧版风格 */ val oldStyle = (if (context.isSystemInDarkMode) 0xffdcdcdc else 0xff707173).toInt() @@ -532,7 +524,7 @@ class SystemUIHooker : YukiBaseHooker() { method { name = "updateDeveloperMode" } beforeHook { /** 是否移除 */ - if (prefs.getBoolean(REMOVE_DEV_NOTIFY, default = true)) resultNull() + if (prefs.get(DataConst.REMOVE_DEV_NOTIFY)) resultNull() } } } @@ -545,7 +537,7 @@ class SystemUIHooker : YukiBaseHooker() { } beforeHook { /** 是否移除 */ - if (firstArgs() == 7 && prefs.getBoolean(REMOVE_CHANGECP_NOTIFY)) resultNull() + if (args().ofInt() == 7 && prefs.get(DataConst.REMOVE_CHANGECP_NOTIFY)) resultNull() } } } @@ -558,7 +550,7 @@ class SystemUIHooker : YukiBaseHooker() { } beforeHook { /** 是否移除 */ - if (prefs.getBoolean(REMOVE_DNDALERT_NOTIFY)) resultNull() + if (prefs.get(DataConst.REMOVE_DNDALERT_NOTIFY)) resultNull() } } } @@ -591,7 +583,8 @@ class SystemUIHooker : YukiBaseHooker() { nf = nf, isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable).also { /** 缓存第一次的 APP 小图标 */ - if (!it) context.findAppIcon(nf.packageName)?.also { e -> appIcons[nf.packageName] = e } + if (it.not()) context.findAppIcon(nf.packageName) + ?.also { e -> appIcons[nf.packageName] = e } }, packageName = nf.packageName, drawable = iconDrawable @@ -671,7 +664,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) { @@ -700,11 +693,11 @@ class SystemUIHooker : YukiBaseHooker() { param(ContextClass, IntentClass) } 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 = firstArgs()!!, // TODO 设置 UI 界面设置定时更新规则 - timeSet = prefs.getString(NOTIFY_ICON_FIX_AUTO_TIME, default = "07:00") + timeSet = prefs.get(DataConst.NOTIFY_ICON_FIX_AUTO_TIME) ) } } diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt b/app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt index ed78bcc..2d22ab0 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt @@ -31,40 +31,36 @@ 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 的通知图标 * @param bean 图标 bean * @param isHook 是否 Hook */ -fun Context.putAppNotifyHookOf(bean: IconDataBean, isHook: Boolean) = - modulePrefs.putBoolean(key = bean.toEnabledName(), value = isHook) +fun Context.putAppNotifyHookOf(bean: IconDataBean, isHook: Boolean) = modulePrefs.putBoolean(bean.toEnabledName(), isHook) /** * 获取此 APP 的通知图标是否被全部 Hook * @param bean 图标 bean */ -fun PackageParam.isAppNotifyHookAllOf(bean: IconDataBean) = - prefs.getBoolean(key = bean.toEnabledAllName(), default = bean.isEnabledAll) +fun PackageParam.isAppNotifyHookAllOf(bean: IconDataBean) = prefs.getBoolean(bean.toEnabledAllName(), bean.isEnabledAll) /** * 获取此 APP 的通知图标是否被全部 Hook * @param bean 图标 bean */ -fun Context.isAppNotifyHookAllOf(bean: IconDataBean) = - modulePrefs.getBoolean(key = bean.toEnabledAllName(), default = bean.isEnabledAll) +fun Context.isAppNotifyHookAllOf(bean: IconDataBean) = modulePrefs.getBoolean(bean.toEnabledAllName(), bean.isEnabledAll) /** * 设置全部 Hook 此 APP 的通知图标 * @param bean 图标 bean * @param isHook 是否 Hook */ -fun Context.putAppNotifyHookAllOf(bean: IconDataBean, isHook: Boolean) = - modulePrefs.putBoolean(key = bean.toEnabledAllName(), value = isHook) \ No newline at end of file +fun Context.putAppNotifyHookAllOf(bean: IconDataBean, isHook: Boolean) = modulePrefs.putBoolean(bean.toEnabledAllName(), isHook) \ No newline at end of file diff --git a/app/src/main/java/com/fankes/coloros/notify/param/IconPackParams.kt b/app/src/main/java/com/fankes/coloros/notify/param/IconPackParams.kt index 562737c..202f27f 100644 --- a/app/src/main/java/com/fankes/coloros/notify/param/IconPackParams.kt +++ b/app/src/main/java/com/fankes/coloros/notify/param/IconPackParams.kt @@ -28,7 +28,7 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.Color import com.fankes.coloros.notify.bean.IconDataBean -import com.fankes.coloros.notify.hook.HookConst.NOTIFY_ICON_DATAS +import com.fankes.coloros.notify.data.DataConst import com.fankes.coloros.notify.utils.factory.* import com.highcapable.yukihookapi.hook.factory.modulePrefs import com.highcapable.yukihookapi.hook.param.PackageParam @@ -101,7 +101,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) /** * 获取图标数据 @@ -188,5 +188,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) } diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/ConfigureActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/ConfigureActivity.kt index 00d2bd3..c0a4ac5 100644 --- a/app/src/main/java/com/fankes/coloros/notify/ui/activity/ConfigureActivity.kt +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/ConfigureActivity.kt @@ -61,7 +61,7 @@ class ConfigureActivity : BaseActivity() { override fun onCreate() { /** 检查激活状态 */ - if (!isXposedModuleActive) { + if (isXposedModuleActive.not()) { showDialog { title = "模块没有激活" msg = "模块没有激活,你无法使用这里的功能,请先激活模块。" @@ -146,14 +146,14 @@ class ConfigureActivity : BaseActivity() { 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) } diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt index e9c0dec..ccbf018 100644 --- a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt @@ -29,16 +29,8 @@ import android.content.pm.PackageManager import androidx.core.view.isVisible import com.fankes.coloros.notify.BuildConfig import com.fankes.coloros.notify.R +import com.fankes.coloros.notify.data.DataConst import com.fankes.coloros.notify.databinding.ActivityMainBinding -import com.fankes.coloros.notify.hook.HookConst.ENABLE_ANDROID12_STYLE -import com.fankes.coloros.notify.hook.HookConst.ENABLE_HIDE_ICON -import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE -import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE_LOG -import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX -import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY -import com.fankes.coloros.notify.hook.HookConst.REMOVE_CHANGECP_NOTIFY -import com.fankes.coloros.notify.hook.HookConst.REMOVE_DEV_NOTIFY -import com.fankes.coloros.notify.hook.HookConst.REMOVE_DNDALERT_NOTIFY import com.fankes.coloros.notify.param.IconPackParams import com.fankes.coloros.notify.ui.activity.base.BaseActivity import com.fankes.coloros.notify.utils.factory.* @@ -89,17 +81,16 @@ class MainActivity : BaseActivity() { } /** 判断是否 Hook */ isXposedModuleActive -> { - if (IconPackParams(context = this).iconDatas.isEmpty() - && modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) - ) showDialog { - title = "配置通知图标优化名单" - msg = "模块需要获取在线规则以更新“通知图标优化名单”,它现在是空的,这看起来是你第一次使用模块,请首先进行配置才可以使用相关功能。\n" + - "你可以随时在本页面下方找到“配置通知图标优化名单”手动前往。" - confirmButton(text = "前往") { navigate() } - cancelButton() - noCancelable() - } - if (isNotNoificationEnabled && modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)) + if (IconPackParams(context = this).iconDatas.isEmpty() && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)) + showDialog { + title = "配置通知图标优化名单" + msg = "模块需要获取在线规则以更新“通知图标优化名单”,它现在是空的,这看起来是你第一次使用模块,请首先进行配置才可以使用相关功能。\n" + + "你可以随时在本页面下方找到“配置通知图标优化名单”手动前往。" + confirmButton(text = "前往") { navigate() } + cancelButton() + noCancelable() + } + if (isNotNoificationEnabled && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)) showDialog { title = "模块的通知权限已关闭" msg = "请开启通知权限,以确保你能收到通知优化图标在线规则的更新。" @@ -120,23 +111,23 @@ class MainActivity : BaseActivity() { } } /** 获取 Sp 存储的信息 */ - binding.devNotifyConfigItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true) - binding.a12StyleConfigItem.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.devNotifyConfigSwitch.isChecked = modulePrefs.getBoolean(REMOVE_DEV_NOTIFY, default = true) - binding.crcpNotifyConfigSwitch.isChecked = modulePrefs.getBoolean(REMOVE_CHANGECP_NOTIFY) - binding.dndNotifyConfigSwitch.isChecked = modulePrefs.getBoolean(REMOVE_DNDALERT_NOTIFY) - binding.a12StyleConfigSwitch.isChecked = modulePrefs.getBoolean(ENABLE_ANDROID12_STYLE, isUpperOfAndroidS) - 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.notifyIconFixSwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) - binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true) + binding.devNotifyConfigItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE) + binding.a12StyleConfigItem.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.devNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_DEV_NOTIFY) + binding.crcpNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_CHANGECP_NOTIFY) + binding.dndNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_DNDALERT_NOTIFY) + binding.a12StyleConfigSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_ANDROID12_STYLE) + 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.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) + binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY) 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.notifyIconConfigItem.isVisible = b binding.devNotifyConfigItem.isVisible = b @@ -144,13 +135,13 @@ class MainActivity : BaseActivity() { 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(packageName, "com.fankes.coloros.notify.Home"), if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED, @@ -158,35 +149,35 @@ class MainActivity : BaseActivity() { ) } 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) } binding.devNotifyConfigSwitch.setOnCheckedChangeListener { btn, b -> - if (!btn.isPressed) return@setOnCheckedChangeListener - modulePrefs.putBoolean(REMOVE_DEV_NOTIFY, b) + if (btn.isPressed.not()) return@setOnCheckedChangeListener + modulePrefs.put(DataConst.REMOVE_DEV_NOTIFY, b) SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true) } binding.crcpNotifyConfigSwitch.setOnCheckedChangeListener { btn, b -> - if (!btn.isPressed) return@setOnCheckedChangeListener - modulePrefs.putBoolean(REMOVE_CHANGECP_NOTIFY, b) + if (btn.isPressed.not()) return@setOnCheckedChangeListener + modulePrefs.put(DataConst.REMOVE_CHANGECP_NOTIFY, b) SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true) } binding.dndNotifyConfigSwitch.setOnCheckedChangeListener { btn, b -> - if (!btn.isPressed) return@setOnCheckedChangeListener - modulePrefs.putBoolean(REMOVE_DNDALERT_NOTIFY, b) + if (btn.isPressed.not()) return@setOnCheckedChangeListener + modulePrefs.put(DataConst.REMOVE_DNDALERT_NOTIFY, b) SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true) } binding.a12StyleConfigSwitch.setOnCheckedChangeListener { btn, b -> - if (!btn.isPressed) return@setOnCheckedChangeListener - modulePrefs.putBoolean(ENABLE_ANDROID12_STYLE, b) + if (btn.isPressed.not()) return@setOnCheckedChangeListener + modulePrefs.put(DataConst.ENABLE_ANDROID12_STYLE, b) SystemUITool.refreshSystemUI(context = this) } /** 通知图标优化名单按钮点击事件 */ @@ -205,7 +196,7 @@ class MainActivity : BaseActivity() { private fun refreshModuleStatus() { binding.mainLinStatus.setBackgroundResource( when { - 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 } @@ -218,10 +209,9 @@ class MainActivity : BaseActivity() { ) binding.mainTextStatus.text = when { - 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 -> "模块未激活" } diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconRuleManagerTool.kt b/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconRuleManagerTool.kt index 42791b9..112d481 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconRuleManagerTool.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconRuleManagerTool.kt @@ -39,10 +39,9 @@ import androidx.core.content.getSystemService import androidx.core.view.isVisible import androidx.core.widget.doOnTextChanged import com.fankes.coloros.notify.R +import com.fankes.coloros.notify.data.DataConst import com.fankes.coloros.notify.databinding.DiaSourceFromBinding import com.fankes.coloros.notify.databinding.DiaSourceFromStringBinding -import com.fankes.coloros.notify.hook.HookConst.SOURCE_SYNC_WAY -import com.fankes.coloros.notify.hook.HookConst.SOURCE_SYNC_WAY_CUSTOM_URL import com.fankes.coloros.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_1 import com.fankes.coloros.notify.hook.HookConst.TYPE_SOURCE_SYNC_WAY_2 import com.fankes.coloros.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().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) } } }