Skip to content

Commit e503abb

Browse files
author
Chenhe
committed
修复某些系统上无法提取图标导致崩溃
fix #20
1 parent 9fce3df commit e503abb

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,9 @@ abstract class NotificationProcessor(context: Context) {
367367
val conversation: Conversation
368368
if (num == -1) {
369369
// 特别关心动态推送
370-
avatarManager.saveAvatar(
371-
CONVERSATION_NAME_QZONE_SPECIAL.hashCode(),
372-
getNotifyLargeIcon(context, original)
373-
)
370+
getNotifyLargeIcon(context, original)?.also {
371+
avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it)
372+
}
374373
conversation = addMessage(
375374
tag,
376375
qzoneSpecialTitle,
@@ -386,10 +385,9 @@ abstract class NotificationProcessor(context: Context) {
386385
Timber.tag(TAG).d("[QZoneSpecial] Ticker: $ticker")
387386
} else {
388387
// 与我相关的动态
389-
avatarManager.saveAvatar(
390-
CONVERSATION_NAME_QZONE.hashCode(),
391-
getNotifyLargeIcon(context, original)
392-
)
388+
getNotifyLargeIcon(context, original)?.also {
389+
avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it)
390+
}
393391
conversation = addMessage(
394392
tag,
395393
context.getString(R.string.notify_qzone_title),
@@ -422,10 +420,9 @@ abstract class NotificationProcessor(context: Context) {
422420
val special = contentMatcher.matches() && contentMatcher.group(1) != null
423421

424422
if (!isMulti)
425-
avatarManager.saveAvatar(
426-
groupName.hashCode(),
427-
getNotifyLargeIcon(context, original)
428-
)
423+
getNotifyLargeIcon(context, original)?.also {
424+
avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it)
425+
}
429426
val conversation = addMessage(
430427
tag, name, text, groupName, avatarManager.getAvatar(name.hashCode()),
431428
original.contentIntent, original.deleteIntent, special
@@ -454,18 +451,20 @@ abstract class NotificationProcessor(context: Context) {
454451
val name = matcher.group(1) ?: return null
455452
val text = matcher.group(2) ?: return null
456453
if (!isMulti)
457-
avatarManager.saveAvatar(name.hashCode(), getNotifyLargeIcon(context, original))
454+
getNotifyLargeIcon(context, original)?.also {
455+
avatarManager.saveAvatar(CONVERSATION_NAME_QZONE_SPECIAL.hashCode(), it)
456+
}
458457
val conversation = addMessage(
459458
tag, name, text, null, avatarManager.getAvatar(name.hashCode()),
460459
original.contentIntent, original.deleteIntent, special
461460
)
462461
deleteOldMessage(conversation, if (isMulti) 0 else matchMessageNum(titleMatcher))
463-
if (special) {
462+
return if (special) {
464463
Timber.tag(TAG).d("[FriendS] Name: $name; Text: $text")
465-
return Pair(NotifyChannel.FRIEND_SPECIAL, conversation)
464+
Pair(NotifyChannel.FRIEND_SPECIAL, conversation)
466465
} else {
467466
Timber.tag(TAG).d("[Friend] Name: $name; Text: $text")
468-
return Pair(NotifyChannel.FRIEND, conversation)
467+
Pair(NotifyChannel.FRIEND, conversation)
469468
}
470469
}
471470
}
@@ -566,8 +565,8 @@ abstract class NotificationProcessor(context: Context) {
566565
* @param notification 原有通知。
567566
* @return 通知的大图标。
568567
*/
569-
private fun getNotifyLargeIcon(context: Context, notification: Notification): Bitmap {
570-
return notification.getLargeIcon().loadDrawable(context).toBitmap()
568+
private fun getNotifyLargeIcon(context: Context, notification: Notification): Bitmap? {
569+
return notification.getLargeIcon()?.loadDrawable(context)?.toBitmap()
571570
}
572571

573572
/**

0 commit comments

Comments
 (0)