Merge code

This commit is contained in:
2022-03-23 02:47:53 +08:00
parent fd6ac454cf
commit d0b2ea5f48
5 changed files with 73 additions and 39 deletions

View File

@@ -141,6 +141,12 @@ class HookEntry : YukiHookXposedInitProxy {
/** 缓存的通知优化图标数组 */
private var iconDatas = ArrayList<IconDataBean>()
/** 缓存的状态栏小图标实例 */
private var statusBarIconViews = HashSet<ImageView>()
/** 缓存的通知小图标包装纸实例 */
private var notificationViewWrappers = HashSet<Any>()
/**
* 是否启用通知图标优化功能
* @param isHooking 是否判断启用通知功能 - 默认:是
@@ -172,6 +178,16 @@ class HookEntry : YukiHookXposedInitProxy {
)
}
/** 刷新状态栏小图标 */
private fun PackageParam.refreshStatusBarIcons() = runInSafe {
// TODO
}
/** 刷新通知小图标 */
private fun PackageParam.refreshNotificationIcons() = runInSafe {
// TODO
}
/**
* - 这个是修复彩色图标的关键核心代码判断
*
@@ -301,6 +317,14 @@ class HookEntry : YukiHookXposedInitProxy {
}
}
/** 刷新缓存数据 */
private fun PackageParam.recachingPrefs() {
prefs.clearCache()
cachingIconDatas()
refreshStatusBarIcons()
refreshNotificationIcons()
}
override fun onInit() = configs {
debugTag = "ColorOSNotify"
isDebug = false
@@ -387,10 +411,10 @@ class HookEntry : YukiHookXposedInitProxy {
name = "icon"
type = IconClass
}.get(result).set(Icon.createWithBitmap(pair.first.toBitmap()))
/** 刷新图标缓存 */
/** 刷新缓存 */
if (nf.packageName == MODULE_PACKAGE_NAME &&
nf.notification.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
) cachingIconDatas()
) recachingPrefs()
}
}
}
@@ -423,10 +447,6 @@ class HookEntry : YukiHookXposedInitProxy {
iconView = this
)
}
/** 刷新图标缓存 */
if (context.packageName == MODULE_PACKAGE_NAME &&
nf.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
) cachingIconDatas()
}
}
}

View File

