Skip to content

Commit 23980a6

Browse files
author
Chenhe
authored
Merge pull request #9 from liangchenhe55/dev
Dev/一堆更新与修复
2 parents d726d70 + 6b8fee8 commit 23980a6

32 files changed

+1080
-160
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
5454
exclude group: 'com.android.support', module: 'support-annotations'
5555
})
56+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
5657
implementation "androidx.preference:preference-ktx:1.1.1"
5758
implementation "androidx.core:core-ktx:1.3.1"
5859
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@
6161
android:value="cc.chenhe.qqnotifyevo.preference.PreferenceAty" />
6262
</service>
6363

64-
<!-- 开机自启 -->
65-
<receiver android:name="cc.chenhe.qqnotifyevo.BootCompletedReceiver">
64+
<receiver android:name="cc.chenhe.qqnotifyevo.StaticReceiver">
6665
<intent-filter>
6766
<action android:name="android.intent.action.BOOT_COMPLETED" />
67+
<action android:name="dnotShowNevoMultiMsgTips" />
6868
</intent-filter>
6969
</receiver>
7070

7171
<activity
7272
android:name=".preference.PreferenceAty"
73-
android:autoRemoveFromRecents="true"
74-
android:excludeFromRecents="true"
75-
android:label="@string/activity_splash">
73+
android:excludeFromRecents="false"
74+
android:label="@string/activity_splash"
75+
android:launchMode="singleInstance">
7676
<intent-filter>
7777
<action android:name="android.intent.action.MAIN" />
7878
<category android:name="android.intent.category.LAUNCHER" />
@@ -81,6 +81,8 @@
8181
</intent-filter>
8282
</activity>
8383

84+
<service android:name=".service.UpgradeService" />
85+
8486
</application>
8587

8688
</manifest>

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package cc.chenhe.qqnotifyevo
22

33
import android.app.Application
4+
import android.app.NotificationChannel
45
import android.app.NotificationChannelGroup
56
import android.app.NotificationManager
6-
import android.content.Context
7-
import android.os.Build
7+
import android.media.AudioAttributes
8+
import android.media.RingtoneManager
9+
import androidx.core.app.NotificationManagerCompat
810
import cc.chenhe.qqnotifyevo.log.CrashHandler
911
import cc.chenhe.qqnotifyevo.log.ReleaseTree
12+
import cc.chenhe.qqnotifyevo.service.UpgradeService
1013
import cc.chenhe.qqnotifyevo.utils.*
1114
import timber.log.Timber
1215

@@ -36,6 +39,8 @@ class MyApplication : Application() {
3639
Timber.tag(TAG).i("= App Create")
3740
Timber.tag(TAG).i("==================================================\n")
3841
registerNotificationChannel()
42+
43+
UpgradeService.startIfNecessary(this)
3944
}
4045

