fix notification cancel delay

This commit is contained in:
Kr328
2020-02-22 22:24:45 +08:00
parent 253d465d32
commit 68d6af4255
2 changed files with 13 additions and 2 deletions

View File

@@ -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 {

View File

@@ -9,4 +9,6 @@
<string name="format_update_failure">更新 %s 失败\\n%s</string>
<string name="process_result">处理结果</string>
<string name="processing_profiles">正在处理配置文件</string>
<string name="recycling_resources">正在回收资源</string>
<string name="destroying">销毁中</string>
</resources>