Merge code

This commit is contained in:
2022-03-22 02:46:20 +08:00
parent 5a501b9846
commit c06abdf514
7 changed files with 73 additions and 24 deletions

View File

@@ -27,12 +27,16 @@ package com.fankes.coloros.notify.application
import android.app.Application
import android.content.Context
import androidx.appcompat.app.AppCompatDelegate
import com.fankes.coloros.notify.BuildConfig
import me.weishu.reflection.Reflection
class CNNApplication : Application() {
companion object {
/** 当前模块的包名 */
const val MODULE_PACKAGE_NAME = BuildConfig.APPLICATION_ID
/** 全局静态实例 */
private var context: CNNApplication? = null

View File

@@ -32,6 +32,7 @@ import android.graphics.drawable.VectorDrawable
import android.service.notification.StatusBarNotification
import android.widget.ImageView
import androidx.core.graphics.drawable.toBitmap
import com.fankes.coloros.notify.application.CNNApplication.Companion.MODULE_PACKAGE_NAME
import com.fankes.coloros.notify.bean.IconDataBean
import com.fankes.coloros.notify.hook.HookConst.ENABLE_ANDROID12_STYLE
import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE
@@ -48,6 +49,7 @@ 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.annotation.xposed.InjectYukiHookWithXposed
import com.highcapable.yukihookapi.hook.bean.VariousClass
import com.highcapable.yukihookapi.hook.factory.configs
@@ -278,6 +280,11 @@ class HookEntry : YukiHookXposedInitProxy {
}
}
/** 缓存图标数据 */
private fun PackageParam.cachingIconDatas() {
iconDatas = IconPackParams(param = this).iconDatas
}
override fun onInit() = configs {
debugTag = "ColorOSNotify"
isDebug = false
@@ -293,7 +300,7 @@ class HookEntry : YukiHookXposedInitProxy {
/** 开始 Hook */
else -> {
/** 缓存图标数据 */
iconDatas = IconPackParams(param = this).iconDatas
cachingIconDatas()
/** 移除开发者警告通知 */
SystemPromptControllerClass.hook {
injectMember {
@@ -365,7 +372,12 @@ class HookEntry : YukiHookXposedInitProxy {
packageName = nf.packageName,
drawable = iconDrawable
)
)
).apply {
/** 刷新图标缓存 */
if (nf.packageName == MODULE_PACKAGE_NAME &&
nf.notification.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
) cachingIconDatas()
}
)
}
}
@@ -398,6 +410,10 @@ class HookEntry : YukiHookXposedInitProxy {
iconView = this
)
}
/** 刷新图标缓存 */
if (context.packageName == MODULE_PACKAGE_NAME &&
nf.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
) cachingIconDatas()
}
}
}

View File

@@ -182,6 +182,14 @@ 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") ?: ""
@@ -190,6 +198,7 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
msg = "你已安装 $appName($pkgName)\n\n" +
"此应用未在通知优化名单中发现适配数据,若此应用发送的通知为彩色图标," +
"可随时点击本页面下方的“贡献通知图标优化名单”按钮提交贡献或请求适配。\n\n" +
"若你已知晓此应用会遵守原生通知图标规范,可忽略此提示。\n\n" +
"你可以现在立即同步适配列表,以获取最新的适配数据。"
confirmButton(text = "同步列表") { onStartRefresh() }
cancelButton(text = "复制名称+包名") { copyToClipboard(content = "$appName($pkgName)") }
@@ -200,6 +209,7 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
}
/** 清除数据 */
intent?.apply {
removeExtra("isShowNeedRestart")
removeExtra("isNewAppSupport")
removeExtra("isShowUpdDialog")
}
@@ -210,7 +220,6 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
IconRuleManagerTool.syncByHand(context = this) {
filterText = ""
mockLocalData()
SystemUITool.showNeedUpdateApplySnake(context = this)
}
/** 装载或刷新本地数据 */

View File

