Skip to content

Commit

Permalink
Merge pull request #9 from liangchenhe55/dev
Browse files Browse the repository at this point in the history
Dev/一堆更新与修复
  • Loading branch information
Chenhe authored Aug 1, 2020
2 parents d726d70 + 6b8fee8 commit 23980a6
Show file tree
Hide file tree
Showing 32 changed files with 1,080 additions and 160 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.preference:preference-ktx:1.1.1"
implementation "androidx.core:core-ktx:1.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@
android:value="cc.chenhe.qqnotifyevo.preference.PreferenceAty" />
</service>

<!-- 开机自启 -->
<receiver android:name="cc.chenhe.qqnotifyevo.BootCompletedReceiver">
<receiver android:name="cc.chenhe.qqnotifyevo.StaticReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="dnotShowNevoMultiMsgTips" />
</intent-filter>
</receiver>

<activity
android:name=".preference.PreferenceAty"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:label="@string/activity_splash">
android:excludeFromRecents="false"
android:label="@string/activity_splash"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -81,6 +81,8 @@
</intent-filter>
</activity>

<service android:name=".service.UpgradeService" />

</application>

</manifest>
23 changes: 0 additions & 23 deletions app/src/main/java/cc/chenhe/qqnotifyevo/BootCompletedReceiver.kt

This file was deleted.

39 changes: 27 additions & 12 deletions app/src/main/java/cc/chenhe/qqnotifyevo/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package cc.chenhe.qqnotifyevo

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationChannelGroup
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.media.AudioAttributes
import android.media.RingtoneManager
import androidx.core.app.NotificationManagerCompat
import cc.chenhe.qqnotifyevo.log.CrashHandler
import cc.chenhe.qqnotifyevo.log.ReleaseTree
import cc.chenhe.qqnotifyevo.service.UpgradeService
import cc.chenhe.qqnotifyevo.utils.*
import timber.log.Timber

Expand Down Expand Up @@ -36,6 +39,8 @@ class MyApplication : Application() {
Timber.tag(TAG).i("= App Create")
Timber.tag(TAG).i("==================================================\n")
registerNotificationChannel()

UpgradeService.startIfNecessary(this)
}

