Added retry notification function when notification icon rule sync failed in ConfigureActivity, IconRuleManagerTool

This commit is contained in:
2023-02-03 23:59:05 +08:00
parent aa10d5491e
commit e0b5b462f9
2 changed files with 24 additions and 9 deletions

View File

@@ -196,11 +196,13 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
neutralButton(text = "取消")
noCancelable()
}
intent?.getBooleanExtra("isDirectUpdate", false) == true -> onStartRefresh(isByHand = false)
intent?.getBooleanExtra("isShowUpdDialog", true) == true -> onStartRefresh()
}
/** 清除数据 */
intent?.apply {
removeExtra("isNewAppSupport")
removeExtra("isDirectUpdate")
removeExtra("isShowUpdDialog")
}
/** 设置返回监听事件 */
@@ -219,12 +221,22 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
}
}
/** 开始手动同步 */
private fun onStartRefresh() =
IconRuleManagerTool.syncByHand(context = this) {
filterText = ""
mockLocalData()
}
/**
* 开始同步
* @param isByHand 是否手动同步 - 默认是
*/
private fun onStartRefresh(isByHand: Boolean = true) {
if (isByHand)
IconRuleManagerTool.syncByHand(context = this) {
filterText = ""
mockLocalData()
}
else
IconRuleManagerTool.sync(context = this) {
filterText = ""
mockLocalData()
}
}
/** 装载或刷新本地数据 */
private fun mockLocalData() {

View File

@@ -310,7 +310,7 @@ object IconRuleManagerTool {
}
}
} else baseCheckingInternetConnect(context) { isDone ->
if (isDone) callback() else pushNotify(context, title = "网络不可用", msg = "无法连接到互联网,无法更新通知图标规则")
if (isDone) callback() else pushNotify(context, title = "网络不可用", msg = "络连接失败,无法更新通知图标规则,点击重试", isRetry = true)
}
/**
@@ -372,8 +372,9 @@ object IconRuleManagerTool {
* @param context 实例 - 类型为 [AppCompatActivity] 时将不会推送通知
* @param title 通知标题
* @param msg 通知消息
* @param isRetry 是否发送重试动作 - 默认否
*/
private fun pushNotify(context: Context, title: String, msg: String) {
private fun pushNotify(context: Context, title: String, msg: String, isRetry: Boolean = false) {
if (context !is AppCompatActivity)
context.getSystemService<NotificationManager>()?.apply {
createNotificationChannel(
@@ -393,7 +394,9 @@ object IconRuleManagerTool {
setContentIntent(
PendingIntent.getActivity(
context, msg.hashCode(),
Intent(context, ConfigureActivity::class.java).apply { putExtra("isShowUpdDialog", false) },
Intent(context, ConfigureActivity::class.java).apply {
if (isRetry) putExtra("isDirectUpdate", true) else putExtra("isShowUpdDialog", false)
},
if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
)
)