@@ -36,10 +36,10 @@ import java.io.Serializable
object GithubReleaseTool {
/** 仓库作者 */
private const val repoAuthor = "fankes"
private const val REPO_AUTHOR = "fankes"
/** 仓库名称 */
private const val repoName = "ColorOSNotifyIcon"
private const val REPO_NAME = "ColorOSNotifyIcon"
/**
* 获取最新版本信息
@@ -50,7 +50,7 @@ object GithubReleaseTool {
fun checkingForUpdate(context: Context, version: String, it: (String, () -> Unit) -> Unit) = checkingInternetConnect(context) {
OkHttpClient().newBuilder().build().newCall(
Request.Builder()
.url("https://api.github.com/repos/$repoAuthor/$repoName/releases/latest")
.url("https://api.github.com/repos/$REPO_AUTHOR/$REPO_NAME/releases/latest")
.get()
.build()
).enqueue(object : Callback {

View File

@@ -32,7 +32,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Icon
import android.os.Build
import com.fankes.coloros.notify.BuildConfig
import com.fankes.coloros.notify.application.CNNApplication.Companion.MODULE_PACKAGE_NAME
import com.fankes.coloros.notify.hook.HookEntry
import com.fankes.coloros.notify.utils.factory.bitmap
import com.fankes.coloros.notify.utils.factory.findAppIcon
@@ -46,9 +46,6 @@ import com.fankes.coloros.notify.utils.factory.runInSafe
*/
object IconAdaptationTool {
/** 当前模块的包名 */
private const val PACKAGE_NAME = BuildConfig.APPLICATION_ID
/**
* 使用的小图标
* @return [Bitmap]
@@ -103,8 +100,8 @@ object IconAdaptationTool {
context, packageName.hashCode(),
Intent().apply {
component = ComponentName(
PACKAGE_NAME,
"$PACKAGE_NAME.ui.activity.ConfigureActivity"
MODULE_PACKAGE_NAME,
"$MODULE_PACKAGE_NAME.ui.activity.ConfigureActivity"
)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}.apply {

View File

@@ -32,6 +32,7 @@ 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
@@ -39,6 +40,7 @@ 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
@@ -64,6 +66,9 @@ import javax.net.ssl.*
*/
object IconRuleManagerTool {
/** 推送通知的渠道名称 */
const val NOTIFY_CHANNEL = "notifyRuleUpdateId"
/** 当前规则的系统名称 */
private const val OS_TAG = "ColorOS"
@@ -138,6 +143,7 @@ object IconRuleManagerTool {
dataJson2 = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]"
)
)
pushWithRefresh(context)
it()
}
else -> context.snake(msg = "请输入有效内容")
@@ -150,6 +156,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)
it()
}
else -> context.snake(msg = "请输入有效内容")
@@ -208,6 +215,7 @@ object IconRuleManagerTool {
params.isCompareDifferent(it) -> {
params.save(it)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
pushWithRefresh(context)
it()
}
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
@@ -256,6 +264,7 @@ object IconRuleManagerTool {
params.isCompareDifferent(content) -> {
params.save(content)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
pushWithRefresh(context)
it()
}
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
@@ -348,6 +357,18 @@ object IconRuleManagerTool {
})
}.onFailure { it(false, "URL 无效") }
/**
* 推送通知图标更新通知
* @param context 实例
*/
private fun pushWithRefresh(context: Context) {
if (context !is AppCompatActivity) return
SystemUITool.showNeedUpdateApplySnake(context)
pushNotify(appContext, title = "更新完成", msg = "部分通知图标需要重启系统界面生效", isAction = false)
/** 刷新成功后取消通知 */
Handler().postDelayed({ context.getSystemService<NotificationManager>()?.cancel(1) }, 1500)
}
/**
* 根据实例类型决定推送通知还是弹出提示
* @param title 标题 - 仅对通知生效
@@ -364,17 +385,18 @@ object IconRuleManagerTool {
* @param context 实例 - 类型为 [AppCompatActivity] 时将不会推送通知
* @param title 通知标题
* @param msg 通知消息
* @param isAction 是否增加点击跳转事件 - 默认:是
*/
private fun pushNotify(context: Context, title: String, msg: String) {
private fun pushNotify(context: Context, title: String, msg: String, isAction: Boolean = true) {
if (context !is AppCompatActivity)
context.getSystemService<NotificationManager>()?.apply {
createNotificationChannel(
NotificationChannel(
"notifyRuleUpdateId", "通知图标优化规则",
NOTIFY_CHANNEL, "通知图标优化规则",
NotificationManager.IMPORTANCE_DEFAULT
)
)
notify(0, NotificationCompat.Builder(context, "notifyRuleUpdateId").apply {
notify(if (isAction) 0 else 1, NotificationCompat.Builder(context, NOTIFY_CHANNEL).apply {
setContentTitle(title)
setContentText(msg)
color = OS_COLOR.toInt()
@@ -382,11 +404,13 @@ object IconRuleManagerTool {
setSmallIcon(R.drawable.ic_nf_icon_update)
setSound(null)
setDefaults(NotificationCompat.DEFAULT_ALL)
setContentIntent(
if (isAction) setContentIntent(
PendingIntent.getActivity(
context, 1,
Intent(context, ConfigureActivity::class.java).apply { putExtra("isShowUpdDialog", false) },
if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
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
)
)
}.build())

View File

@@ -23,10 +23,7 @@
package com.fankes.coloros.notify.utils.tool
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 com.fankes.coloros.notify.utils.factory.*
import com.google.android.material.snackbar.Snackbar
import com.highcapable.yukihookapi.hook.factory.isXposedModuleActive
@@ -68,6 +65,8 @@ object SystemUITool {
*/
fun showNeedUpdateApplySnake(context: Context) =
if (isXposedModuleActive)
context.snake(msg = "数据已更新,请重启系统界面使更改生效", actionText = "立即重启") { restartSystemUI(context) }
if (isNotNoificationEnabled)
context.snake(msg = "无通知权限,请重启系统界面使更改生效", actionText = "立即重启") { restartSystemUI(context) }
else context.snake(msg = "数据已更新,已推送的通知将在下次生效", actionText = "立即重启") { restartSystemUI(context) }
else context.snake(msg = "模块没有激活,更改不会生效")
}