@@ -5,7 +5,6 @@ import android.app.PendingIntent
55import android.content.Context
66import android.graphics.Bitmap
77import android.service.notification.StatusBarNotification
8- import android.util.Log
98import androidx.annotation.IntDef
109import androidx.annotation.VisibleForTesting
1110import androidx.core.app.NotificationCompat
@@ -15,6 +14,7 @@ import androidx.core.graphics.drawable.IconCompat
1514import androidx.core.graphics.drawable.toBitmap
1615import cc.chenhe.qqnotifyevo.R
1716import cc.chenhe.qqnotifyevo.utils.*
17+ import timber.log.Timber
1818import java.util.*
1919import java.util.regex.Matcher
2020import java.util.regex.Pattern
@@ -127,6 +127,7 @@ abstract class NotificationProcessor(context: Context) {
127127 * @param tag 来源标记。
128128 */
129129 fun clearHistory (@SourceTag tag : Int ) {
130+ Timber .tag(TAG ).v(" Clear history. tag=$tag " )
130131 when (tag) {
131132 TAG_QQ -> {
132133 qqHistory.clear()
@@ -187,8 +188,10 @@ abstract class NotificationProcessor(context: Context) {
187188 fun resolveNotification (context : Context , packageName : String , sbn : StatusBarNotification ): Notification ? {
188189 val original = sbn.notification ? : return null
189190 val tag = getTagFromPackageName(packageName)
190- if (tag == TAG_UNKNOWN )
191+ if (tag == TAG_UNKNOWN ) {
192+ Timber .tag(TAG ).d(" Unknown tag, skip. pkgName=$packageName " )
191193 return null
194+ }
192195
193196 val title = original.extras.getString(Notification .EXTRA_TITLE )
194197 val content = original.extras.getString(Notification .EXTRA_TEXT )
@@ -205,11 +208,11 @@ abstract class NotificationProcessor(context: Context) {
205208 // 单独处理QQ空间
206209 val isQzone = title?.let { qzonePattern.matcher(it).matches() } ? : false
207210
208- Log .v(TAG , " 标题: $title ; Ticker: $ticker ; Q空间: $isQzone ; 内容: $content " )
209-
211+ Timber .tag(TAG ).v(" Title: $title ; Ticker: $ticker ; QZone: $isQzone ; Multi: $isMulti ; Content: $content " )
210212
211213 // 隐藏消息详情
212214 if (ticker != null && ticker == content && hideMsgPattern.matcher(ticker).matches()) {
215+ Timber .tag(TAG ).v(" Hidden message content, skip." )
213216 return null
214217 }
215218
@@ -221,12 +224,14 @@ abstract class NotificationProcessor(context: Context) {
221224 avatarManager.getAvatar(CONVERSATION_NAME_QZONE .hashCode()), original.contentIntent,
222225 original.deleteIntent)
223226 deleteOldMessage(conversation, matchQzoneNum(title))
224- Log .d (TAG , " [QZone] Ticker: $ticker " )
227+ Timber .tag (TAG ).d( " [QZone] Ticker: $ticker " )
225228 return renewQzoneNotification(context, tag, conversation, sbn, original)
226229 }
227230
228- if (ticker == null )
231+ if (ticker == null ) {
232+ Timber .tag(TAG ).i(" Ticker is null, skip." )
229233 return null
234+ }
230235
231236 // 群消息
232237 groupMsgPattern.matcher(ticker).also { matcher ->
@@ -239,7 +244,7 @@ abstract class NotificationProcessor(context: Context) {
239244 val conversation = addMessage(tag, name, text, groupName,
240245 avatarManager.getAvatar(name.hashCode()), original.contentIntent, original.deleteIntent)
241246 deleteOldMessage(conversation, if (isMulti) 0 else matchMessageNum(title))
242- Log .d (TAG , " [Group] Name: $name ; Group: $groupName ; Text: $text " )
247+ Timber .tag (TAG ).d( " [Group] Name: $name ; Group: $groupName ; Text: $text " )
243248 return renewConversionNotification(context, tag, NotifyChannel .GROUP , conversation, sbn, original)
244249 }
245250 }
@@ -257,15 +262,15 @@ abstract class NotificationProcessor(context: Context) {
257262 original.contentIntent, original.deleteIntent)
258263 deleteOldMessage(conversation, if (isMulti) 0 else matchMessageNum(titleMatcher))
259264 return if (special) {
260- Log .d (TAG , " [Special] Name: $name ; Text: $text " )
265+ Timber .tag (TAG ).d( " [Special] Name: $name ; Text: $text " )
261266 renewConversionNotification(context, tag, NotifyChannel .FRIEND_SPECIAL , conversation, sbn, original)
262267 } else {
263- Log .d (TAG , " [Friend] Name: $name ; Text: $text " )
268+ Timber .tag (TAG ).d( " [Friend] Name: $name ; Text: $text " )
264269 renewConversionNotification(context, tag, NotifyChannel .FRIEND , conversation, sbn, original)
265270 }
266271 }
267272 }
268- Log .w (TAG , " [None] Not match any pattern." )
273+ Timber .tag (TAG ).w( " [None] Not match any pattern." )
269274 return null
270275 }
271276
@@ -368,6 +373,7 @@ abstract class NotificationProcessor(context: Context) {
368373 }
369374 val num = conversation.messages.size
370375 val subtext = if (num > 1 ) context.getString(R .string.notify_subtext_qzone_num, num) else null
376+ Timber .tag(TAG ).v(" Create QZone notification for $num messages." )
371377 return createNotification(context, tag, NotifyChannel .QZONE , style,
372378 avatarManager.getAvatar(CONVERSATION_NAME_QZONE .hashCode()), original, subtext)
373379 }
@@ -379,8 +385,8 @@ abstract class NotificationProcessor(context: Context) {
379385 * @param tag 来源标记。
380386 * @param original 原始通知。
381387 */
382- protected fun createConversionNotification (context : Context , @SourceTag tag : Int , channel : NotifyChannel ,
383- conversation : Conversation , original : Notification ): Notification {
388+ protected fun createConversationNotification (context : Context , @SourceTag tag : Int , channel : NotifyChannel ,
389+ conversation : Conversation , original : Notification ): Notification {
384390 val style = NotificationCompat .MessagingStyle (Person .Builder ().setName(conversation.name).build())
385391 if (conversation.isGroup) {
386392 style.conversationTitle = conversation.name
@@ -391,6 +397,7 @@ abstract class NotificationProcessor(context: Context) {
391397 }
392398 val num = conversation.messages.size
393399 val subtext = if (num > 1 ) context.getString(R .string.notify_subtext_message_num, num) else null
400+ Timber .tag(TAG ).v(" Create conversation notification for $num messages." )
394401 return createNotification(context, tag, channel, style,
395402 avatarManager.getAvatar(conversation.name.hashCode()), original, subtext)
396403 }
@@ -466,6 +473,7 @@ abstract class NotificationProcessor(context: Context) {
466473 return
467474 if (conversation.messages.size <= maxMessageNum)
468475 return
476+ Timber .tag(TAG ).d(" Delete old messages. conversation: ${conversation.name} , max: $maxMessageNum " )
469477 while (conversation.messages.size > maxMessageNum) {
470478 conversation.messages.removeAt(0 )
471479 }
0 commit comments