diff --git a/app/src/main/java/com/fankes/coloros/notify/application/CNNApplication.kt b/app/src/main/java/com/fankes/coloros/notify/application/CNNApplication.kt
index fee0776..e6d5724 100644
--- a/app/src/main/java/com/fankes/coloros/notify/application/CNNApplication.kt
+++ b/app/src/main/java/com/fankes/coloros/notify/application/CNNApplication.kt
@@ -25,6 +25,7 @@
package com.fankes.coloros.notify.application
import androidx.appcompat.app.AppCompatDelegate
+import com.fankes.coloros.notify.data.ConfigData
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
class CNNApplication : ModuleApplication() {
@@ -33,5 +34,7 @@ class CNNApplication : ModuleApplication() {
super.onCreate()
/** 跟随系统夜间模式 */
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
+ /** 装载存储控制类 */
+ ConfigData.init(instance = this)
}
}
\ 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/const/ConstFactory.kt
similarity index 61%
rename from app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt
rename to app/src/main/java/com/fankes/coloros/notify/const/ConstFactory.kt
index d3d3dbb..f8912e2 100644
--- a/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt
+++ b/app/src/main/java/com/fankes/coloros/notify/const/ConstFactory.kt
@@ -18,16 +18,33 @@
* and eula along with this software. If not, see
*
*
- * This file is Created by fankes on 2022/1/24.
+ * This file is Created by fankes on 2023/2/2.
*/
-package com.fankes.coloros.notify.hook
+package com.fankes.coloros.notify.const
-object HookConst {
+/**
+ * 包名常量定义类
+ */
+object PackageName {
- const val TYPE_SOURCE_SYNC_WAY_1 = 1000
- const val TYPE_SOURCE_SYNC_WAY_2 = 2000
- const val TYPE_SOURCE_SYNC_WAY_3 = 3000
+ /** 系统框架 */
+ const val SYSTEM_FRAMEWORK = "android"
- const val ANDROID_PACKAGE_NAME = "android"
- const val SYSTEMUI_PACKAGE_NAME = "com.android.systemui"
+ /** 系统界面 (系统 UI) */
+ const val SYSTEMUI = "com.android.systemui"
+}
+
+/**
+ * 通知图标优化名单同步方式定义类
+ */
+object IconRuleSourceSyncType {
+
+ /** Github Raw (代理) */
+ const val GITHUB_RAW_PROXY = 1000
+
+ /** Github Raw (直连) */
+ const val GITHUB_RAW_DIRECT = 2000
+
+ /** 自定义地址 */
+ const val CUSTOM_URL = 3000
}
\ No newline at end of file
diff --git a/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt b/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt
new file mode 100644
index 0000000..e970b97
--- /dev/null
+++ b/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt
@@ -0,0 +1,363 @@
+/*
+ * 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 2023/2/2.
+ */
+@file:Suppress("MemberVisibilityCanBePrivate")
+
+package com.fankes.coloros.notify.data
+
+import android.content.Context
+import com.fankes.coloros.notify.const.IconRuleSourceSyncType
+import com.fankes.coloros.notify.utils.factory.isUpperOfAndroidS
+import com.highcapable.yukihookapi.hook.factory.modulePrefs
+import com.highcapable.yukihookapi.hook.log.loggerW
+import com.highcapable.yukihookapi.hook.param.PackageParam
+import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
+
+/**
+ * 全局配置存储控制类
+ */
+object ConfigData {
+
+ /** 启用模块 */
+ val ENABLE_MODULE = PrefsData("_enable_module", true)
+
+ /** 启用模块日志 */
+ val ENABLE_MODULE_LOG = PrefsData("_enable_module_log", false)
+
+ /** 启用通知图标兼容模式 */
+ val ENABLE_COLOR_ICON_COMPAT = PrefsData("_color_icon_compat", false)
+
+ /** 移除开发者选项警告通知 */
+ val ENABLE_REMOVE_DEV_NOTIFY = PrefsData("_remove_dev_notify", true)
+
+ /** 移除充电完成通知 */
+ val ENABLE_REMOVE_CHANGE_COMPLETE_NOTIFY = PrefsData("_remove_charge_complete_notify", false)
+
+ /** 移除免打扰通知 */
+ val ENABLE_REMOVE_DND_ALERT_NOTIFY = PrefsData("_remove_dndalert_notify", false)
+
+ /** 启用 Material 3 通知图标风格 */
+ val ENABLE_MD3_NOTIFY_ICON_STYLE = PrefsData("_notify_icon_md3_style", isUpperOfAndroidS)
+
+ /** 通知栏中的通知图标圆角程度 */
+ val NOTIFY_ICON_CORNER_SIZE = PrefsData("_notify_icon_corner", 15)
+
+ /** 强制通知栏中的通知图标为 APP 图标 */
+ val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false)
+
+ /** 启用媒体通知播放时自动展开 */
+ val ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP = PrefsData("_enable_notify_media_panel_auto_exp", false)
+
+ /** 启用自定义通知面板背景透明度 */
+ val ENABLE_NOTIFY_PANEL_ALPHA = PrefsData("_enable_notify_panel_alpha", false)
+
+ /** 自定义通知面板背景透明度 */
+ val NOTIFY_PANEL_ALPHA_LEVEL = PrefsData("_notify_panel_alpha_pst", 75)
+
+ /** 启用通知图标优化 */
+ val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true)
+
+ /** 提醒未适配通知图标的新安装应用 */
+ val ENABLE_NOTIFY_ICON_FIX_NOTIFY = PrefsData("_notify_icon_fix_notify", true)
+
+ /** 启用通知图标优化名单自动更新 */
+ val ENABLE_NOTIFY_ICON_FIX_AUTO = PrefsData("_enable_notify_icon_fix_auto", true)
+
+ /** 通知图标优化名单自动更新时间 */
+ val NOTIFY_ICON_FIX_AUTO_TIME = PrefsData("_notify_icon_fix_auto_time", "07:00")
+
+ /** 通知图标优化适配数据 */
+ val NOTIFY_ICONS_DATA = PrefsData("_notify_icon_datas", "")
+
+ /** 通知图标优化名单同步方式 */
+ val ICON_RULE_SOURCE_SYNC_TYPE = PrefsData("_rule_source_sync_way", IconRuleSourceSyncType.GITHUB_RAW_PROXY)
+
+ /** 通知图标优化名单同步地址 */
+ val ICON_RULE_SOURCE_SYNC_CUSTOM_URL = PrefsData("_rule_source_sync_way_custom_url", "")
+
+ /** 当前实例 - [Context] or [PackageParam] */
+ private var instance: Any? = null
+
+ /**
+ * 初始化存储控制类
+ * @param instance 实例 - 只能是 [Context] or [PackageParam]
+ * @throws IllegalStateException 如果类型错误
+ */
+ fun init(instance: Any) {
+ when (instance) {
+ is Context, is PackageParam -> this.instance = instance
+ else -> error("Unknown type for init ConfigData")
+ }
+ }
+
+ /**
+ * 读取 [Int] 数据
+ * @param data 键值数据模板
+ * @return [Int]
+ */
+ private fun getInt(data: PrefsData) = when (instance) {
+ is Context -> (instance as Context).modulePrefs.get(data)
+ is PackageParam -> (instance as PackageParam).prefs.get(data)
+ else -> error("Unknown type for get prefs data")
+ }
+
+ /**
+ * 存入 [Int] 数据
+ * @param data 键值数据模板
+ * @param value 键值内容
+ */
+ private fun putInt(data: PrefsData, value: Int) {
+ when (instance) {
+ is Context -> (instance as Context).modulePrefs.put(data, value)
+ is PackageParam -> loggerW(msg = "Not support for this method")
+ else -> error("Unknown type for put prefs data")
+ }
+ }
+
+ /**
+ * 读取 [String] 数据
+ * @param data 键值数据模板
+ * @return [String]
+ */
+ private fun getString(data: PrefsData) = when (instance) {
+ is Context -> (instance as Context).modulePrefs.get(data)
+ is PackageParam -> (instance as PackageParam).prefs.get(data)
+ else -> error("Unknown type for get prefs data")
+ }
+
+ /**
+ * 存入 [String] 数据
+ * @param data 键值数据模板
+ * @param value 键值内容
+ */
+ private fun putString(data: PrefsData, value: String) {
+ when (instance) {
+ is Context -> (instance as Context).modulePrefs.put(data, value)
+ is PackageParam -> loggerW(msg = "Not support for this method")
+ else -> error("Unknown type for put prefs data")
+ }
+ }
+
+ /**
+ * 读取 [Boolean] 数据
+ * @param data 键值数据模板
+ * @return [Boolean]
+ */
+ internal fun getBoolean(data: PrefsData) = when (instance) {
+ is Context -> (instance as Context).modulePrefs.get(data)
+ is PackageParam -> (instance as PackageParam).prefs.get(data)
+ else -> error("Unknown type for get prefs data")
+ }
+
+ /**
+ * 存入 [Boolean] 数据
+ * @param data 键值数据模板
+ * @param value 键值内容
+ */
+ internal fun putBoolean(data: PrefsData, value: Boolean) {
+ when (instance) {
+ is Context -> (instance as Context).modulePrefs.put(data, value)
+ is PackageParam -> loggerW(msg = "Not support for this method")
+ else -> error("Unknown type for put prefs data")
+ }
+ }
+
+ /**
+ * 是否启用模块
+ * @return [Boolean]
+ */
+ var isEnableModule
+ get() = getBoolean(ENABLE_MODULE)
+ set(value) {
+ putBoolean(ENABLE_MODULE, value)
+ }
+
+ /**
+ * 是否启用模块日志
+ * @return [Boolean]
+ */
+ var isEnableModuleLog
+ get() = getBoolean(ENABLE_MODULE_LOG)
+ set(value) {
+ putBoolean(ENABLE_MODULE_LOG, value)
+ }
+
+ /**
+ * 是否启用通知图标兼容模式
+ * @return [Boolean]
+ */
+ var isEnableColorIconCompat
+ get() = getBoolean(ENABLE_COLOR_ICON_COMPAT)
+ set(value) {
+ putBoolean(ENABLE_COLOR_ICON_COMPAT, value)
+ }
+
+ /**
+ * 是否移除开发者选项警告通知
+ * @return [Boolean]
+ */
+ var isEnableRemoveDevNotify
+ get() = getBoolean(ENABLE_REMOVE_DEV_NOTIFY)
+ set(value) {
+ putBoolean(ENABLE_REMOVE_DEV_NOTIFY, value)
+ }
+
+ /**
+ * 是否移除充电完成通知
+ * @return [Boolean]
+ */
+ var isEnableRemoveChangeCompleteNotify
+ get() = getBoolean(ENABLE_REMOVE_CHANGE_COMPLETE_NOTIFY)
+ set(value) {
+ putBoolean(ENABLE_REMOVE_CHANGE_COMPLETE_NOTIFY, value)
+ }
+
+ /**
+ * 是否移除免打扰通知
+ * @return [Boolean]
+ */
+ var isEnableRemoveDndAlertNotify
+ get() = getBoolean(ENABLE_REMOVE_DND_ALERT_NOTIFY)
+ set(value) {
+ putBoolean(ENABLE_REMOVE_DND_ALERT_NOTIFY, value)
+ }
+
+ /**
+ * 是否启用 material 3 通知图标风格
+ * @return [Boolean]
+ */
+ var isEnableMd3NotifyIconStyle
+ get() = getBoolean(ENABLE_MD3_NOTIFY_ICON_STYLE)
+ set(value) {
+ putBoolean(ENABLE_MD3_NOTIFY_ICON_STYLE, value)
+ }
+
+ /**
+ * 通知栏中的通知图标圆角程度
+ * @return [Int]
+ */
+ var notifyIconCornerSize
+ get() = getInt(NOTIFY_ICON_CORNER_SIZE)
+ set(value) {
+ putInt(NOTIFY_ICON_CORNER_SIZE, value)
+ }
+
+ /**
+ * 是否强制通知栏中的通知图标为 APP 图标
+ * @return [Boolean]
+ */
+ var isEnableNotifyIconForceAppIcon
+ get() = getBoolean(ENABLE_NOTIFY_ICON_FORCE_APP_ICON)
+ set(value) {
+ putBoolean(ENABLE_NOTIFY_ICON_FORCE_APP_ICON, value)
+ }
+
+ /**
+ * 是否启用媒体通知播放时自动展开
+ * @return [Boolean]
+ */
+ var isEnableNotifyMediaPanelAutoExp
+ get() = getBoolean(ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP)
+ set(value) {
+ putBoolean(ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP, value)
+ }
+
+ /**
+ * 是否启用自定义通知面板背景透明度
+ * @return [Boolean]
+ */
+ var isEnableNotifyPanelAlpha
+ get() = getBoolean(ENABLE_NOTIFY_PANEL_ALPHA)
+ set(value) {
+ putBoolean(ENABLE_NOTIFY_PANEL_ALPHA, value)
+ }
+
+ /**
+ * 自定义通知面板背景透明度
+ * @return [Int]
+ */
+ var notifyPanelAlphaLevel
+ get() = getInt(NOTIFY_PANEL_ALPHA_LEVEL)
+ set(value) {
+ putInt(NOTIFY_PANEL_ALPHA_LEVEL, value)
+ }
+
+ /**
+ * 是否启用通知图标优化
+ * @return [Boolean]
+ */
+ var isEnableNotifyIconFix
+ get() = getBoolean(ENABLE_NOTIFY_ICON_FIX)
+ set(value) {
+ putBoolean(ENABLE_NOTIFY_ICON_FIX, value)
+ }
+
+ /**
+ * 是否提醒未适配通知图标的新安装应用
+ * @return [Boolean]
+ */
+ var isEnableNotifyIconFixNotify
+ get() = getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY)
+ set(value) {
+ putBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, value)
+ }
+
+ /**
+ * 是否启用通知图标优化名单自动更新
+ * @return [Boolean]
+ */
+ var isEnableNotifyIconFixAuto
+ get() = getBoolean(ENABLE_NOTIFY_ICON_FIX_AUTO)
+ set(value) {
+ putBoolean(ENABLE_NOTIFY_ICON_FIX_AUTO, value)
+ }
+
+ /**
+ * 通知图标优化名单自动更新时间
+ * @return [String]
+ */
+ var notifyIconFixAutoTime
+ get() = getString(NOTIFY_ICON_FIX_AUTO_TIME)
+ set(value) {
+ putString(NOTIFY_ICON_FIX_AUTO_TIME, value)
+ }
+
+ /**
+ * 通知图标优化名单同步方式
+ * @return [Int]
+ */
+ var iconRuleSourceSyncType
+ get() = getInt(ICON_RULE_SOURCE_SYNC_TYPE)
+ set(value) {
+ putInt(ICON_RULE_SOURCE_SYNC_TYPE, value)
+ }
+
+ /**
+ * 通知图标优化名单同步地址
+ * @return [String]
+ */
+ var iconRuleSourceSyncCustomUrl
+ get() = getString(ICON_RULE_SOURCE_SYNC_CUSTOM_URL)
+ set(value) {
+ putString(ICON_RULE_SOURCE_SYNC_CUSTOM_URL, value)
+ }
+}
\ No newline at end of file
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
deleted file mode 100644
index 75ced94..0000000
--- a/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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_COLOR_ICON_COMPAT = PrefsData("_color_icon_compat", false)
- val ENABLE_MD3_NOTIFY_ICON_STYLE = PrefsData("_notify_icon_md3_style", isUpperOfAndroidS)
- val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true)
- val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false)
- 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 ENABLE_NOTIFY_PANEL_ALPHA = PrefsData("_enable_notify_panel_alpha", false)
- val ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP = PrefsData("_enable_notify_media_panel_auto_exp", false)
- val NOTIFY_ICON_CORNER = PrefsData("_notify_icon_corner", 10)
- val NOTIFY_PANEL_ALPHA = PrefsData("_notify_panel_alpha_pst", 75)
- 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/data/factory/CompoundButtonFactory.kt b/app/src/main/java/com/fankes/coloros/notify/data/factory/CompoundButtonFactory.kt
new file mode 100644
index 0000000..cf89fd5
--- /dev/null
+++ b/app/src/main/java/com/fankes/coloros/notify/data/factory/CompoundButtonFactory.kt
@@ -0,0 +1,102 @@
+/*
+ * 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 2023/2/3.
+ */
+@file:Suppress("unused", "MemberVisibilityCanBePrivate")
+
+package com.fankes.coloros.notify.data.factory
+
+import android.widget.CompoundButton
+import com.fankes.coloros.notify.data.ConfigData
+import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
+
+/**
+ * 绑定到 [CompoundButton] 自动设置选中状态
+ * @param data 键值数据模板
+ * @param initiate 方法体
+ */
+fun CompoundButton.bind(data: PrefsData, initiate: CompoundButtonDataBinder.(CompoundButton) -> Unit = {}) {
+ val binder = CompoundButtonDataBinder(button = this).also { initiate(it, this) }
+ isChecked = ConfigData.getBoolean(data).also { binder.initializeCallback?.invoke(it) }
+ binder.applyChangesCallback = { ConfigData.putBoolean(data, it) }
+ setOnCheckedChangeListener { button, isChecked ->
+ if (button.isPressed) {
+ if (binder.isAutoApplyChanges) binder.applyChangesCallback?.invoke(isChecked)
+ binder.changedCallback?.invoke(isChecked)
+ }
+ }
+}
+
+/**
+ * [CompoundButton] 数据绑定管理器实例
+ * @param button 当前实例
+ */
+class CompoundButtonDataBinder(private val button: CompoundButton) {
+
+ /** 状态初始化回调事件 */
+ internal var initializeCallback: ((Boolean) -> Unit)? = null
+
+ /** 状态改变回调事件 */
+ internal var changedCallback: ((Boolean) -> Unit)? = null
+
+ /** 应用更改回调事件 */
+ internal var applyChangesCallback: ((Boolean) -> Unit)? = null
+
+ /** 是否启用自动应用更改 */
+ var isAutoApplyChanges = true
+
+ /**
+ * 监听状态初始化
+ * @param result 回调结果
+ */
+ fun onInitialize(result: (Boolean) -> Unit) {
+ initializeCallback = result
+ }
+
+ /**
+ * 监听状态改变
+ * @param result 回调结果
+ */
+ fun onChanged(result: (Boolean) -> Unit) {
+ changedCallback = result
+ }
+
+ /** 重新初始化 */
+ fun reinitialize() {
+ initializeCallback?.invoke(button.isChecked)
+ }
+
+ /** 应用更改并重新初始化 */
+ fun applyChangesAndReinitialize() {
+ applyChanges()
+ reinitialize()
+ }
+
+ /** 应用更改 */
+ fun applyChanges() {
+ applyChangesCallback?.invoke(button.isChecked)
+ }
+
+ /** 取消更改 */
+ fun cancelChanges() {
+ button.isChecked = button.isChecked.not()
+ }
+}
\ No newline at end of file
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 4f8fc4b..c381852 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,8 +22,8 @@
*/
package com.fankes.coloros.notify.hook
-import com.fankes.coloros.notify.data.DataConst
-import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
+import com.fankes.coloros.notify.const.PackageName
+import com.fankes.coloros.notify.data.ConfigData
import com.fankes.coloros.notify.hook.entity.SystemUIHooker
import com.fankes.coloros.notify.utils.factory.isNotColorOS
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
@@ -41,13 +41,11 @@ object HookEntry : IYukiHookXposedInit {
}
override fun onHook() = encase {
- loadApp(SYSTEMUI_PACKAGE_NAME) {
+ loadApp(PackageName.SYSTEMUI) {
+ ConfigData.init(instance = this)
when {
- /** 不是 ColorOS 系统停止 Hook */
isNotColorOS -> loggerW(msg = "Aborted Hook -> This System is not ColorOS")
- /** Hook 被手动关闭停止 Hook */
- prefs.get(DataConst.ENABLE_MODULE).not() -> loggerW(msg = "Aborted Hook -> Hook Closed")
- /** 开始 Hook */
+ ConfigData.isEnableModule.not() -> loggerW(msg = "Aborted Hook -> Hook Closed")
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 685edaa..c9732a3 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
@@ -45,12 +45,11 @@ import androidx.core.graphics.drawable.toBitmap
import androidx.core.view.children
import com.fankes.coloros.notify.R
import com.fankes.coloros.notify.bean.IconDataBean
-import com.fankes.coloros.notify.data.DataConst
-import com.fankes.coloros.notify.hook.HookConst.ANDROID_PACKAGE_NAME
-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
+import com.fankes.coloros.notify.const.PackageName
+import com.fankes.coloros.notify.data.ConfigData
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.BitmapCompatTool
import com.fankes.coloros.notify.utils.tool.IconAdaptationTool
@@ -77,31 +76,31 @@ object SystemUIHooker : YukiBaseHooker() {
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
/** 原生存在的类 */
- private const val NotificationUtilsClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationUtils"
+ private const val NotificationUtilsClass = "${PackageName.SYSTEMUI}.statusbar.notification.NotificationUtils"
/** 原生存在的类 */
- private const val NotificationEntryClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.collection.NotificationEntry"
+ private const val NotificationEntryClass = "${PackageName.SYSTEMUI}.statusbar.notification.collection.NotificationEntry"
/** 原生存在的类 */
private const val StatusBarIconClass = "com.android.internal.statusbar.StatusBarIcon"
/** 原生存在的类 */
- private const val StatusBarIconViewClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.StatusBarIconView"
+ private const val StatusBarIconViewClass = "${PackageName.SYSTEMUI}.statusbar.StatusBarIconView"
/** 原生存在的类 */
- private const val IconBuilderClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.icon.IconBuilder"
+ private const val IconBuilderClass = "${PackageName.SYSTEMUI}.statusbar.notification.icon.IconBuilder"
/** 原生存在的类 */
- private const val IconManagerClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.icon.IconManager"
+ private const val IconManagerClass = "${PackageName.SYSTEMUI}.statusbar.notification.icon.IconManager"
/** 原生存在的类 */
- private const val NotificationBackgroundViewClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.NotificationBackgroundView"
+ private const val NotificationBackgroundViewClass = "${PackageName.SYSTEMUI}.statusbar.notification.row.NotificationBackgroundView"
/** 原生存在的类 */
- private const val PlayerViewHolderClass = "$SYSTEMUI_PACKAGE_NAME.media.PlayerViewHolder"
+ private const val PlayerViewHolderClass = "${PackageName.SYSTEMUI}.media.PlayerViewHolder"
/** 原生存在的类 */
- private const val MediaDataClass = "$SYSTEMUI_PACKAGE_NAME.media.MediaData"
+ private const val MediaDataClass = "${PackageName.SYSTEMUI}.media.MediaData"
/** ColorOS 存在的类 - 旧版本不存在 */
private const val OplusContrastColorUtilClass = "com.oplusos.util.OplusContrastColorUtil"
@@ -158,26 +157,26 @@ object SystemUIHooker : YukiBaseHooker() {
/** 根据多个版本存在不同的包名相同的类 */
private val StatusBarNotificationPresenterClass = VariousClass(
- "$SYSTEMUI_PACKAGE_NAME.statusbar.phone.StatusBarNotificationPresenter",
- "$SYSTEMUI_PACKAGE_NAME.statusbar.phone.StatusBar"
+ "${PackageName.SYSTEMUI}.statusbar.phone.StatusBarNotificationPresenter",
+ "${PackageName.SYSTEMUI}.statusbar.phone.StatusBar"
)
/** 根据多个版本存在不同的包名相同的类 */
private val ExpandableNotificationRowClass = VariousClass(
- "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.ExpandableNotificationRow",
- "$SYSTEMUI_PACKAGE_NAME.statusbar.ExpandableNotificationRow"
+ "${PackageName.SYSTEMUI}.statusbar.notification.row.ExpandableNotificationRow",
+ "${PackageName.SYSTEMUI}.statusbar.ExpandableNotificationRow"
)
/** 根据多个版本存在不同的包名相同的类 */
private val NotificationViewWrapperClass = VariousClass(
- "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationViewWrapper",
- "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationViewWrapper"
+ "${PackageName.SYSTEMUI}.statusbar.notification.row.wrapper.NotificationViewWrapper",
+ "${PackageName.SYSTEMUI}.statusbar.notification.NotificationViewWrapper"
)
/** 根据多个版本存在不同的包名相同的类 */
private val NotificationHeaderViewWrapperClass = VariousClass(
- "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapper",
- "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationHeaderViewWrapper"
+ "${PackageName.SYSTEMUI}.statusbar.notification.row.wrapper.NotificationHeaderViewWrapper",
+ "${PackageName.SYSTEMUI}.statusbar.notification.NotificationHeaderViewWrapper"
)
/** 缓存的彩色 APP 图标 */
@@ -204,19 +203,11 @@ object SystemUIHooker : YukiBaseHooker() {
/** 是否已经使用过缓存刷新功能 */
private var isUsingCachingMethod = false
- /**
- * 是否启用通知图标优化功能
- * @param isHooking 是否判断启用通知功能 - 默认:是
- * @return [Boolean]
- */
- private fun isEnableHookColorNotifyIcon(isHooking: Boolean = true) =
- prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) && (if (isHooking) prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY) else true)
-
/**
* 判断通知是否来自系统推送
* @return [Boolean]
*/
- private val StatusBarNotification.isOplusPush get() = opPkg == ANDROID_PACKAGE_NAME && opPkg != packageName
+ private val StatusBarNotification.isOplusPush get() = opPkg == PackageName.SYSTEM_FRAMEWORK && opPkg != packageName
/**
* 判断通知背景是否为旧版本
@@ -243,7 +234,7 @@ object SystemUIHooker : YukiBaseHooker() {
isCustom: Boolean,
isGrayscale: Boolean
) {
- if (prefs.get(DataConst.ENABLE_MODULE_LOG)) loggerD(
+ if (ConfigData.isEnableModuleLog) loggerD(
msg = "$tag --> [${context.appNameOf(packageName)}][$packageName] " +
"custom [$isCustom] " +
"grayscale [$isGrayscale]"
@@ -322,7 +313,7 @@ object SystemUIHooker : YukiBaseHooker() {
* @return [Boolean]
*/
private fun isGrayscaleIcon(context: Context, drawable: Drawable) =
- if (prefs.get(DataConst.ENABLE_COLOR_ICON_COMPAT).not()) safeOfFalse {
+ if (ConfigData.isEnableColorIconCompat.not()) safeOfFalse {
ContrastColorUtilClass.toClass().let {
it.method {
name = "isGrayscaleIcon"
@@ -362,10 +353,10 @@ object SystemUIHooker : YukiBaseHooker() {
}.getOrNull() ?: context.resources.drawableOf(R.drawable.ic_unsupported)
when {
/** 替换系统图标为 Android 默认 */
- (packageName == ANDROID_PACKAGE_NAME || packageName == SYSTEMUI_PACKAGE_NAME) && isGrayscaleIcon.not() ->
+ (packageName == PackageName.SYSTEM_FRAMEWORK || packageName == PackageName.SYSTEMUI) && isGrayscaleIcon.not() ->
customPair = Pair(statSysAdbIcon, 0)
/** 替换自定义通知图标 */
- prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) -> run {
+ ConfigData.isEnableNotifyIconFix -> run {
iconDatas.takeIf { it.isNotEmpty() }?.forEach {
if (packageName == it.packageName && isAppNotifyHookOf(it)) {
if (isGrayscaleIcon.not() || isAppNotifyHookAllOf(it))
@@ -428,22 +419,18 @@ object SystemUIHooker : YukiBaseHooker() {
/** 清除之前图标可能存在的背景 */
iconView.background = null
when {
- prefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) ->
- placeholderView.apply {
- /** 重新设置图标 */
- setImageDrawable(appIcons[packageName] ?: context.appIconOf(packageName))
- /** 设置默认样式 */
- setDefaultNotifyIconViewStyle()
- }
+ ConfigData.isEnableNotifyIconForceAppIcon -> placeholderView.apply {
+ /** 重新设置图标 */
+ setImageDrawable(appIcons[packageName] ?: context.appIconOf(packageName))
+ /** 设置默认样式 */
+ setDefaultNotifyIconViewStyle()
+ }
customPair.first != null || isGrayscaleIcon -> placeholderView.apply {
/** 设置不要裁切到边界 */
clipToOutline = false
/** 重新设置图标 */
setImageDrawable(customPair.first ?: drawable)
- /** 是否开启 Material 3 风格 */
- val isMaterial3Style = prefs.get(DataConst.ENABLE_MD3_NOTIFY_ICON_STYLE)
-
/** 旧版风格 */
val oldStyle = (if (context.isSystemInDarkMode) 0xffdcdcdc else 0xff707173).toInt()
@@ -461,11 +448,11 @@ object SystemUIHooker : YukiBaseHooker() {
val newApplyColor = customPair.second.takeIf { it != 0 } ?: iconColor.takeIf { it != 0 } ?: md3Style
/** 判断风格并开始 Hook */
- if (isMaterial3Style) {
+ if (ConfigData.isEnableMd3NotifyIconStyle) {
/** 通知图标边框圆角大小 */
background = DrawableBuilder()
.rectangle()
- .cornerRadius(prefs.get(DataConst.NOTIFY_ICON_CORNER).dp(context))
+ .cornerRadius(ConfigData.notifyIconCornerSize.dp(context))
.solidColor(newApplyColor)
.build()
setColorFilter(newStyle)
@@ -495,26 +482,25 @@ object SystemUIHooker : YukiBaseHooker() {
* @param isTint 是否着色 [view]
*/
private fun modifyNotifyPanelAlpha(view: View?, drawable: Drawable? = null, isTint: Boolean = false) {
- prefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA).also { isEnabled ->
- val currentAlpha = prefs.get(DataConst.NOTIFY_PANEL_ALPHA)
- val currendColor = if (view?.context?.isSystemInDarkMode == true) 0xFF404040.toInt() else 0xFFFAFAFA.toInt()
- /** 设置通知面板背景透明度 */
- when {
- isEnabled.not() -> {
- if (isTint) view?.backgroundTintList = ColorStateList.valueOf(currendColor)
- else drawable?.setTint(currendColor)
- }
- isTint.not() && view?.parent?.parent?.javaClass?.name?.contains("ChildrenContainer") == true -> drawable?.alpha = 0
- else -> {
- currendColor.colorAlphaOf(currentAlpha / 100f).also {
- if (isTint) view?.backgroundTintList = ColorStateList.valueOf(it)
- else drawable?.setTint(it)
- }
+ val isEnable = ConfigData.isEnableNotifyPanelAlpha
+ val currentAlpha = ConfigData.notifyPanelAlphaLevel
+ val currendColor = if (view?.context?.isSystemInDarkMode == true) 0xFF404040.toInt() else 0xFFFAFAFA.toInt()
+ /** 设置通知面板背景透明度 */
+ when {
+ isEnable.not() -> {
+ if (isTint) view?.backgroundTintList = ColorStateList.valueOf(currendColor)
+ else drawable?.setTint(currendColor)
+ }
+ isTint.not() && view?.parent?.parent?.javaClass?.name?.contains("ChildrenContainer") == true -> drawable?.alpha = 0
+ else -> {
+ currendColor.colorAlphaOf(currentAlpha / 100f).also {
+ if (isTint) view?.backgroundTintList = ColorStateList.valueOf(it)
+ else drawable?.setTint(it)
}
}
- /** 移除阴影效果 */
- if (isEnabled) view?.elevation = 0f
}
+ /** 移除阴影效果 */
+ if (isEnable) view?.elevation = 0f
}
/** 设置默认通知栏通知图标样式 */
@@ -545,8 +531,8 @@ object SystemUIHooker : YukiBaseHooker() {
registerReceiver(Intent.ACTION_USER_PRESENT) { _, _ -> if (isUsingCachingMethod) refreshStatusBarIcons() }
/** 注册定时监听 */
registerReceiver(Intent.ACTION_TIME_TICK) { context, _ ->
- if (isEnableHookColorNotifyIcon() && prefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO))
- IconAdaptationTool.prepareAutoUpdateIconRule(context, prefs.get(DataConst.NOTIFY_ICON_FIX_AUTO_TIME))
+ if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify && ConfigData.isEnableNotifyIconFixAuto)
+ IconAdaptationTool.prepareAutoUpdateIconRule(context, ConfigData.notifyIconFixAutoTime)
}
/** 注册发送适配新的 APP 图标通知监听 */
registerReceiver(IntentFilter().apply {
@@ -555,21 +541,21 @@ object SystemUIHooker : YukiBaseHooker() {
addAction(Intent.ACTION_PACKAGE_REPLACED)
addAction(Intent.ACTION_PACKAGE_REMOVED)
}) { context, intent ->
- if (isEnableHookColorNotifyIcon().not()) return@registerReceiver
if (intent.action.equals(Intent.ACTION_PACKAGE_REPLACED).not() &&
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
) return@registerReceiver
- intent.data?.schemeSpecificPart?.also { packageName ->
- when (intent.action) {
- Intent.ACTION_PACKAGE_ADDED -> {
- if (iconDatas.takeIf { e -> e.isNotEmpty() }
- ?.filter { e -> e.packageName == packageName }
- .isNullOrEmpty()
- ) IconAdaptationTool.pushNewAppSupportNotify(context, packageName)
+ if (ConfigData.isEnableNotifyIconFix && ConfigData.isEnableNotifyIconFixNotify)
+ intent.data?.schemeSpecificPart?.also { packageName ->
+ when (intent.action) {
+ Intent.ACTION_PACKAGE_ADDED -> {
+ if (iconDatas.takeIf { e -> e.isNotEmpty() }
+ ?.filter { e -> e.packageName == packageName }
+ .isNullOrEmpty()
+ ) IconAdaptationTool.pushNewAppSupportNotify(context, packageName)
+ }
+ Intent.ACTION_PACKAGE_REMOVED -> IconAdaptationTool.removeNewAppSupportNotify(context, packageName)
}
- Intent.ACTION_PACKAGE_REMOVED -> IconAdaptationTool.removeNewAppSupportNotify(context, packageName)
}
- }
}
/** 注入模块资源 */
onCreate { injectModuleAppResources() }
@@ -581,12 +567,7 @@ object SystemUIHooker : YukiBaseHooker() {
/** 缓存图标数据 */
private fun cachingIconDatas() {
iconDatas.clear()
- IconPackParams(param = this).iconDatas.apply {
- when {
- isNotEmpty() -> forEach { iconDatas.add(it) }
- isEmpty() && isEnableHookColorNotifyIcon(isHooking = false) -> loggerW(msg = "NotifyIconSupportData is empty!")
- }
- }
+ IconPackParams(param = this).iconDatas.apply { if (isNotEmpty()) forEach { iconDatas.add(it) } }
}
/**
@@ -619,7 +600,7 @@ object SystemUIHooker : YukiBaseHooker() {
method { name = "updateDeveloperMode" }
beforeHook {
/** 是否移除 */
- if (prefs.get(DataConst.REMOVE_DEV_NOTIFY)) resultNull()
+ if (ConfigData.isEnableRemoveDevNotify) resultNull()
}
}
}
@@ -632,7 +613,7 @@ object SystemUIHooker : YukiBaseHooker() {
}
beforeHook {
/** 是否移除 */
- if (args().first().int() == 7 && prefs.get(DataConst.REMOVE_CHANGECP_NOTIFY)) resultNull()
+ if (args().first().int() == 7 && ConfigData.isEnableRemoveChangeCompleteNotify) resultNull()
}
}
}
@@ -645,7 +626,7 @@ object SystemUIHooker : YukiBaseHooker() {
}
beforeHook {
/** 是否移除 */
- if (prefs.get(DataConst.REMOVE_DNDALERT_NOTIFY)) resultNull()
+ if (ConfigData.isEnableRemoveDndAlertNotify) resultNull()
}
}
}
@@ -785,8 +766,7 @@ object SystemUIHooker : YukiBaseHooker() {
emptyParam()
}
beforeHook {
- if (prefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA))
- field { name = "mShowGroupBackgroundWhenExpanded" }.get(instance).setTrue()
+ if (ConfigData.isEnableNotifyPanelAlpha) field { name = "mShowGroupBackgroundWhenExpanded" }.get(instance).setTrue()
}
}
}
@@ -822,7 +802,7 @@ object SystemUIHooker : YukiBaseHooker() {
emptyParam()
}?.get(field { name = "mOplusMediaViewController" }.get(instance).any())?.boolean() ?: false
/** 符合条件后执行 */
- if (prefs.get(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP).not() || isExpanded || isPlaying.not()) return@afterHook
+ if (ConfigData.isEnableNotifyMediaPanelAutoExp.not() || isExpanded || isPlaying.not()) return@afterHook
/** 模拟手动展开通知 */
BasePlayViewHolderClass.toClassOrNull()?.method {
name = "getExpandButton"
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 db53ddd..68a737d 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
@@ -27,7 +27,7 @@ package com.fankes.coloros.notify.param
import android.content.Context
import android.graphics.Color
import com.fankes.coloros.notify.bean.IconDataBean
-import com.fankes.coloros.notify.data.DataConst
+import com.fankes.coloros.notify.data.ConfigData
import com.fankes.coloros.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()?.get(DataConst.NOTIFY_ICON_DATAS)
+ internal val storageDataJson get() = (context?.modulePrefs ?: param?.prefs)?.direct()?.get(ConfigData.NOTIFY_ICONS_DATA)
/**
* 获取图标数据
@@ -134,5 +134,5 @@ class IconPackParams(private val context: Context? = null, private val param: Pa
* 保存图标数据
* @param dataJson 图标数据 JSON
*/
- fun save(dataJson: String) = context?.modulePrefs?.put(DataConst.NOTIFY_ICON_DATAS, dataJson)
+ fun save(dataJson: String) = context?.modulePrefs?.put(ConfigData.NOTIFY_ICONS_DATA, dataJson)
}
diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt b/app/src/main/java/com/fankes/coloros/notify/param/factory/DataFactory.kt
similarity index 96%
rename from app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt
rename to app/src/main/java/com/fankes/coloros/notify/param/factory/DataFactory.kt
index 2d22ab0..e6e8a5d 100644
--- a/app/src/main/java/com/fankes/coloros/notify/hook/factory/DataFactory.kt
+++ b/app/src/main/java/com/fankes/coloros/notify/param/factory/DataFactory.kt
@@ -19,8 +19,9 @@
*
*
* This file is Created by fankes on 2022/2/15.
+ * This file is Modified by fankes on 2023/2/3.
*/
-package com.fankes.coloros.notify.hook.factory
+package com.fankes.coloros.notify.param.factory
import android.content.Context
import com.fankes.coloros.notify.bean.IconDataBean
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 316e2d9..54a584a 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
@@ -30,10 +30,10 @@ import com.fankes.coloros.notify.bean.IconDataBean
import com.fankes.coloros.notify.databinding.ActivityConfigBinding
import com.fankes.coloros.notify.databinding.AdapterConfigBinding
import com.fankes.coloros.notify.databinding.DiaIconFilterBinding
-import com.fankes.coloros.notify.hook.factory.isAppNotifyHookAllOf
-import com.fankes.coloros.notify.hook.factory.isAppNotifyHookOf
-import com.fankes.coloros.notify.hook.factory.putAppNotifyHookAllOf
-import com.fankes.coloros.notify.hook.factory.putAppNotifyHookOf
+import com.fankes.coloros.notify.param.factory.isAppNotifyHookAllOf
+import com.fankes.coloros.notify.param.factory.isAppNotifyHookOf
+import com.fankes.coloros.notify.param.factory.putAppNotifyHookAllOf
+import com.fankes.coloros.notify.param.factory.putAppNotifyHookOf
import com.fankes.coloros.notify.param.IconPackParams
import com.fankes.coloros.notify.ui.activity.base.BaseActivity
import com.fankes.coloros.notify.utils.factory.*
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 10b267a..21f7c20 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,7 +29,8 @@ import android.widget.SeekBar.OnSeekBarChangeListener
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.data.ConfigData
+import com.fankes.coloros.notify.data.factory.bind
import com.fankes.coloros.notify.databinding.ActivityMainBinding
import com.fankes.coloros.notify.param.IconPackParams
import com.fankes.coloros.notify.ui.activity.base.BaseActivity
@@ -38,7 +39,6 @@ import com.fankes.coloros.notify.utils.tool.GithubReleaseTool
import com.fankes.coloros.notify.utils.tool.SystemUITool
import com.fankes.coloros.notify.utils.tool.YukiPromoteTool
import com.highcapable.yukihookapi.YukiHookAPI
-import com.highcapable.yukihookapi.hook.factory.modulePrefs
class MainActivity : BaseActivity() {
@@ -63,9 +63,6 @@ class MainActivity : BaseActivity() {
override fun onCreate() {
/** 设置可用性 */
isActivityLive = true
- /** 设置文本 */
- binding.mainTextVersion.text = "模块版本:$moduleVersion $pendingFlag"
- binding.mainTextColorOsVersion.text = "系统版本:$colorOSFullVersion"
/** 检查更新 */
GithubReleaseTool.checkingForUpdate(context = this, moduleVersion) { version, function ->
binding.mainTextReleaseVersion.apply {
@@ -89,7 +86,7 @@ class MainActivity : BaseActivity() {
}
/** 判断是否 Hook */
YukiHookAPI.Status.isXposedModuleActive -> {
- if (IconPackParams(context = this).iconDatas.isEmpty() && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX))
+ if (IconPackParams(context = this).iconDatas.isEmpty() && ConfigData.isEnableNotifyIconFix)
showDialog {
title = "配置通知图标优化名单"
msg = "模块需要获取在线规则以更新“通知图标优化名单”,它现在是空的,这看起来是你第一次使用模块,请首先进行配置才可以使用相关功能。\n" +
@@ -98,7 +95,7 @@ class MainActivity : BaseActivity() {
cancelButton()
noCancelable()
}
- if (isNotNoificationEnabled && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX))
+ if (isNotNoificationEnabled && ConfigData.isEnableNotifyIconFix)
showDialog {
title = "模块的通知权限已关闭"
msg = "请开启通知权限,以确保你能收到通知优化图标在线规则的更新。"
@@ -120,142 +117,123 @@ class MainActivity : BaseActivity() {
noCancelable()
}
}
- var notifyIconAutoSyncTime = modulePrefs.get(DataConst.NOTIFY_ICON_FIX_AUTO_TIME)
- binding.devNotifyConfigItem.isVisible = modulePrefs.get(DataConst.ENABLE_MODULE)
- binding.notifyStyleConfigItem.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.notifyIconCustomCornerItem.isVisible = modulePrefs.get(DataConst.ENABLE_MD3_NOTIFY_ICON_STYLE) &&
- modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON).not()
- binding.notifyIconFixNotifyItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
- binding.notifyIconAutoSyncItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
- binding.notifyIconAutoSyncChildItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO)
- binding.notifyPanelConfigSeekbar.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
- binding.notifyPanelConfigTextPanel.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
- binding.notifyPanelConfigWarnPanel.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
- 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.md3StyleConfigSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MD3_NOTIFY_ICON_STYLE)
- binding.notifyMediaPanelAutoExpSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP)
- binding.moduleEnableSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE)
- binding.moduleEnableLogSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE_LOG)
- binding.colorIconCompatSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_COLOR_ICON_COMPAT)
- binding.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
- binding.notifyIconForceAppIconSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON)
- binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY)
- binding.notifyIconAutoSyncSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO)
- binding.notifyPanelConfigSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
- binding.notifyPanelConfigSeekbar.progress = modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA)
- binding.notifyIconCustomCornerSeekbar.progress = modulePrefs.get(DataConst.NOTIFY_ICON_CORNER)
- binding.notifyPanelConfigText.text = "${modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA)}%"
- binding.notifyIconCustomCornerText.text = "${modulePrefs.get(DataConst.NOTIFY_ICON_CORNER)} dp"
- binding.notifyIconAutoSyncText.text = notifyIconAutoSyncTime
+ binding.mainTextVersion.text = "模块版本:$moduleVersion $pendingFlag"
+ binding.mainTextColorOsVersion.text = "系统版本:$colorOSFullVersion"
/** 媒体通知自动展开仅支持 12.1 - 旧版本适配过于复杂已放弃 */
if (colorOSNumberVersion != "V12.1") {
binding.notifyMediaPanelAutoExpSwitch.isVisible = false
binding.notifyMediaPanelAutoExpText.isVisible = false
}
- binding.moduleEnableSwitch.setOnCheckedChangeListener { btn, 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
- binding.notifyStyleConfigItem.isVisible = b
- SystemUITool.showNeedRestartSnake(context = this)
- }
- binding.moduleEnableLogSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.ENABLE_MODULE_LOG, b)
- SystemUITool.showNeedRestartSnake(context = this)
- }
- binding.colorIconCompatSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- /** 保存当前配置并生效 */
- fun saveConfigs() {
- modulePrefs.put(DataConst.ENABLE_COLOR_ICON_COMPAT, b)
- SystemUITool.refreshSystemUI(context = this)
+ binding.notifyPanelConfigSeekbar.progress = ConfigData.notifyPanelAlphaLevel
+ binding.notifyIconCustomCornerSeekbar.progress = ConfigData.notifyIconCornerSize
+ binding.notifyPanelConfigText.text = "${ConfigData.notifyPanelAlphaLevel}%"
+ binding.notifyIconCustomCornerText.text = "${ConfigData.notifyIconCornerSize} dp"
+ binding.notifyIconAutoSyncText.text = ConfigData.notifyIconFixAutoTime
+ binding.moduleEnableSwitch.bind(ConfigData.ENABLE_MODULE) {
+ onInitialize {
+ binding.moduleEnableLogSwitch.isVisible = it
+ binding.notifyIconConfigItem.isVisible = it
+ binding.devNotifyConfigItem.isVisible = it
+ binding.notifyStyleConfigItem.isVisible = it
}
- if (b) showDialog {
- title = "启用兼容模式"
- msg = "启用兼容模式可修复部分系统版本可能出现无法判定通知图标反色的问题," +
- "但是这也可能会导致新的问题,一般情况下不建议开启,确定要继续吗?\n\n" +
- "如果系统界面刷新后通知图标颜色发生错误,请尝试重启一次系统界面。"
- confirmButton { saveConfigs() }
- cancelButton { btn.isChecked = false }
- noCancelable()
- } else saveConfigs()
- }
- binding.notifyIconFixSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX, b)
- binding.notifyIconFixButton.isVisible = b
- binding.notifyIconFixNotifyItem.isVisible = b
- binding.notifyIconAutoSyncItem.isVisible = b
- SystemUITool.refreshSystemUI(context = this)
- }
- binding.notifyIconForceAppIconSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- fun saveState() {
- binding.notifyIconCustomCornerItem.isVisible = b.not() && modulePrefs.get(DataConst.ENABLE_MD3_NOTIFY_ICON_STYLE)
- modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON, b)
- SystemUITool.refreshSystemUI(context = this)
+ onChanged {
+ reinitialize()
+ refreshModuleStatus()
+ SystemUITool.showNeedRestartSnake(context = this@MainActivity)
}
- if (b) showDialog {
- title = "破坏性功能警告"
- msg = "开启这个功能后,任何通知栏中的通知图标都会被强制替换为当前推送通知的 APP 的图标," +
- "某些系统级别的 APP 通知图标可能会显示异常或发生图标丢失。\n\n" +
- "此功能仅面向一些追求图标美观度的用户,我们不推荐开启这个功能,且发生任何 BUG 都不会去修复,仍然继续开启吗?"
- confirmButton { saveState() }
- cancelButton { btn.isChecked = btn.isChecked.not() }
- noCancelable()
- } else saveState()
}
- binding.notifyIconFixNotifySwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
- SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
+ binding.moduleEnableLogSwitch.bind(ConfigData.ENABLE_MODULE_LOG) {
+ onChanged { SystemUITool.showNeedRestartSnake(context = this@MainActivity) }
}
- binding.devNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.REMOVE_DEV_NOTIFY, b)
- SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
+ binding.devNotifyConfigSwitch.bind(ConfigData.ENABLE_REMOVE_DEV_NOTIFY) {
+ onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true) }
}
- binding.crcpNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.REMOVE_CHANGECP_NOTIFY, b)
- SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
+ binding.crcpNotifyConfigSwitch.bind(ConfigData.ENABLE_REMOVE_CHANGE_COMPLETE_NOTIFY) {
+ onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true) }
}
- binding.dndNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.REMOVE_DNDALERT_NOTIFY, b)
- SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
+ binding.dndNotifyConfigSwitch.bind(ConfigData.ENABLE_REMOVE_DND_ALERT_NOTIFY) {
+ onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true) }
}
- binding.md3StyleConfigSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- binding.notifyIconCustomCornerItem.isVisible = b && modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON).not()
- modulePrefs.put(DataConst.ENABLE_MD3_NOTIFY_ICON_STYLE, b)
- SystemUITool.refreshSystemUI(context = this)
+ binding.colorIconCompatSwitch.bind(ConfigData.ENABLE_COLOR_ICON_COMPAT) {
+ isAutoApplyChanges = false
+ onChanged {
+ /** 应用更改并刷新系统界面 */
+ fun applyChangesAndRefresh() {
+ applyChanges()
+ SystemUITool.refreshSystemUI(context = this@MainActivity)
+ }
+ if (it) showDialog {
+ title = "启用兼容模式"
+ msg = "启用兼容模式可修复部分系统版本可能出现无法判定通知图标反色的问题," +
+ "但是这也可能会导致新的问题,一般情况下不建议开启,确定要继续吗?\n\n" +
+ "如果系统界面刷新后通知图标颜色发生错误,请尝试重启一次系统界面。"
+ confirmButton { applyChangesAndRefresh() }
+ cancelButton { cancelChanges() }
+ noCancelable()
+ } else applyChangesAndRefresh()
+ }
}
- binding.notifyMediaPanelAutoExpSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP, b)
- SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
+ binding.md3StyleConfigSwitch.bind(ConfigData.ENABLE_MD3_NOTIFY_ICON_STYLE) {
+ onInitialize { binding.notifyIconCustomCornerItem.isVisible = it && ConfigData.isEnableNotifyIconForceAppIcon.not() }
+ onChanged {
+ reinitialize()
+ SystemUITool.refreshSystemUI(context = this@MainActivity)
+ }
}
- binding.notifyPanelConfigSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.ENABLE_NOTIFY_PANEL_ALPHA, b)
- binding.notifyPanelConfigTextPanel.isVisible = b
- binding.notifyPanelConfigWarnPanel.isVisible = b
- binding.notifyPanelConfigSeekbar.isVisible = b
- SystemUITool.refreshSystemUI(context = this)
+ binding.notifyIconForceAppIconSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) {
+ isAutoApplyChanges = false
+ onInitialize { binding.notifyIconCustomCornerItem.isVisible = it.not() && ConfigData.isEnableMd3NotifyIconStyle }
+ onChanged {
+ /** 应用更改并刷新系统界面 */
+ fun applyChangesAndRefresh() {
+ applyChangesAndReinitialize()
+ SystemUITool.refreshSystemUI(context = this@MainActivity)
+ }
+ if (it) showDialog {
+ title = "破坏性功能警告"
+ msg = "开启这个功能后,任何通知栏中的通知图标都会被强制替换为当前推送通知的 APP 的图标," +
+ "某些系统级别的 APP 通知图标可能会显示异常或发生图标丢失。\n\n" +
+ "此功能仅面向一些追求图标美观度的用户,我们不推荐开启这个功能,且发生任何 BUG 都不会去修复,仍然继续开启吗?"
+ confirmButton { applyChangesAndRefresh() }
+ cancelButton { cancelChanges() }
+ noCancelable()
+ } else applyChangesAndRefresh()
+ }
}
- binding.notifyIconAutoSyncSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO, b)
- binding.notifyIconAutoSyncChildItem.isVisible = b
- SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
+ binding.notifyPanelConfigSwitch.bind(ConfigData.ENABLE_NOTIFY_PANEL_ALPHA) {
+ onInitialize {
+ binding.notifyPanelConfigTextPanel.isVisible = it
+ binding.notifyPanelConfigWarnPanel.isVisible = it
+ binding.notifyPanelConfigSeekbar.isVisible = it
+ }
+ onChanged {
+ reinitialize()
+ SystemUITool.refreshSystemUI(context = this@MainActivity)
+ }
+ }
+ binding.notifyMediaPanelAutoExpSwitch.bind(ConfigData.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP) {
+ onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true) }
+ }
+ binding.notifyIconFixSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FIX) {
+ onInitialize {
+ binding.notifyIconFixButton.isVisible = it
+ binding.notifyIconFixNotifyItem.isVisible = it
+ binding.notifyIconAutoSyncItem.isVisible = it
+ }
+ onChanged {
+ reinitialize()
+ SystemUITool.refreshSystemUI(context = this@MainActivity)
+ }
+ }
+ binding.notifyIconFixNotifySwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FIX_NOTIFY) {
+ onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true) }
+ }
+ binding.notifyIconAutoSyncSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FIX_AUTO) {
+ onInitialize { binding.notifyIconAutoSyncChildItem.isVisible = it }
+ onChanged {
+ reinitialize()
+ SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true)
+ }
}
binding.notifyPanelConfigSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
@@ -263,7 +241,7 @@ class MainActivity : BaseActivity() {
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
- modulePrefs.put(DataConst.NOTIFY_PANEL_ALPHA, seekBar.progress)
+ ConfigData.notifyPanelAlphaLevel = seekBar.progress
SystemUITool.refreshSystemUI(context = this@MainActivity)
}
@@ -275,23 +253,17 @@ class MainActivity : BaseActivity() {
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
- modulePrefs.put(DataConst.NOTIFY_ICON_CORNER, seekBar.progress)
+ ConfigData.notifyIconCornerSize = seekBar.progress
SystemUITool.refreshSystemUI(context = this@MainActivity)
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
})
- /** 设置桌面图标显示隐藏 */
- binding.hideIconInLauncherSwitch.isChecked = isLauncherIconShowing.not()
- binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
- if (btn.isPressed.not()) return@setOnCheckedChangeListener
- hideOrShowLauncherIcon(b)
- }
/** 通知图标优化名单按钮点击事件 */
binding.notifyIconFixButton.setOnClickListener { navigate() }
/** 自动更新在线规则修改时间按钮点击事件 */
binding.notifyIconAutoSyncButton.setOnClickListener {
- showTimePicker(notifyIconAutoSyncTime) {
+ showTimePicker(ConfigData.notifyIconFixAutoTime) {
showDialog {
title = "每天 $it 自动更新"
msg = "设置保存后将在每天 $it 自动同步名单到最新云端数据,若数据已是最新则不会显示任何提示,否则会发送一条通知。\n\n" +
@@ -301,9 +273,8 @@ class MainActivity : BaseActivity() {
"3.模块的系统通知权限已开启\n\n" +
"模块无需保持在后台运行,到达同步时间后会自动启动,如果到达时间后模块正在运行则会自动取消本次计划任务。"
confirmButton(text = "保存设置") {
- notifyIconAutoSyncTime = it
+ ConfigData.notifyIconFixAutoTime = it
this@MainActivity.binding.notifyIconAutoSyncText.text = it
- modulePrefs.put(DataConst.NOTIFY_ICON_FIX_AUTO_TIME, it)
SystemUITool.refreshSystemUI(context, isRefreshCacheOnly = true)
}
cancelButton()
@@ -319,25 +290,32 @@ class MainActivity : BaseActivity() {
binding.linkWithFollowMe.setOnClickListener {
openBrowser(url = "https://www.coolapk.com/u/876977", packageName = "com.coolapk.market")
}
+ /** 设置桌面图标显示隐藏 */
+ binding.hideIconInLauncherSwitch.isChecked = isLauncherIconShowing.not()
+ binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
+ if (btn.isPressed.not()) return@setOnCheckedChangeListener
+ hideOrShowLauncherIcon(b)
+ }
}
/** 刷新模块状态 */
private fun refreshModuleStatus() {
binding.mainLinStatus.setBackgroundResource(
when {
- YukiHookAPI.Status.isXposedModuleActive && (isModuleRegular.not() || isModuleValied.not()) -> R.drawable.bg_yellow_round
+ YukiHookAPI.Status.isXposedModuleActive &&
+ (isModuleRegular.not() || isModuleValied.not() || ConfigData.isEnableModule.not()) -> R.drawable.bg_yellow_round
YukiHookAPI.Status.isXposedModuleActive -> R.drawable.bg_green_round
else -> R.drawable.bg_dark_round
}
)
binding.mainImgStatus.setImageResource(
when {
- YukiHookAPI.Status.isXposedModuleActive -> R.drawable.ic_success
+ YukiHookAPI.Status.isXposedModuleActive && ConfigData.isEnableModule -> R.drawable.ic_success
else -> R.drawable.ic_warn
}
)
binding.mainTextStatus.text = when {
- YukiHookAPI.Status.isXposedModuleActive && isModuleRegular.not() && modulePrefs.get(DataConst.ENABLE_MODULE).not() -> "模块已停用"
+ YukiHookAPI.Status.isXposedModuleActive && ConfigData.isEnableModule.not() -> "模块已停用"
YukiHookAPI.Status.isXposedModuleActive && isModuleRegular.not() -> "模块已激活,请重启系统界面"
YukiHookAPI.Status.isXposedModuleActive && isModuleValied.not() -> "模块已更新,请重启系统界面"
YukiHookAPI.Status.isXposedModuleActive -> "模块已激活"
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 375f1e4..e366466 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,18 +39,15 @@ 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.const.IconRuleSourceSyncType
+import com.fankes.coloros.notify.data.ConfigData
import com.fankes.coloros.notify.databinding.DiaSourceFromBinding
import com.fankes.coloros.notify.databinding.DiaSourceFromStringBinding
-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
import com.fankes.coloros.notify.param.IconPackParams
import com.fankes.coloros.notify.ui.activity.ConfigureActivity
import com.fankes.coloros.notify.utils.factory.safeOfNull
import com.fankes.coloros.notify.utils.factory.showDialog
import com.fankes.coloros.notify.utils.factory.snake
-import com.highcapable.yukihookapi.hook.factory.modulePrefs
import com.highcapable.yukihookapi.hook.log.loggerD
import okhttp3.*
import java.io.IOException
@@ -70,7 +67,13 @@ object IconRuleManagerTool {
private const val OS_TAG = "ColorOS"
/** 当前规则的通知图标颜色 */
- private const val OS_COLOR = 0xFF4E8A5A
+ private const val OS_COLOR = 0xFF4E8A5A.toInt()
+
+ /** 同步地址 - Github Raw (代理) */
+ private const val SYNC_URL_PROXY = "https://raw.githubusercontentS.com/fankes/AndroidNotifyIconAdapt/main"
+
+ /** 同步地址 - Github Raw (直连) */
+ private const val SYNC_URL_DIRECT = "https://raw.githubusercontent.com/fankes/AndroidNotifyIconAdapt/main"
/**
* 从在线地址手动同步规则
@@ -80,8 +83,8 @@ object IconRuleManagerTool {
fun syncByHand(context: Context, callback: () -> Unit) =
context.showDialog {
title = "同步列表"
- var sourceType = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY)
- var customUrl = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY_CUSTOM_URL)
+ var sourceType = ConfigData.iconRuleSourceSyncType
+ var customUrl = ConfigData.iconRuleSourceSyncCustomUrl
binding.sourceUrlEdit.apply {
if (customUrl.isNotBlank()) {
setText(customUrl)
@@ -89,25 +92,25 @@ object IconRuleManagerTool {
}
doOnTextChanged { text, _, _, _ -> customUrl = text.toString() }
}
- binding.sourceFromTextLin.isVisible = sourceType == TYPE_SOURCE_SYNC_WAY_3
- binding.sourceRadio1.isChecked = sourceType == TYPE_SOURCE_SYNC_WAY_1
- binding.sourceRadio2.isChecked = sourceType == TYPE_SOURCE_SYNC_WAY_2
- binding.sourceRadio3.isChecked = sourceType == TYPE_SOURCE_SYNC_WAY_3
+ binding.sourceFromTextLin.isVisible = sourceType == IconRuleSourceSyncType.CUSTOM_URL
+ binding.sourceRadio1.isChecked = sourceType == IconRuleSourceSyncType.GITHUB_RAW_PROXY
+ binding.sourceRadio2.isChecked = sourceType == IconRuleSourceSyncType.GITHUB_RAW_DIRECT
+ binding.sourceRadio3.isChecked = sourceType == IconRuleSourceSyncType.CUSTOM_URL
binding.sourceRadio1.setOnClickListener {
binding.sourceFromTextLin.isVisible = false
- sourceType = TYPE_SOURCE_SYNC_WAY_1
+ sourceType = IconRuleSourceSyncType.GITHUB_RAW_PROXY
}
binding.sourceRadio2.setOnClickListener {
binding.sourceFromTextLin.isVisible = false
- sourceType = TYPE_SOURCE_SYNC_WAY_2
+ sourceType = IconRuleSourceSyncType.GITHUB_RAW_DIRECT
}
binding.sourceRadio3.setOnClickListener {
binding.sourceFromTextLin.isVisible = true
- sourceType = TYPE_SOURCE_SYNC_WAY_3
+ sourceType = IconRuleSourceSyncType.CUSTOM_URL
}
confirmButton {
- context.modulePrefs.put(DataConst.SOURCE_SYNC_WAY, sourceType)
- context.modulePrefs.put(DataConst.SOURCE_SYNC_WAY_CUSTOM_URL, customUrl)
+ ConfigData.iconRuleSourceSyncType = sourceType
+ ConfigData.iconRuleSourceSyncCustomUrl = customUrl
sync(context, sourceType, customUrl, callback)
}
cancelButton()
@@ -165,16 +168,14 @@ object IconRuleManagerTool {
*/
fun sync(
context: Context,
- sourceType: Int = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY),
- customUrl: String = context.modulePrefs.get(DataConst.SOURCE_SYNC_WAY_CUSTOM_URL),
+ sourceType: Int = ConfigData.iconRuleSourceSyncType,
+ customUrl: String = ConfigData.iconRuleSourceSyncCustomUrl,
callback: () -> Unit
) {
when (sourceType) {
- TYPE_SOURCE_SYNC_WAY_1 ->
- onRefreshing(context, url = "https://raw.githubusercontentS.com/fankes/AndroidNotifyIconAdapt/main", callback)
- TYPE_SOURCE_SYNC_WAY_2 ->
- onRefreshing(context, url = "https://raw.githubusercontent.com/fankes/AndroidNotifyIconAdapt/main", callback)
- TYPE_SOURCE_SYNC_WAY_3 ->
+ IconRuleSourceSyncType.GITHUB_RAW_PROXY -> onRefreshing(context, SYNC_URL_PROXY, callback)
+ IconRuleSourceSyncType.GITHUB_RAW_DIRECT -> onRefreshing(context, SYNC_URL_DIRECT, callback)
+ IconRuleSourceSyncType.CUSTOM_URL ->
if (customUrl.isNotBlank())
if (customUrl.startsWith("http://") || customUrl.startsWith("https://"))
onRefreshingCustom(context, customUrl, callback)
@@ -384,7 +385,7 @@ object IconRuleManagerTool {
notify(0, NotificationCompat.Builder(context, NOTIFY_CHANNEL).apply {
setContentTitle(title)
setContentText(msg)
- color = OS_COLOR.toInt()
+ color = OS_COLOR
setAutoCancel(true)
setSmallIcon(R.drawable.ic_nf_icon_update)
setSound(null)
diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt b/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt
index a243603..2002b4d 100644
--- a/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt
+++ b/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt
@@ -24,7 +24,7 @@ package com.fankes.coloros.notify.utils.tool
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
-import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
+import com.fankes.coloros.notify.const.PackageName
import com.fankes.coloros.notify.utils.factory.delayedRun
import com.fankes.coloros.notify.utils.factory.execShell
import com.fankes.coloros.notify.utils.factory.showDialog
@@ -64,7 +64,7 @@ object SystemUITool {
* @param result 成功后回调
*/
fun checkingActivated(context: Context, result: (Boolean) -> Unit) =
- context.dataChannel(SYSTEMUI_PACKAGE_NAME).checkingVersionEquals(result = result)
+ context.dataChannel(PackageName.SYSTEMUI).checkingVersionEquals(result = result)
/**
* 重启系统界面
@@ -107,7 +107,7 @@ object SystemUITool {
* @param result 回调结果
*/
fun doRefresh(result: (Boolean) -> Unit) {
- context?.dataChannel(SYSTEMUI_PACKAGE_NAME)?.with {
+ context?.dataChannel(PackageName.SYSTEMUI)?.with {
wait(CALL_MODULE_REFRESH_RESULT) { result(it) }
put(CALL_HOST_REFRESH_CACHING, isRefreshCacheOnly)
}