From 68d6af42557fc368b4aeae5e7ba11168cb5c0c14 Mon Sep 17 00:00:00 2001
From: Kr328 <39107975+Kr328@users.noreply.github.com>
Date: Sat, 22 Feb 2020 22:24:45 +0800
Subject: [PATCH] fix notification cancel delay
---
.../github/kr328/clash/service/ClashNotification.kt | 13 +++++++++++--
service/src/main/res/values-zh/strings.xml | 2 ++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt b/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt
index e68fe2f..eff36be 100644
--- a/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt
+++ b/service/src/main/java/com/github/kr328/clash/service/ClashNotification.kt
@@ -6,10 +6,12 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.github.kr328.clash.core.Clash
+import com.github.kr328.clash.core.utils.Log
import com.github.kr328.clash.core.utils.asBytesString
import com.github.kr328.clash.core.utils.asSpeedString
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
+import kotlinx.serialization.serializer
class ClashNotification(
private val context: Service
@@ -49,9 +51,9 @@ class ClashNotification(
}
fun destroy() {
- updateDestroy()
-
context.stopForeground(true)
+
+ updateDestroy()
}
fun setProfile(profile: String) {
@@ -78,10 +80,17 @@ class ClashNotification(
private fun updateDestroy() {
// just waiting system cancel our notification :)
// fxxking google
+
val notification = baseBuilder
.setContentTitle(context.getText(R.string.destroying))
.setContentText(context.getText(R.string.recycling_resources))
+ .setSubText(null)
.build()
+
+ NotificationManagerCompat.from(context).apply {
+ notify(CLASH_STATUS_NOTIFICATION_ID, notification)
+ cancel(CLASH_STATUS_NOTIFICATION_ID)
+ }
}
private fun createNotification(): Notification {
diff --git a/service/src/main/res/values-zh/strings.xml b/service/src/main/res/values-zh/strings.xml
index a5e792b..de9888f 100644
--- a/service/src/main/res/values-zh/strings.xml
+++ b/service/src/main/res/values-zh/strings.xml
@@ -9,4 +9,6 @@
更新 %s 失败\\n%s
处理结果
正在处理配置文件
+ 正在回收资源
+ 销毁中
\ No newline at end of file