Skip to content

Commit

Permalink
修复某些系统上无法提取图标导致崩溃
Browse files Browse the repository at this point in the history
fix #20
  • Loading branch information
Chenhe committed Sep 22, 2021
1 parent 9fce3df commit e503abb
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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()
}

/**
Expand Down

0 comments on commit e503abb

Please sign in to comment.