From e503abbf888ff87e71135593ce728a65fd9495ef Mon Sep 17 00:00:00 2001 From: Chenhe Date: Wed, 22 Sep 2021 14:20:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=B8=8A=E6=97=A0=E6=B3=95=E6=8F=90=E5=8F=96=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #20 --- .../qqnotifyevo/core/NotificationProcessor.kt | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt b/app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt index fdff732..31d2b8e 100644 --- a/app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt +++ b/app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt @@ -367,10 +367,9 @@ abstract class NotificationProcessor(context: Context) { val conversation: Conversation if (num == -1) { // 特别关心动态推送 - avatarManager.saveAvatar( - CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), - getNotifyLargeIcon(context, original) - ) + getNotifyLargeIcon(context, original)?.also { + avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it) + } conversation = addMessage( tag, qzoneSpecialTitle, @@ -386,10 +385,9 @@ abstract class NotificationProcessor(context: Context) { Timber.tag(TAG).d("[QZoneSpecial] Ticker: $ticker") } else { // 与我相关的动态 - avatarManager.saveAvatar( - CONVERSATION_NAME_QZONE.hashCode(), - getNotifyLargeIcon(context, original) - ) + getNotifyLargeIcon(context, original)?.also { + avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it) + } conversation = addMessage( tag, context.getString(R.string.notify_qzone_title), @@ -422,10 +420,9 @@ abstract class NotificationProcessor(context: Context) { val special = contentMatcher.matches() && contentMatcher.group(1) != null if (!isMulti) - avatarManager.saveAvatar( - groupName.hashCode(), - getNotifyLargeIcon(context, original) - ) + getNotifyLargeIcon(context, original)?.also { + avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it) + } val conversation = addMessage( tag, name, text, groupName, avatarManager.getAvatar(name.hashCode()), original.contentIntent, original.deleteIntent, special @@ -454,18 +451,20 @@ abstract class NotificationProcessor(context: Context) { val name = matcher.group(1) ?: return null val text = matcher.group(2) ?: return null if (!isMulti) - avatarManager.saveAvatar(name.hashCode(), getNotifyLargeIcon(context, original)) + getNotifyLargeIcon(context, original)?.also { + avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it) + } val conversation = addMessage( tag, name, text, null, avatarManager.getAvatar(name.hashCode()), original.contentIntent, original.deleteIntent, special ) deleteOldMessage(conversation, if (isMulti) 0 else matchMessageNum(titleMatcher)) - if (special) { + return if (special) { Timber.tag(TAG).d("[FriendS] Name: $name; Text: $text") - return Pair(NotifyChannel.FRIEND_SPECIAL, conversation) + Pair(NotifyChannel.FRIEND_SPECIAL, conversation) } else { Timber.tag(TAG).d("[Friend] Name: $name; Text: $text") - return Pair(NotifyChannel.FRIEND, conversation) + Pair(NotifyChannel.FRIEND, conversation) } } } @@ -566,8 +565,8 @@ abstract class NotificationProcessor(context: Context) { * @param notification 原有通知。 * @return 通知的大图标。 */ - private fun getNotifyLargeIcon(context: Context, notification: Notification): Bitmap { - return notification.getLargeIcon().loadDrawable(context).toBitmap() + private fun getNotifyLargeIcon(context: Context, notification: Notification): Bitmap? { + return notification.getLargeIcon()?.loadDrawable(context)?.toBitmap() } /**