4146
private fun setupTimber(enableLog: Boolean) {
@@ -70,17 +75,27 @@ class MyApplication : Application() {
7075
}
7176

7277
private fun registerNotificationChannel() {
73-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
74-
Timber.tag(TAG).d("Register system notification channels")
75-
val group = NotificationChannelGroup(NOTIFY_GROUP_ID, getString(R.string.notify_group_base))
76-
77-
(getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.apply {
78-
createNotificationChannelGroup(group)
79-
for (channel in getNotificationChannels(this@MyApplication, false)) {
80-
channel.group = group.id
81-
createNotificationChannel(channel)
82-
}
78+
Timber.tag(TAG).d("Register system notification channels")
79+
val group = NotificationChannelGroup(NOTIFY_QQ_GROUP_ID, getString(R.string.notify_group_base))
80+
81+
82+
val att = AudioAttributes.Builder()
83+
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
84+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
85+
.build()
86+
val tipChannel = NotificationChannel(NOTIFY_SELF_TIPS_CHANNEL_ID,
87+
getString(R.string.notify_self_tips_channel_name),
88+
NotificationManager.IMPORTANCE_DEFAULT).apply {
89+
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
90+
}
91+
92+
NotificationManagerCompat.from(this).apply {
93+
createNotificationChannelGroup(group)
94+
for (channel in getNotificationChannels(this@MyApplication, false)) {
95+
channel.group = group.id
96+
createNotificationChannel(channel)
8397
}
98+
createNotificationChannel(tipChannel)
8499
}
85100
}
86101

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cc.chenhe.qqnotifyevo
2+
3+
import android.content.BroadcastReceiver
4+
import android.content.Context
5+
import android.content.Intent
6+
import androidx.core.app.NotificationManagerCompat
7+
import cc.chenhe.qqnotifyevo.service.NotificationMonitorService
8+
import cc.chenhe.qqnotifyevo.utils.*
9+
10+
class StaticReceiver : BroadcastReceiver() {
11+
12+
override fun onReceive(context: Context, intent: Intent) {
13+
when (intent.action) {
14+
Intent.ACTION_BOOT_COMPLETED -> {
15+
if (getMode(context) == MODE_LEGACY) {
16+
val start = Intent(context, NotificationMonitorService::class.java)
17+
context.startService(start)
18+
}
19+
}
20+
ACTION_MULTI_MSG_DONT_SHOW -> {
21+
NotificationManagerCompat.from(context).cancel(NOTIFY_ID_MULTI_MSG)
22+
nevoMultiMsgTip(context, false)
23+
}
24+
}
25+
}
26+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cc.chenhe.qqnotifyevo.core
22

33
import android.app.Notification
4-
import android.app.NotificationManager
54
import android.content.Context
65
import android.service.notification.StatusBarNotification
6+
import androidx.core.app.NotificationManagerCompat
77
import cc.chenhe.qqnotifyevo.utils.NotifyChannel
88
import timber.log.Timber
99
import java.util.*
@@ -51,15 +51,15 @@ class InnerNotificationProcessor(
5151
else -> null
5252
}
5353
Timber.tag(TAG).v("Clear all evolutionary notifications.")
54-
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).apply {
54+
NotificationManagerCompat.from(context).apply {
5555
ids?.forEach { id -> cancel(id) }
5656
ids?.clear()
5757
}
5858
}
5959

6060
private fun sendNotification(context: Context, @NotificationProcessor.Companion.SourceTag tag: Int, id: Int,
6161
notification: Notification) {
62-
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(id, notification)
62+
NotificationManagerCompat.from(context).notify(id, notification)
6363
addNotifyId(tag, id)
6464
}
6565

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
package cc.chenhe.qqnotifyevo.core
22

33
import android.app.Notification
4+
import android.app.PendingIntent
45
import android.content.Context
6+
import android.content.Intent
57
import android.service.notification.StatusBarNotification
6-
import cc.chenhe.qqnotifyevo.utils.NotifyChannel
8+
import androidx.core.app.NotificationCompat
9+
import androidx.core.app.NotificationManagerCompat
10+
import cc.chenhe.qqnotifyevo.R
11+
import cc.chenhe.qqnotifyevo.StaticReceiver
12+
import cc.chenhe.qqnotifyevo.preference.PreferenceAty
13+
import cc.chenhe.qqnotifyevo.utils.*
714

815
/**
916
* 配合 [cc.chenhe.qqnotifyevo.service.NevoDecorator] 使用的通知处理器,直接创建并返回优化后的通知。
1017
*/
1118
class NevoNotificationProcessor(context: Context) : NotificationProcessor(context) {
1219

20+
companion object {
21+
private const val REQ_MULTI_MSG_LEARN_MORE = 1
22+
private const val REQ_MULTI_MSG_DONT_SHOW = 2
23+
}
24+
1325
override fun renewQzoneNotification(context: Context, tag: Int, conversation: Conversation,
1426
sbn: StatusBarNotification, original: Notification): Notification {
1527
return createQZoneNotification(context, tag, conversation, original)
@@ -21,4 +33,36 @@ class NevoNotificationProcessor(context: Context) : NotificationProcessor(contex
2133
return createConversationNotification(context, tag, channel, conversation, original)
2234
}
2335

36+
override fun onMultiMessageDetected() {
37+
super.onMultiMessageDetected()
38+
if (nevoMultiMsgTip(ctx)) {
39+
val dontShow = PendingIntent.getBroadcast(ctx, REQ_MULTI_MSG_DONT_SHOW,
40+
Intent(ctx, StaticReceiver::class.java).also {
41+
it.action = ACTION_MULTI_MSG_DONT_SHOW
42+
}, PendingIntent.FLAG_UPDATE_CURRENT)
43+
44+
val learnMore = PendingIntent.getActivity(ctx, REQ_MULTI_MSG_LEARN_MORE,
45+
Intent(ctx, PreferenceAty::class.java).also {
46+
it.putExtra(PreferenceAty.EXTRA_NEVO_MULTI_MSG, true)
47+
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
48+
}, PendingIntent.FLAG_UPDATE_CURRENT)
49+
50+
val style = NotificationCompat.BigTextStyle()
51+
.setBigContentTitle(ctx.getString(R.string.notify_multi_msg_title))
52+
.bigText(ctx.getString(R.string.notify_multi_msg_content))
53+
val n = NotificationCompat.Builder(ctx, NOTIFY_SELF_TIPS_CHANNEL_ID)
54+
.setStyle(style)
55+
.setAutoCancel(true)
56+
.setContentTitle(ctx.getString(R.string.notify_multi_msg_title))
57+
.setContentText(ctx.getString(R.string.notify_multi_msg_content))
58+
.setSmallIcon(R.drawable.ic_notify_warning)
59+
.setContentIntent(learnMore)
60+
.addAction(R.drawable.ic_notify_action_dnot_show, ctx.getString(R.string.dont_show), dontShow)
61+
.addAction(R.drawable.ic_notify_action_learn_more, ctx.getString(R.string.learn_more), learnMore)
62+
.build()
63+
64+
NotificationManagerCompat.from(ctx).notify(NOTIFY_ID_MULTI_MSG, n)
65+
}
66+
}
67+
2468
}

0 commit comments

Comments
 (0)