@@ -56,7 +56,7 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
/** 回调滚动事件改变 */
private var onScrollEvent: ((Boolean) -> Unit)? = null
/** 全部的通知优化图标数据 */
/** 全部的通知图标优化数据 */
private var iconAllDatas = ArrayList<IconDataBean>()
override fun onCreate() {
@@ -149,13 +149,13 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
if (!btn.isPressed) return@setOnCheckedChangeListener
putAppNotifyHookOf(it, b)
holder.adpAppAllSwitch.isEnabled = b
SystemUITool.showNeedRestartSnake(context = this@ConfigureActivity)
SystemUITool.refreshSystemUI(context = this@ConfigureActivity)
}
holder.adpAppAllSwitch.isChecked = isAppNotifyHookAllOf(it)
holder.adpAppAllSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
putAppNotifyHookAllOf(it, b)
SystemUITool.showNeedRestartSnake(context = this@ConfigureActivity)
SystemUITool.refreshSystemUI(context = this@ConfigureActivity)
}
}
return cView!!
@@ -182,14 +182,6 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
mockLocalData()
/** 更新数据 */
when {
intent?.getBooleanExtra("isShowNeedRestart", false) == true ->
showDialog {
title = "规则列表已同步至最新"
msg = "同步完成,部分通知图标可能需要重新启动系统界面才能生效。"
confirmButton(text = "重新启动") { SystemUITool.restartSystemUI(context) }
cancelButton()
noCancelable()
}
intent?.getBooleanExtra("isNewAppSupport", false) == true ->
showDialog {
val appName = intent?.getStringExtra("appName") ?: ""
@@ -209,7 +201,6 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
}
/** 清除数据 */
intent?.apply {
removeExtra("isShowNeedRestart")
removeExtra("isNewAppSupport")
removeExtra("isShowUpdDialog")
}

View File

@@ -170,32 +170,32 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX, b)
binding.notifyIconFixButton.isVisible = b
binding.notifyIconFixNotifyItem.isVisible = b
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.notifyIconFixNotifySwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.devNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(REMOVE_DEV_NOTIFY, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.crcpNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(REMOVE_CHANGECP_NOTIFY, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.dndNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(REMOVE_DNDALERT_NOTIFY, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.a12StyleConfigSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_ANDROID12_STYLE, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
/** 通知图标优化名单按钮点击事件 */
binding.notifyIconFixButton.setOnClickListener { navigate<ConfigureActivity>() }

View File

@@ -141,7 +141,7 @@ object IconRuleManagerTool {
dataJson2 = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]"
)
)
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> context.snake(msg = "请输入有效内容")
@@ -154,7 +154,7 @@ object IconRuleManagerTool {
jsonString.isNotBlank() && params.isNotVaildJson(jsonString) -> context.snake(msg = "不是有效的 JSON 数据")
jsonString.isNotBlank() -> {
params.save(dataJson = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]")
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> context.snake(msg = "请输入有效内容")
@@ -218,7 +218,7 @@ object IconRuleManagerTool {
params.isCompareDifferent(it) -> {
params.save(it)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
@@ -267,7 +267,7 @@ object IconRuleManagerTool {
params.isCompareDifferent(content) -> {
params.save(content)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
@@ -360,17 +360,35 @@ object IconRuleManagerTool {
})
}.onFailure { it(false, "URL 无效") }
/**
* 刷新系统界面状态栏与通知图标
* @param context 实例
*/
fun refreshSystemUI(context: Context) {
if (context !is AppCompatActivity) return
context.showDialog {
title = "请稍后"
progressContent = "正在刷新系统界面改变"
/** 发送通知提醒宿主更新图标缓存 */
pushNotify(appContext, title = "请稍后", msg = "正在等待系统界面响应", isAction = false)
/** 刷新成功后取消通知 */
Handler().postDelayed({
context.getSystemService<NotificationManager>()?.cancel(1)
cancel()
}, 500)
noCancelable()
}
}
/**
* 推送通知图标更新通知
* @param context 实例
*/
private fun pushWithRefresh(context: Context) {
private fun pushAndNotifyRefresh(context: Context) {
if (context !is AppCompatActivity) return
SystemUITool.showNeedUpdateApplySnake(context)
/** 发送通知提醒宿主更新图标缓存 */
pushNotify(appContext, title = "请稍后", msg = "正在动态刷新通知图标改变", isAction = false)
/** 刷新成功后取消通知 */
Handler().postDelayed({ context.getSystemService<NotificationManager>()?.cancel(1) }, 1500)
/** 刷新改变 */
refreshSystemUI(context)
}
/**
@@ -411,10 +429,8 @@ object IconRuleManagerTool {
if (isAction) setContentIntent(
PendingIntent.getActivity(
context, msg.hashCode(),
Intent(context, ConfigureActivity::class.java).apply {
putExtra("isShowNeedRestart", true)
putExtra("isShowUpdDialog", false)
}, if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
Intent(context, ConfigureActivity::class.java).apply { putExtra("isShowUpdDialog", false) },
if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
)
)
}.build())

View File

@@ -39,7 +39,8 @@ object SystemUITool {
fun restartSystemUI(context: Context) =
context.showDialog {
title = "重启系统界面"
msg = "你确定要立即重启系统界面吗?"
msg = "你确定要立即重启系统界面吗?\n\n" +
"部分 MIUI 系统使用了状态栏主题可能会发生主题失效的情况,这种情况请再重启一次即可。"
confirmButton {
execShellSu(cmd = "pgrep systemui").also { pid ->
if (pid.isNotBlank())
@@ -50,6 +51,12 @@ object SystemUITool {
cancelButton()
}
/**
* 刷新系统界面状态栏与通知图标
* @param context 实例
*/
fun refreshSystemUI(context: Context) = IconRuleManagerTool.refreshSystemUI(context)
/**
* 显示需要重启系统界面的 [Snackbar]
* @param context 实例
@@ -67,6 +74,6 @@ object SystemUITool {
if (isXposedModuleActive)
if (isNotNoificationEnabled)
context.snake(msg = "无通知权限,请重启系统界面使更改生效", actionText = "立即重启") { restartSystemUI(context) }
else context.snake(msg = "数据已更新,已推送的通知将在下次生效", actionText = "立即重启") { restartSystemUI(context) }
else context.snake(msg = "通知图标优化名单已完成同步")
else context.snake(msg = "模块没有激活,更改不会生效")
}