Skip to content

Commit ab07eb6

Browse files
author
Chenhe
committed
优化代码
1 parent 6e5a730 commit ab07eb6

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

app/src/main/java/cc/chenhe/qqnotifyevo/BootCompletedReceiver.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import android.content.BroadcastReceiver
44
import android.content.Context
55
import android.content.Intent
66
import cc.chenhe.qqnotifyevo.service.NotificationMonitorService
7+
import cc.chenhe.qqnotifyevo.utils.MODE_LEGACY
8+
import cc.chenhe.qqnotifyevo.utils.getMode
79

810
/**
911
* 系统启动完成广播接收器
@@ -12,8 +14,10 @@ import cc.chenhe.qqnotifyevo.service.NotificationMonitorService
1214
class BootCompletedReceiver : BroadcastReceiver() {
1315
override fun onReceive(context: Context, intent: Intent) {
1416
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
15-
val start = Intent(context, NotificationMonitorService::class.java)
16-
context.startService(start)
17+
if (getMode(context) == MODE_LEGACY) {
18+
val start = Intent(context, NotificationMonitorService::class.java)
19+
context.startService(start)
20+
}
1721
}
1822
}
1923
}

app/src/main/java/cc/chenhe/qqnotifyevo/core/InnerNotificationProcessor.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ class InnerNotificationProcessor(
5151
else -> null
5252
}
5353
Timber.tag(TAG).v("Clear all evolutionary notifications.")
54-
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).run {
54+
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).apply {
5555
ids?.forEach { id -> cancel(id) }
56+
ids?.clear()
5657
}
5758
}
5859

@@ -79,7 +80,7 @@ class InnerNotificationProcessor(
7980
conversation: Conversation, sbn: StatusBarNotification,
8081
original: Notification): Notification {
8182
val history = getHistoryMessage(tag)
82-
var notification: Notification = createConversationNotification(context, tag, channel, conversation, original)
83+
var notification: Notification? = null
8384
for (c in history) {
8485
if (c.name != conversation.name || c.isGroup && channel != NotifyChannel.GROUP ||
8586
!c.isGroup && channel == NotifyChannel.GROUP) {
@@ -93,7 +94,7 @@ class InnerNotificationProcessor(
9394
sendNotification(context, tag, c.name.hashCode(), notification)
9495
commander.cancelNotification(sbn.key)
9596
}
96-
return notification
97+
return notification ?: Notification() // 此处返回值没有实际意义
9798
}
9899

99100
private fun addNotifyId(@NotificationProcessor.Companion.SourceTag tag: Int, ids: Int) {

app/src/main/java/cc/chenhe/qqnotifyevo/service/NevoDecorator.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.chenhe.qqnotifyevo.service
22

3+
import android.annotation.SuppressLint
34
import android.content.BroadcastReceiver
45
import android.content.Context
56
import android.content.Intent
@@ -19,7 +20,7 @@ import timber.log.Timber
1920
class NevoDecorator : NevoDecoratorService(), LifecycleOwner {
2021

2122
companion object {
22-
var instance: NevoDecorator? = null
23+
private var instance: NevoDecorator? = null
2324

2425
fun isRunning(): Boolean {
2526
return try {
@@ -51,6 +52,7 @@ class NevoDecorator : NevoDecoratorService(), LifecycleOwner {
5152

5253
override fun getLifecycle(): Lifecycle = lifecycleRegistry
5354

55+
@SuppressLint("WrongThread") // wrong report
5456
override fun onCreate() {
5557
super.onCreate()
5658
instance = this

app/src/main/java/cc/chenhe/qqnotifyevo/service/NotificationMonitorService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class NotificationMonitorService : NotificationListenerService(), InnerNotificat
2222
companion object {
2323
private const val TAG = "NotifyMonitor"
2424

25-
var instance: NotificationMonitorService? = null
25+
private var instance: NotificationMonitorService? = null
2626

2727
fun isRunning(): Boolean {
2828
return try {

0 commit comments

Comments
 (0)