private fun setupTimber(enableLog: Boolean) {
Expand Down Expand Up @@ -70,17 +75,27 @@ class MyApplication : Application() {
}

private fun registerNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Timber.tag(TAG).d("Register system notification channels")
val group = NotificationChannelGroup(NOTIFY_GROUP_ID, getString(R.string.notify_group_base))

(getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.apply {
createNotificationChannelGroup(group)
for (channel in getNotificationChannels(this@MyApplication, false)) {
channel.group = group.id
createNotificationChannel(channel)
}
Timber.tag(TAG).d("Register system notification channels")
val group = NotificationChannelGroup(NOTIFY_QQ_GROUP_ID, getString(R.string.notify_group_base))


val att = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
val tipChannel = NotificationChannel(NOTIFY_SELF_TIPS_CHANNEL_ID,
getString(R.string.notify_self_tips_channel_name),
NotificationManager.IMPORTANCE_DEFAULT).apply {
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
}

NotificationManagerCompat.from(this).apply {
createNotificationChannelGroup(group)
for (channel in getNotificationChannels(this@MyApplication, false)) {
channel.group = group.id
createNotificationChannel(channel)
}
createNotificationChannel(tipChannel)
}
}

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/cc/chenhe/qqnotifyevo/StaticReceiver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cc.chenhe.qqnotifyevo

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationManagerCompat
import cc.chenhe.qqnotifyevo.service.NotificationMonitorService
import cc.chenhe.qqnotifyevo.utils.*

class StaticReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Intent.ACTION_BOOT_COMPLETED -> {
if (getMode(context) == MODE_LEGACY) {
val start = Intent(context, NotificationMonitorService::class.java)
context.startService(start)
}
}
ACTION_MULTI_MSG_DONT_SHOW -> {
NotificationManagerCompat.from(context).cancel(NOTIFY_ID_MULTI_MSG)
nevoMultiMsgTip(context, false)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cc.chenhe.qqnotifyevo.core

import android.app.Notification
import android.app.NotificationManager
import android.content.Context
import android.service.notification.StatusBarNotification
import androidx.core.app.NotificationManagerCompat
import cc.chenhe.qqnotifyevo.utils.NotifyChannel
import timber.log.Timber
import java.util.*
Expand Down Expand Up @@ -51,15 +51,15 @@ class InnerNotificationProcessor(
else -> null
}
Timber.tag(TAG).v("Clear all evolutionary notifications.")
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).apply {
NotificationManagerCompat.from(context).apply {
ids?.forEach { id -> cancel(id) }
ids?.clear()
}
}

private fun sendNotification(context: Context, @NotificationProcessor.Companion.SourceTag tag: Int, id: Int,
notification: Notification) {
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(id, notification)
NotificationManagerCompat.from(context).notify(id, notification)
addNotifyId(tag, id)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package cc.chenhe.qqnotifyevo.core

import android.app.Notification
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.service.notification.StatusBarNotification
import cc.chenhe.qqnotifyevo.utils.NotifyChannel
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import cc.chenhe.qqnotifyevo.R
import cc.chenhe.qqnotifyevo.StaticReceiver
import cc.chenhe.qqnotifyevo.preference.PreferenceAty
import cc.chenhe.qqnotifyevo.utils.*

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

companion object {
private const val REQ_MULTI_MSG_LEARN_MORE = 1
private const val REQ_MULTI_MSG_DONT_SHOW = 2
}

override fun renewQzoneNotification(context: Context, tag: Int, conversation: Conversation,
sbn: StatusBarNotification, original: Notification): Notification {
return createQZoneNotification(context, tag, conversation, original)
Expand All @@ -21,4 +33,36 @@ class NevoNotificationProcessor(context: Context) : NotificationProcessor(contex
return createConversationNotification(context, tag, channel, conversation, original)
}

override fun onMultiMessageDetected() {
super.onMultiMessageDetected()
if (nevoMultiMsgTip(ctx)) {
val dontShow = PendingIntent.getBroadcast(ctx, REQ_MULTI_MSG_DONT_SHOW,
Intent(ctx, StaticReceiver::class.java).also {
it.action = ACTION_MULTI_MSG_DONT_SHOW
}, PendingIntent.FLAG_UPDATE_CURRENT)

val learnMore = PendingIntent.getActivity(ctx, REQ_MULTI_MSG_LEARN_MORE,
Intent(ctx, PreferenceAty::class.java).also {
it.putExtra(PreferenceAty.EXTRA_NEVO_MULTI_MSG, true)
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}, PendingIntent.FLAG_UPDATE_CURRENT)

val style = NotificationCompat.BigTextStyle()
.setBigContentTitle(ctx.getString(R.string.notify_multi_msg_title))
.bigText(ctx.getString(R.string.notify_multi_msg_content))
val n = NotificationCompat.Builder(ctx, NOTIFY_SELF_TIPS_CHANNEL_ID)
.setStyle(style)
.setAutoCancel(true)
.setContentTitle(ctx.getString(R.string.notify_multi_msg_title))
.setContentText(ctx.getString(R.string.notify_multi_msg_content))
.setSmallIcon(R.drawable.ic_notify_warning)
.setContentIntent(learnMore)
.addAction(R.drawable.ic_notify_action_dnot_show, ctx.getString(R.string.dont_show), dontShow)
.addAction(R.drawable.ic_notify_action_learn_more, ctx.getString(R.string.learn_more), learnMore)
.build()

NotificationManagerCompat.from(ctx).notify(NOTIFY_ID_MULTI_MSG, n)
}
}

}
Loading

0 comments on commit 23980a6

Please sign in to comment.