mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-06 02:35:41 +08:00
Merge code
This commit is contained in:
@@ -41,14 +41,20 @@ object Const {
|
||||
const val MODULE_VERSION_CODE = BuildConfig.VERSION_CODE
|
||||
|
||||
/** 当前模块的版本校验 */
|
||||
const val MODULE_VERSION_VERIFY = "${MODULE_VERSION_NAME}_${MODULE_VERSION_CODE}_202103240401"
|
||||
const val MODULE_VERSION_VERIFY = "${MODULE_VERSION_NAME}_${MODULE_VERSION_CODE}_202203252250"
|
||||
|
||||
/** 当前模块的版本校验标签 */
|
||||
const val MODULE_VERSION_VERIFY_TAG = "module_version_verify"
|
||||
|
||||
/** 发送通讯广播号标签 */
|
||||
const val ACTION_MODULE_CHECKING_RECEIVER = "cnn_checking_action"
|
||||
/** 发送通讯广播号标签 - 模块激活状态 */
|
||||
const val ACTION_MODULE_CHECKING_RECEIVER = "cnn_module_checking_action"
|
||||
|
||||
/** 接收通讯广播号标签 */
|
||||
const val ACTION_MODULE_HANDLER_RECEIVER = "cnn_handler_action"
|
||||
/** 接收通讯广播号标签 - 模块激活状态 */
|
||||
const val ACTION_MODULE_HANDLER_RECEIVER = "cnn_module_handler_action"
|
||||
|
||||
/** 发送通讯广播号标签 - 通知系统界面刷新 */
|
||||
const val ACTION_REMIND_CHECKING_RECEIVER = "cnn_remind_checking_action"
|
||||
|
||||
/** 接收通讯广播号标签 - 通知系统界面刷新 */
|
||||
const val ACTION_REMIND_HANDLER_RECEIVER = "cnn_remind_handler_action"
|
||||
}
|
@@ -56,7 +56,6 @@ import com.fankes.coloros.notify.param.IconPackParams
|
||||
import com.fankes.coloros.notify.utils.drawable.drawabletoolbox.DrawableBuilder
|
||||
import com.fankes.coloros.notify.utils.factory.*
|
||||
import com.fankes.coloros.notify.utils.tool.IconAdaptationTool
|
||||
import com.fankes.coloros.notify.utils.tool.IconRuleManagerTool
|
||||
import com.highcapable.yukihookapi.hook.bean.VariousClass
|
||||
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
|
||||
import com.highcapable.yukihookapi.hook.factory.field
|
||||
@@ -191,18 +190,39 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
}
|
||||
|
||||
/** 模块广播接收器 */
|
||||
private val moduleReceiver by lazy {
|
||||
private val moduleCheckingReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
context?.sendBroadcast(Intent().apply {
|
||||
action = Const.ACTION_MODULE_HANDLER_RECEIVER
|
||||
putExtra("isAction", true)
|
||||
putExtra("isValied", intent?.getStringExtra(Const.MODULE_VERSION_VERIFY_TAG) == Const.MODULE_VERSION_VERIFY)
|
||||
putExtra("isRegular", true)
|
||||
putExtra("isValied", intent?.isValiedModule)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 通知广播接收器 */
|
||||
private val remindCheckingReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) = delayedRun(ms = 300) {
|
||||
if (intent?.isValiedModule == true)
|
||||
recachingPrefs(intent.getBooleanExtra("isRefreshCacheOnly", false))
|
||||
context?.sendBroadcast(Intent().apply {
|
||||
action = Const.ACTION_REMIND_HANDLER_RECEIVER
|
||||
putExtra("isGrasp", true)
|
||||
putExtra("isValied", intent?.isValiedModule)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断模块和宿主版本是否一致
|
||||
* @return [Boolean]
|
||||
*/
|
||||
private val Intent.isValiedModule get() = getStringExtra(Const.MODULE_VERSION_VERIFY_TAG) == Const.MODULE_VERSION_VERIFY
|
||||
|
||||
/**
|
||||
* 注册广播接收器
|
||||
* @param context 实例
|
||||
@@ -210,7 +230,8 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
private fun registerReceiver(context: Context) {
|
||||
if (isRegisterReceiver) return
|
||||
context.registerReceiver(userPresentReceiver, IntentFilter().apply { addAction(Intent.ACTION_USER_PRESENT) })
|
||||
context.registerReceiver(moduleReceiver, IntentFilter().apply { addAction(Const.ACTION_MODULE_CHECKING_RECEIVER) })
|
||||
context.registerReceiver(moduleCheckingReceiver, IntentFilter().apply { addAction(Const.ACTION_MODULE_CHECKING_RECEIVER) })
|
||||
context.registerReceiver(remindCheckingReceiver, IntentFilter().apply { addAction(Const.ACTION_REMIND_CHECKING_RECEIVER) })
|
||||
isRegisterReceiver = true
|
||||
}
|
||||
|
||||
@@ -487,11 +508,15 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新缓存数据 */
|
||||
private fun recachingPrefs() {
|
||||
/**
|
||||
* 刷新缓存数据
|
||||
* @param isRefreshCacheOnly 仅刷新缓存不刷新图标和通知改变 - 默认:否
|
||||
*/
|
||||
private fun recachingPrefs(isRefreshCacheOnly: Boolean = false) {
|
||||
isUsingCachingMethod = true
|
||||
prefs.clearCache()
|
||||
cachingIconDatas()
|
||||
if (isRefreshCacheOnly) return
|
||||
refreshStatusBarIcons()
|
||||
refreshNotificationIcons()
|
||||
}
|
||||
@@ -573,10 +598,6 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
name = "icon"
|
||||
type = IconClass
|
||||
}.get(result).set(Icon.createWithBitmap(pair.first.toBitmap()))
|
||||
/** 刷新缓存 */
|
||||
if (nf.packageName == Const.MODULE_PACKAGE_NAME &&
|
||||
nf.notification.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
|
||||
) recachingPrefs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,12 +24,11 @@
|
||||
|
||||
package com.fankes.coloros.notify.ui.activity
|
||||
|
||||
import android.content.*
|
||||
import android.content.ComponentName
|
||||
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.const.Const
|
||||
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
|
||||
@@ -60,8 +59,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
private const val pendingFlag = "[pending]"
|
||||
}
|
||||
|
||||
/** 模块是否激活 */
|
||||
private var isModuleAction = false
|
||||
/** 模块是否可用 */
|
||||
private var isModuleRegular = false
|
||||
|
||||
/** 模块是否有效 */
|
||||
private var isModuleValied = false
|
||||
@@ -168,22 +167,22 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
binding.notifyIconFixNotifySwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
|
||||
SystemUITool.refreshSystemUI(context = this)
|
||||
SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
|
||||
}
|
||||
binding.devNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(REMOVE_DEV_NOTIFY, b)
|
||||
SystemUITool.refreshSystemUI(context = this)
|
||||
SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
|
||||
}
|
||||
binding.crcpNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(REMOVE_CHANGECP_NOTIFY, b)
|
||||
SystemUITool.refreshSystemUI(context = this)
|
||||
SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
|
||||
}
|
||||
binding.dndNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
modulePrefs.putBoolean(REMOVE_DNDALERT_NOTIFY, b)
|
||||
SystemUITool.refreshSystemUI(context = this)
|
||||
SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
|
||||
}
|
||||
binding.a12StyleConfigSwitch.setOnCheckedChangeListener { btn, b ->
|
||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||
@@ -200,15 +199,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
binding.linkWithFollowMe.setOnClickListener {
|
||||
openBrowser(url = "https://www.coolapk.com/u/876977", packageName = "com.coolapk.market")
|
||||
}
|
||||
/** 注册广播检查模块激活状态 */
|
||||
registerReceiver(hostReceiver, IntentFilter().apply { addAction(Const.ACTION_MODULE_HANDLER_RECEIVER) })
|
||||
}
|
||||
|
||||
/** 刷新模块状态 */
|
||||
private fun refreshModuleStatus() {
|
||||
binding.mainLinStatus.setBackgroundResource(
|
||||
when {
|
||||
isXposedModuleActive && (!isModuleAction || !isModuleValied) -> R.drawable.bg_yellow_round
|
||||
isXposedModuleActive && (!isModuleRegular || !isModuleValied) -> R.drawable.bg_yellow_round
|
||||
isXposedModuleActive -> R.drawable.bg_green_round
|
||||
else -> R.drawable.bg_dark_round
|
||||
}
|
||||
@@ -221,9 +218,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
)
|
||||
binding.mainTextStatus.text =
|
||||
when {
|
||||
isXposedModuleActive && !isModuleAction &&
|
||||
isXposedModuleActive && !isModuleRegular &&
|
||||
!modulePrefs.getBoolean(ENABLE_MODULE, default = true) -> "模块已停用"
|
||||
isXposedModuleActive && !isModuleAction -> "模块已激活,请重启系统界面"
|
||||
isXposedModuleActive && !isModuleRegular -> "模块已激活,请重启系统界面"
|
||||
isXposedModuleActive && !isModuleValied -> "模块已更新,请重启系统界面"
|
||||
isXposedModuleActive -> "模块已激活"
|
||||
else -> "模块未激活"
|
||||
@@ -237,26 +234,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
/** 刷新模块状态 */
|
||||
refreshModuleStatus()
|
||||
/** 发送广播检查模块激活状态 */
|
||||
sendBroadcast(Intent().apply {
|
||||
action = Const.ACTION_MODULE_CHECKING_RECEIVER
|
||||
putExtra(Const.MODULE_VERSION_VERIFY_TAG, Const.MODULE_VERSION_VERIFY)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
/** 取消注册广播 */
|
||||
unregisterReceiver(hostReceiver)
|
||||
}
|
||||
|
||||
/** 宿主广播接收器 */
|
||||
private val hostReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
isModuleAction = intent?.getBooleanExtra("isAction", false) ?: false
|
||||
isModuleValied = intent?.getBooleanExtra("isValied", false) ?: false
|
||||
refreshModuleStatus()
|
||||
}
|
||||
SystemUITool.checkingActivated(context = this) { isRegular, isValied ->
|
||||
isModuleRegular = isRegular
|
||||
isModuleValied = isValied
|
||||
refreshModuleStatus()
|
||||
}
|
||||
}
|
||||
}
|
@@ -29,6 +29,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.fankes.coloros.notify.R
|
||||
import com.fankes.coloros.notify.utils.factory.isNotSystemInDarkMode
|
||||
import com.fankes.coloros.notify.utils.tool.SystemUITool
|
||||
import com.gyf.immersionbar.ktx.immersionBar
|
||||
import com.highcapable.yukihookapi.hook.factory.method
|
||||
import com.highcapable.yukihookapi.hook.type.android.LayoutInflaterClass
|
||||
@@ -61,10 +62,18 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
navigationBarDarkIcon(isNotSystemInDarkMode)
|
||||
fitsSystemWindows(true)
|
||||
}
|
||||
/** 注册 */
|
||||
SystemUITool.register(context = this)
|
||||
/** 装载子类 */
|
||||
onCreate()
|
||||
}
|
||||
|
||||
/** 回调 [onCreate] 方法 */
|
||||
abstract fun onCreate()
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
/** 解除注册 */
|
||||
SystemUITool.unregister(context = this)
|
||||
}
|
||||
}
|
@@ -42,6 +42,7 @@ import android.graphics.drawable.Drawable
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import android.util.Base64
|
||||
import android.widget.Toast
|
||||
@@ -377,4 +378,11 @@ fun Context.copyToClipboard(content: String) = runInSafe {
|
||||
if (it != content) snake(msg = "复制失败") else snake(msg = "已复制")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟执行
|
||||
* @param ms 毫秒 - 默认:150
|
||||
* @param it 方法体
|
||||
*/
|
||||
fun Any?.delayedRun(ms: Long = 150, it: () -> Unit) = runInSafe { Handler().postDelayed({ it() }, ms) }
|
@@ -47,6 +47,9 @@ import com.fankes.coloros.notify.utils.factory.runInSafe
|
||||
*/
|
||||
object IconAdaptationTool {
|
||||
|
||||
/** 推送通知的渠道名称 */
|
||||
private const val NOTIFY_CHANNEL = "notifyRuleSupportId"
|
||||
|
||||
/**
|
||||
* 使用的小图标
|
||||
* @return [Bitmap]
|
||||
@@ -116,11 +119,11 @@ object IconAdaptationTool {
|
||||
context.getSystemService(NotificationManager::class.java)?.apply {
|
||||
createNotificationChannel(
|
||||
NotificationChannel(
|
||||
IconRuleManagerTool.NOTIFY_CHANNEL, "通知图标优化适配",
|
||||
NOTIFY_CHANNEL, "通知图标优化适配",
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
).apply { enableLights(false) }
|
||||
)
|
||||
notify(packageName.hashCode(), Notification.Builder(context, IconRuleManagerTool.NOTIFY_CHANNEL).apply {
|
||||
notify(packageName.hashCode(), Notification.Builder(context, NOTIFY_CHANNEL).apply {
|
||||
setShowWhen(true)
|
||||
setContentTitle("您已安装 ${context.findAppName(packageName)}")
|
||||
setContentText("尚未适配此应用,点按打开在线规则。")
|
||||
|
@@ -32,7 +32,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.NotificationCompat
|
||||
@@ -40,7 +39,6 @@ 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.application.CNNApplication.Companion.appContext
|
||||
import com.fankes.coloros.notify.databinding.DiaSourceFromBinding
|
||||
import com.fankes.coloros.notify.databinding.DiaSourceFromStringBinding
|
||||
import com.fankes.coloros.notify.hook.HookConst.SOURCE_SYNC_WAY
|
||||
@@ -50,7 +48,9 @@ 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.*
|
||||
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.*
|
||||
@@ -65,7 +65,7 @@ import javax.net.ssl.*
|
||||
object IconRuleManagerTool {
|
||||
|
||||
/** 推送通知的渠道名称 */
|
||||
const val NOTIFY_CHANNEL = "notifyRuleUpdateId"
|
||||
private const val NOTIFY_CHANNEL = "notifyRuleUpdateId"
|
||||
|
||||
/** 当前规则的系统名称 */
|
||||
private const val OS_TAG = "ColorOS"
|
||||
@@ -139,7 +139,7 @@ object IconRuleManagerTool {
|
||||
dataJson2 = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]"
|
||||
)
|
||||
)
|
||||
pushAndNotifyRefresh(context)
|
||||
notifyRefresh(context)
|
||||
it()
|
||||
}
|
||||
else -> context.snake(msg = "请输入有效内容")
|
||||
@@ -152,7 +152,7 @@ object IconRuleManagerTool {
|
||||
jsonString.isNotBlank() && params.isNotVaildJson(jsonString) -> context.snake(msg = "不是有效的 JSON 数据")
|
||||
jsonString.isNotBlank() -> {
|
||||
params.save(dataJson = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]")
|
||||
pushAndNotifyRefresh(context)
|
||||
notifyRefresh(context)
|
||||
it()
|
||||
}
|
||||
else -> context.snake(msg = "请输入有效内容")
|
||||
@@ -216,7 +216,7 @@ object IconRuleManagerTool {
|
||||
params.isCompareDifferent(it) -> {
|
||||
params.save(it)
|
||||
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
|
||||
pushAndNotifyRefresh(context)
|
||||
notifyRefresh(context)
|
||||
it()
|
||||
}
|
||||
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
|
||||
@@ -265,7 +265,7 @@ object IconRuleManagerTool {
|
||||
params.isCompareDifferent(content) -> {
|
||||
params.save(content)
|
||||
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
|
||||
pushAndNotifyRefresh(context)
|
||||
notifyRefresh(context)
|
||||
it()
|
||||
}
|
||||
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
|
||||
@@ -358,44 +358,13 @@ object IconRuleManagerTool {
|
||||
})
|
||||
}.onFailure { it(false, "URL 无效") }
|
||||
|
||||
/**
|
||||
* 刷新系统界面状态栏与通知图标
|
||||
* @param context 实例
|
||||
*/
|
||||
fun refreshSystemUI(context: Context) {
|
||||
if (context !is AppCompatActivity) return
|
||||
if (isNotNoificationEnabled)
|
||||
context.showDialog {
|
||||
title = "模块的通知权限已关闭"
|
||||
msg = "请开启通知权限然后重启系统界面,否则无法动态刷新系统界面使更改生效。"
|
||||
confirmButton { context.openNotifySetting() }
|
||||
cancelButton()
|
||||
noCancelable()
|
||||
}
|
||||
else
|
||||
context.showDialog {
|
||||
title = "请稍后"
|
||||
progressContent = "正在刷新系统界面改变"
|
||||
/** 发送通知提醒宿主更新图标缓存 */
|
||||
pushNotify(appContext, title = "请稍后", msg = "正在等待系统界面响应", isAction = false)
|
||||
/** 刷新成功后取消通知 */
|
||||
Handler().postDelayed({
|
||||
context.getSystemService<NotificationManager>()?.cancel(1)
|
||||
cancel()
|
||||
}, 1000)
|
||||
noCancelable()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送通知图标更新通知
|
||||
* @param context 实例
|
||||
*/
|
||||
private fun pushAndNotifyRefresh(context: Context) {
|
||||
private fun notifyRefresh(context: Context) {
|
||||
if (context !is AppCompatActivity) return
|
||||
SystemUITool.showNeedUpdateApplySnake(context)
|
||||
/** 刷新改变 */
|
||||
refreshSystemUI(context)
|
||||
SystemUITool.refreshSystemUI(context) { context.snake(msg = "通知图标优化名单已完成同步") }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,9 +383,8 @@ object IconRuleManagerTool {
|
||||
* @param context 实例 - 类型为 [AppCompatActivity] 时将不会推送通知
|
||||
* @param title 通知标题
|
||||
* @param msg 通知消息
|
||||
* @param isAction 是否增加点击跳转事件 - 默认:是
|
||||
*/
|
||||
private fun pushNotify(context: Context, title: String, msg: String, isAction: Boolean = true) {
|
||||
private fun pushNotify(context: Context, title: String, msg: String) {
|
||||
if (context !is AppCompatActivity)
|
||||
context.getSystemService<NotificationManager>()?.apply {
|
||||
createNotificationChannel(
|
||||
@@ -425,15 +393,15 @@ object IconRuleManagerTool {
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
)
|
||||
notify(if (isAction) 0 else 1, NotificationCompat.Builder(context, NOTIFY_CHANNEL).apply {
|
||||
notify(0, NotificationCompat.Builder(context, NOTIFY_CHANNEL).apply {
|
||||
setContentTitle(title)
|
||||
setContentText(msg)
|
||||
color = OS_COLOR.toInt()
|
||||
setAutoCancel(true)
|
||||
setSmallIcon(if (isAction) R.drawable.ic_nf_icon_update else R.drawable.ic_nf_icon_refresh)
|
||||
setSmallIcon(R.drawable.ic_nf_icon_update)
|
||||
setSound(null)
|
||||
setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||
if (isAction) setContentIntent(
|
||||
setContentIntent(
|
||||
PendingIntent.getActivity(
|
||||
context, msg.hashCode(),
|
||||
Intent(context, ConfigureActivity::class.java).apply { putExtra("isShowUpdDialog", false) },
|
||||
|
@@ -22,11 +22,12 @@
|
||||
*/
|
||||
package com.fankes.coloros.notify.utils.tool
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import com.fankes.coloros.notify.utils.factory.execShellSu
|
||||
import com.fankes.coloros.notify.utils.factory.showDialog
|
||||
import com.fankes.coloros.notify.utils.factory.snake
|
||||
import com.fankes.coloros.notify.utils.factory.toast
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import com.fankes.coloros.notify.const.Const
|
||||
import com.fankes.coloros.notify.utils.factory.*
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.highcapable.yukihookapi.hook.factory.isXposedModuleActive
|
||||
|
||||
@@ -35,6 +36,45 @@ import com.highcapable.yukihookapi.hook.factory.isXposedModuleActive
|
||||
*/
|
||||
object SystemUITool {
|
||||
|
||||
/** 宿主广播回调 */
|
||||
private var moduleHandlerCallback: ((Boolean, Boolean) -> Unit)? = null
|
||||
|
||||
/** 通知广播回调 */
|
||||
private var remindHandlerCallback: ((Boolean, Boolean) -> Unit)? = null
|
||||
|
||||
/**
|
||||
* 注册广播
|
||||
* @param context 实例
|
||||
*/
|
||||
fun register(context: Context) {
|
||||
/** 注册广播检查模块激活状态 */
|
||||
context.registerReceiver(moduleHandlerReceiver, IntentFilter().apply { addAction(Const.ACTION_MODULE_HANDLER_RECEIVER) })
|
||||
/** 注册广播通知系统界面改变 */
|
||||
context.registerReceiver(remindHandlerReceiver, IntentFilter().apply { addAction(Const.ACTION_REMIND_HANDLER_RECEIVER) })
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消注册广播
|
||||
* @param context 实例
|
||||
*/
|
||||
fun unregister(context: Context) {
|
||||
context.unregisterReceiver(moduleHandlerReceiver)
|
||||
context.unregisterReceiver(remindHandlerReceiver)
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模块是否激活
|
||||
* @param context 实例
|
||||
* @param it 成功后回调 - ([Boolean] 是否激活,[Boolean] 是否有效)
|
||||
*/
|
||||
fun checkingActivated(context: Context, it: (Boolean, Boolean) -> Unit) {
|
||||
moduleHandlerCallback = it
|
||||
context.sendBroadcast(Intent().apply {
|
||||
action = Const.ACTION_MODULE_CHECKING_RECEIVER
|
||||
putExtra(Const.MODULE_VERSION_VERIFY_TAG, Const.MODULE_VERSION_VERIFY)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启系统界面
|
||||
* @param context 实例
|
||||
@@ -57,10 +97,40 @@ object SystemUITool {
|
||||
/**
|
||||
* 刷新系统界面状态栏与通知图标
|
||||
* @param context 实例
|
||||
* @param isRefreshCacheOnly 仅刷新缓存不刷新图标和通知改变 - 默认:否
|
||||
* @param it 成功后回调
|
||||
*/
|
||||
fun refreshSystemUI(context: Context) =
|
||||
fun refreshSystemUI(context: Context, isRefreshCacheOnly: Boolean = false, it: () -> Unit = {}) =
|
||||
if (isXposedModuleActive)
|
||||
IconRuleManagerTool.refreshSystemUI(context)
|
||||
context.showDialog {
|
||||
title = "请稍后"
|
||||
progressContent = "正在等待系统界面刷新"
|
||||
/** 是否等待成功 */
|
||||
var isWaited = false
|
||||
/** 设置等待延迟 */
|
||||
delayedRun(ms = 5000) {
|
||||
if (isWaited) return@delayedRun
|
||||
remindHandlerCallback = null
|
||||
cancel()
|
||||
context.snake(msg = "预计响应超时,建议重启系统界面", actionText = "立即重启") { restartSystemUI(context) }
|
||||
}
|
||||
remindHandlerCallback = { isGrasp, isValied ->
|
||||
remindHandlerCallback = null
|
||||
cancel()
|
||||
isWaited = true
|
||||
when {
|
||||
isGrasp && !isValied ->
|
||||
context.snake(msg = "请重启系统界面以生效模块更新", actionText = "立即重启") { restartSystemUI(context) }
|
||||
else -> it()
|
||||
}
|
||||
}
|
||||
context.sendBroadcast(Intent().apply {
|
||||
action = Const.ACTION_REMIND_CHECKING_RECEIVER
|
||||
putExtra("isRefreshCacheOnly", isRefreshCacheOnly)
|
||||
putExtra(Const.MODULE_VERSION_VERIFY_TAG, Const.MODULE_VERSION_VERIFY)
|
||||
})
|
||||
noCancelable()
|
||||
}
|
||||
else context.snake(msg = "模块没有激活,更改不会生效")
|
||||
|
||||
/**
|
||||
@@ -72,11 +142,25 @@ object SystemUITool {
|
||||
context.snake(msg = "设置需要重启系统界面才能生效", actionText = "立即重启") { restartSystemUI(context) }
|
||||
else context.snake(msg = "模块没有激活,更改不会生效")
|
||||
|
||||
/**
|
||||
* 显示更新数据后需要重启系统界面的 [Snackbar]
|
||||
* @param context 实例
|
||||
*/
|
||||
fun showNeedUpdateApplySnake(context: Context) =
|
||||
if (isXposedModuleActive) context.snake(msg = "通知图标优化名单已完成同步")
|
||||
else context.snake(msg = "模块没有激活,更改不会生效")
|
||||
/** 宿主广播接收器 */
|
||||
private val moduleHandlerReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
val isRegular = intent?.getBooleanExtra("isRegular", false) ?: false
|
||||
val isValied = intent?.getBooleanExtra("isValied", false) ?: false
|
||||
moduleHandlerCallback?.invoke(isRegular, isValied)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 通知广播接收器 */
|
||||
private val remindHandlerReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
val isGrasp = intent?.getBooleanExtra("isGrasp", false) ?: false
|
||||
val isValied = intent?.getBooleanExtra("isValied", false) ?: false
|
||||
remindHandlerCallback?.invoke(isGrasp, isValied)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:tint="@color/white"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.01,14H2v2h7.01v3L13,15l-3.99,-4V14zM14.99,13v-3H22V8h-7.01V5L11,9L14.99,13z" />
|
||||
</vector>
|
Reference in New Issue
Block a user