Use a Bitmap instead of a BitmapDrawable for open group attachment notification icon.

This commit is contained in:
Anton Chekulaev 2020-10-01 21:15:22 +10:00
parent 7dffacf957
commit f620d1cdb9
4 changed files with 17 additions and 11 deletions

View File

@ -79,8 +79,6 @@ class PublicChatManager(private val context: Context) {
?.downloadOpenGroupAvatar(server, info.profilePictureURL)
avatar = BitmapUtil.fromByteArray(avatarBytes)
}
// FIXME: If updating the avatar here, there can be a memory issue if a public chat message contains some attachment.
// The error message is "Failed to execute task in background: Canvas: trying to use a recycled bitmap android.graphics.Bitmap"
val result = GroupManager.createOpenGroup(chat.id, context, avatar, chat.displayName)
threadID = result.threadId
}

View File

@ -69,8 +69,7 @@ class ProfilePictureView : RelativeLayout {
}
}
fun isOpenGroupWithAvatar(recipient: Recipient): Boolean {
return recipient.isOpenGroupRecipient &&
DatabaseFactory.getGroupDatabase(context).hasAvatar(recipient.address.toString())
return recipient.isOpenGroupRecipient && recipient.groupAvatarId != null
}
if (recipient.isGroupRecipient && !isOpenGroupWithAvatar(recipient)) {
val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toMutableList() ?: mutableListOf()

View File

@ -84,13 +84,17 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
ContactPhoto contactPhoto = recipient.getContactPhoto();
if (contactPhoto != null) {
try {
setLargeIcon(GlideApp.with(context.getApplicationContext())
// AC: For some reason, if not use ".asBitmap()" method, the returned BitmapDrawable
// wraps a recycled bitmap and leads to a crash.
Bitmap iconBitmap = GlideApp.with(context.getApplicationContext())
.asBitmap()
.load(contactPhoto)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.circleCrop()
.submit(context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height))
.get());
.get();
setLargeIcon(iconBitmap);
} catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e);
setLargeIcon(getPlaceholderDrawable(context, recipient));

View File

@ -509,6 +509,11 @@ public class Recipient implements RecipientModifiedListener {
if (notify) notifyListeners();
}
@Nullable
public synchronized Long getGroupAvatarId() {
return groupAvatarId;
}
public synchronized @Nullable Uri getMessageRingtone() {
if (messageRingtone != null && messageRingtone.getScheme() != null && messageRingtone.getScheme().startsWith("file")) {
return null;