From 65239e403489f2439c67ff4759877c93390079ce Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 21 Feb 2022 12:04:02 +0000 Subject: [PATCH 1/7] relying on the glide caches (persisted and in memory) instead of our own - this effectively halves the amount of image memory used by notifications --- .../vector/app/features/notifications/BitmapLoader.kt | 10 +--------- .../im/vector/app/features/notifications/IconLoader.kt | 9 +-------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt b/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt index d1c4624cdc..da0f071841 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt @@ -28,11 +28,6 @@ import javax.inject.Singleton @Singleton class BitmapLoader @Inject constructor(private val context: Context) { - /** - * Avatar Url -> Bitmap - */ - private val cache = HashMap() - /** * Get icon of a room. * If already in cache, use it, else load it and call BitmapLoaderListener.onBitmapsLoaded() when ready @@ -42,10 +37,7 @@ class BitmapLoader @Inject constructor(private val context: Context) { if (path == null) { return null } - - return cache.getOrPut(path) { - loadRoomBitmap(path) - } + return loadRoomBitmap(path) } @WorkerThread diff --git a/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt b/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt index 3e68744c88..ec53e89d57 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt @@ -30,11 +30,6 @@ import javax.inject.Singleton @Singleton class IconLoader @Inject constructor(private val context: Context) { - /** - * Avatar Url -> IconCompat - */ - private val cache = HashMap() - /** * Get icon of a user. * If already in cache, use it, else load it and call IconLoaderListener.onIconsLoaded() when ready @@ -46,9 +41,7 @@ class IconLoader @Inject constructor(private val context: Context) { return null } - return cache.getOrPut(path) { - loadUserIcon(path) - } + return loadUserIcon(path) } @WorkerThread From eeb9785651d844ba2675c0c684f210638ebb1762 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 21 Feb 2022 13:03:31 +0000 Subject: [PATCH 2/7] limiting the room bitmap loader image size, the notification icon size is relatively small and there's no cap on the image size --- .../im/vector/app/features/notifications/BitmapLoader.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt b/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt index da0f071841..9190141dfb 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt @@ -21,6 +21,7 @@ import android.graphics.Bitmap import androidx.annotation.WorkerThread import com.bumptech.glide.Glide import com.bumptech.glide.load.DecodeFormat +import com.bumptech.glide.signature.ObjectKey import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton @@ -28,6 +29,9 @@ import javax.inject.Singleton @Singleton class BitmapLoader @Inject constructor(private val context: Context) { + private val iconWidth = context.resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width) + private val iconHeight = context.resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height) + /** * Get icon of a room. * If already in cache, use it, else load it and call BitmapLoaderListener.onBitmapsLoaded() when ready @@ -47,8 +51,10 @@ class BitmapLoader @Inject constructor(private val context: Context) { Glide.with(context) .asBitmap() .load(path) + .fitCenter() .format(DecodeFormat.PREFER_ARGB_8888) - .submit() + .signature(ObjectKey("room-icon-notification")) + .submit(iconWidth, iconHeight) .get() } catch (e: Exception) { Timber.e(e, "decodeFile failed") From 9f44975b4a23ec6bf3398e8dc24862ac49acbe3a Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 21 Feb 2022 16:54:51 +0000 Subject: [PATCH 3/7] tranforming images for adaptive shortcuts within glides transformations - avoid creating new bitmaps each time the room list changes --- .../home/AdaptiveIconTransformation.kt | 54 +++++++++++++++++++ .../app/features/home/AvatarRenderer.kt | 45 +++++++++++----- .../app/features/home/ShortcutCreator.kt | 14 ++--- 3 files changed, 92 insertions(+), 21 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt diff --git a/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt b/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt new file mode 100644 index 0000000000..9efd842e58 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.home + +import android.graphics.Bitmap +import android.graphics.Canvas +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation +import com.bumptech.glide.util.Util +import java.nio.ByteBuffer +import java.security.MessageDigest + +private const val ADAPTIVE_TRANSFORMATION_ID = "adaptive-icon-transform" +private val ID_BYTES = ADAPTIVE_TRANSFORMATION_ID.toByteArray() + +class AdaptiveIconTransformation(private val adaptiveIconSize: Int, private val adaptiveIconOuterSides: Float) : BitmapTransformation() { + + override fun updateDiskCacheKey(messageDigest: MessageDigest) { + messageDigest.update(ID_BYTES) + messageDigest.update(ByteBuffer.allocate(4).putInt(adaptiveIconSize).putFloat(adaptiveIconOuterSides).array()) + } + + override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap { + val insetBmp = Bitmap.createBitmap(adaptiveIconSize, adaptiveIconSize, Bitmap.Config.ARGB_8888) + val canvas = Canvas(insetBmp) + canvas.drawBitmap(toTransform, adaptiveIconOuterSides, adaptiveIconOuterSides, null) + canvas.setBitmap(null) + return insetBmp + } + + override fun equals(other: Any?): Boolean { + return if (other is AdaptiveIconTransformation) { + other.adaptiveIconSize == adaptiveIconSize && other.adaptiveIconOuterSides == adaptiveIconOuterSides + } else { + false + } + } + + override fun hashCode() = Util.hashCode(ADAPTIVE_TRANSFORMATION_ID.hashCode(), Util.hashCode(adaptiveIconSize, Util.hashCode(adaptiveIconOuterSides))) +} diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index 2ee3233637..d8a8409f5a 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -26,6 +26,7 @@ import androidx.core.graphics.drawable.toBitmap import com.amulyakhare.textdrawable.TextDrawable import com.bumptech.glide.load.MultiTransformation import com.bumptech.glide.load.Transformation +import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.CircleCrop import com.bumptech.glide.load.resource.bitmap.RoundedCorners @@ -157,25 +158,41 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active fun shortcutDrawable(glideRequests: GlideRequests, matrixItem: MatrixItem, iconSize: Int): Bitmap { return glideRequests .asBitmap() - .let { - val resolvedUrl = resolvedUrl(matrixItem.avatarUrl) - if (resolvedUrl != null) { - it.load(resolvedUrl) - } else { - val avatarColor = matrixItemColorProvider.getColor(matrixItem) - it.load(TextDrawable.builder() - .beginConfig() - .bold() - .endConfig() - .buildRect(matrixItem.firstLetterOfDisplayName(), avatarColor) - .toBitmap(width = iconSize, height = iconSize)) - } - } + .avatarOrText(matrixItem, iconSize) .apply(RequestOptions.centerCropTransform()) .submit(iconSize, iconSize) .get() } + @AnyThread + @Throws + fun adaptiveShortcutDrawable(glideRequests: GlideRequests, matrixItem: MatrixItem, iconSize: Int, adaptiveIconSize: Int, adaptiveIconOuterSides: Float): Bitmap { + return glideRequests + .asBitmap() + .avatarOrText(matrixItem, iconSize) + .transform(CenterCrop(), AdaptiveIconTransformation(adaptiveIconSize, adaptiveIconOuterSides)) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .submit(adaptiveIconSize, adaptiveIconSize) + .get() + } + + private fun GlideRequest.avatarOrText(matrixItem: MatrixItem, iconSize: Int): GlideRequest { + return this.let { + val resolvedUrl = resolvedUrl(matrixItem.avatarUrl) + if (resolvedUrl != null) { + it.load(resolvedUrl) + } else { + val avatarColor = matrixItemColorProvider.getColor(matrixItem) + it.load(TextDrawable.builder() + .beginConfig() + .bold() + .endConfig() + .buildRect(matrixItem.firstLetterOfDisplayName(), avatarColor) + .toBitmap(width = iconSize, height = iconSize)) + } + } + } + @UiThread fun renderBlur(matrixItem: MatrixItem, imageView: ImageView, diff --git a/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt index ee7edc021d..082d318cc7 100644 --- a/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt +++ b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt @@ -19,7 +19,6 @@ package im.vector.app.features.home import android.content.Context import android.content.pm.ShortcutInfo import android.graphics.Bitmap -import android.graphics.Canvas import android.os.Build import androidx.annotation.WorkerThread import androidx.core.content.pm.ShortcutInfoCompat @@ -61,7 +60,12 @@ class ShortcutCreator @Inject constructor( fun create(roomSummary: RoomSummary, rank: Int = 1): ShortcutInfoCompat { val intent = RoomDetailActivity.shortcutIntent(context, roomSummary.roomId) val bitmap = try { - avatarRenderer.shortcutDrawable(GlideApp.with(context), roomSummary.toMatrixItem(), iconSize) + val glideRequests = GlideApp.with(context) + val matrixItem = roomSummary.toMatrixItem() + when (useAdaptiveIcon) { + true -> avatarRenderer.adaptiveShortcutDrawable(glideRequests, matrixItem, iconSize, adaptiveIconSize, adaptiveIconOuterSides.toFloat()) + false -> avatarRenderer.shortcutDrawable(glideRequests, matrixItem, iconSize) + } } catch (failure: Throwable) { null } @@ -83,11 +87,7 @@ class ShortcutCreator @Inject constructor( private fun Bitmap.toProfileImageIcon(): IconCompat { return if (useAdaptiveIcon) { - val insetBmp = Bitmap.createBitmap(adaptiveIconSize, adaptiveIconSize, Bitmap.Config.ARGB_8888) - val canvas = Canvas(insetBmp) - canvas.drawBitmap(this, adaptiveIconOuterSides.toFloat(), adaptiveIconOuterSides.toFloat(), null) - - IconCompat.createWithAdaptiveBitmap(insetBmp) + IconCompat.createWithAdaptiveBitmap(this) } else { IconCompat.createWithBitmap(this) } From 33c30e27faa68a64b07a04dbd9e13a48f96f1ad2 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 21 Feb 2022 17:14:36 +0000 Subject: [PATCH 4/7] flattening the room and user icon loading into the same file --- .../features/notifications/BitmapLoader.kt | 65 ------------- .../app/features/notifications/IconLoader.kt | 66 ------------- .../notifications/NotificationBitmapLoader.kt | 92 +++++++++++++++++++ .../notifications/RoomGroupMessageCreator.kt | 11 +-- 4 files changed, 96 insertions(+), 138 deletions(-) delete mode 100644 vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt delete mode 100644 vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt create mode 100644 vector/src/main/java/im/vector/app/features/notifications/NotificationBitmapLoader.kt diff --git a/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt b/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt deleted file mode 100644 index 9190141dfb..0000000000 --- a/vector/src/main/java/im/vector/app/features/notifications/BitmapLoader.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.app.features.notifications - -import android.content.Context -import android.graphics.Bitmap -import androidx.annotation.WorkerThread -import com.bumptech.glide.Glide -import com.bumptech.glide.load.DecodeFormat -import com.bumptech.glide.signature.ObjectKey -import timber.log.Timber -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class BitmapLoader @Inject constructor(private val context: Context) { - - private val iconWidth = context.resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width) - private val iconHeight = context.resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height) - - /** - * Get icon of a room. - * If already in cache, use it, else load it and call BitmapLoaderListener.onBitmapsLoaded() when ready - */ - @WorkerThread - fun getRoomBitmap(path: String?): Bitmap? { - if (path == null) { - return null - } - return loadRoomBitmap(path) - } - - @WorkerThread - private fun loadRoomBitmap(path: String): Bitmap? { - return path.let { - try { - Glide.with(context) - .asBitmap() - .load(path) - .fitCenter() - .format(DecodeFormat.PREFER_ARGB_8888) - .signature(ObjectKey("room-icon-notification")) - .submit(iconWidth, iconHeight) - .get() - } catch (e: Exception) { - Timber.e(e, "decodeFile failed") - null - } - } - } -} diff --git a/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt b/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt deleted file mode 100644 index ec53e89d57..0000000000 --- a/vector/src/main/java/im/vector/app/features/notifications/IconLoader.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.app.features.notifications - -import android.content.Context -import android.os.Build -import androidx.annotation.WorkerThread -import androidx.core.graphics.drawable.IconCompat -import com.bumptech.glide.Glide -import com.bumptech.glide.load.DecodeFormat -import com.bumptech.glide.request.RequestOptions -import timber.log.Timber -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class IconLoader @Inject constructor(private val context: Context) { - - /** - * Get icon of a user. - * If already in cache, use it, else load it and call IconLoaderListener.onIconsLoaded() when ready - * Before Android P, this does nothing because the icon won't be used - */ - @WorkerThread - fun getUserIcon(path: String?): IconCompat? { - if (path == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - return null - } - - return loadUserIcon(path) - } - - @WorkerThread - private fun loadUserIcon(path: String): IconCompat? { - return path.let { - try { - Glide.with(context) - .asBitmap() - .load(path) - .apply(RequestOptions.circleCropTransform() - .format(DecodeFormat.PREFER_ARGB_8888)) - .submit() - .get() - } catch (e: Exception) { - Timber.e(e, "decodeFile failed") - null - }?.let { bitmap -> - IconCompat.createWithBitmap(bitmap) - } - } - } -} diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationBitmapLoader.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationBitmapLoader.kt new file mode 100644 index 0000000000..518b011ffd --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationBitmapLoader.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.notifications + +import android.content.Context +import android.graphics.Bitmap +import android.os.Build +import androidx.annotation.WorkerThread +import androidx.core.graphics.drawable.IconCompat +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DecodeFormat +import com.bumptech.glide.load.resource.bitmap.CircleCrop +import com.bumptech.glide.signature.ObjectKey +import timber.log.Timber +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class NotificationBitmapLoader @Inject constructor(private val context: Context) { + + /** + * Get icon of a room + */ + @WorkerThread + fun getRoomBitmap(path: String?): Bitmap? { + if (path == null) { + return null + } + return loadRoomBitmap(path) + } + + @WorkerThread + private fun loadRoomBitmap(path: String): Bitmap? { + return try { + Glide.with(context) + .asBitmap() + .load(path) + .format(DecodeFormat.PREFER_ARGB_8888) + .signature(ObjectKey("room-icon-notification")) + .submit() + .get() + } catch (e: Exception) { + Timber.e(e, "decodeFile failed") + null + } + } + + /** + * Get icon of a user. + * Before Android P, this does nothing because the icon won't be used + */ + @WorkerThread + fun getUserIcon(path: String?): IconCompat? { + if (path == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + return null + } + + return loadUserIcon(path) + } + + @WorkerThread + private fun loadUserIcon(path: String): IconCompat? { + return try { + val bitmap = Glide.with(context) + .asBitmap() + .load(path) + .transform(CircleCrop()) + .format(DecodeFormat.PREFER_ARGB_8888) + .signature(ObjectKey("user-icon-notification")) + .submit() + .get() + IconCompat.createWithBitmap(bitmap) + } catch (e: Exception) { + Timber.e(e, "decodeFile failed") + null + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt b/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt index b57c81f686..8310c15daa 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt @@ -16,7 +16,6 @@ package im.vector.app.features.notifications -import android.content.Context import android.graphics.Bitmap import androidx.core.app.NotificationCompat import androidx.core.app.Person @@ -28,11 +27,9 @@ import timber.log.Timber import javax.inject.Inject class RoomGroupMessageCreator @Inject constructor( - private val iconLoader: IconLoader, - private val bitmapLoader: BitmapLoader, + private val bitmapLoader: NotificationBitmapLoader, private val stringProvider: StringProvider, - private val notificationUtils: NotificationUtils, - private val appContext: Context + private val notificationUtils: NotificationUtils ) { fun createRoomMessage(events: List, roomId: String, userDisplayName: String, userAvatarUrl: String?): RoomNotification.Message { @@ -41,7 +38,7 @@ class RoomGroupMessageCreator @Inject constructor( val roomIsGroup = !firstKnownRoomEvent.roomIsDirect val style = NotificationCompat.MessagingStyle(Person.Builder() .setName(userDisplayName) - .setIcon(iconLoader.getUserIcon(userAvatarUrl)) + .setIcon(bitmapLoader.getUserIcon(userAvatarUrl)) .setKey(firstKnownRoomEvent.matrixID) .build() ).also { @@ -92,7 +89,7 @@ class RoomGroupMessageCreator @Inject constructor( } else { Person.Builder() .setName(event.senderName) - .setIcon(iconLoader.getUserIcon(event.senderAvatarPath)) + .setIcon(bitmapLoader.getUserIcon(event.senderAvatarPath)) .setKey(event.senderId) .build() } From 5bbb3f28b14186e750385cfa3bb6cb308e453ccf Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 21 Feb 2022 17:30:45 +0000 Subject: [PATCH 5/7] adding changelog entry --- changelog.d/5276.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5276.misc diff --git a/changelog.d/5276.misc b/changelog.d/5276.misc new file mode 100644 index 0000000000..437bd28eb6 --- /dev/null +++ b/changelog.d/5276.misc @@ -0,0 +1 @@ +Improves bitmap memory usage by caching the shortcut images \ No newline at end of file From 506690a8979a58203f0a1cf9dc31acde0cabf050 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 21 Feb 2022 17:54:05 +0000 Subject: [PATCH 6/7] fixing wrong shortcut icon size and ensuring the transformed files are stored with unique keys --- .../im/vector/app/features/home/AdaptiveIconTransformation.kt | 2 +- .../main/java/im/vector/app/features/home/AvatarRenderer.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt b/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt index 9efd842e58..6eb41a1d85 100644 --- a/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt +++ b/vector/src/main/java/im/vector/app/features/home/AdaptiveIconTransformation.kt @@ -31,7 +31,7 @@ class AdaptiveIconTransformation(private val adaptiveIconSize: Int, private val override fun updateDiskCacheKey(messageDigest: MessageDigest) { messageDigest.update(ID_BYTES) - messageDigest.update(ByteBuffer.allocate(4).putInt(adaptiveIconSize).putFloat(adaptiveIconOuterSides).array()) + messageDigest.update(ByteBuffer.allocate(8).putInt(adaptiveIconSize).putFloat(adaptiveIconOuterSides).array()) } override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap { diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index d8a8409f5a..5b96caa3f1 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -33,6 +33,7 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.DrawableImageViewTarget import com.bumptech.glide.request.target.Target +import com.bumptech.glide.signature.ObjectKey import im.vector.app.core.contacts.MappedContact import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.glide.AvatarPlaceholder @@ -171,8 +172,9 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active .asBitmap() .avatarOrText(matrixItem, iconSize) .transform(CenterCrop(), AdaptiveIconTransformation(adaptiveIconSize, adaptiveIconOuterSides)) + .signature(ObjectKey("adaptive-icon")) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .submit(adaptiveIconSize, adaptiveIconSize) + .submit(iconSize, iconSize) .get() } From bad45799b97d7b832a7398bc9af54930c16ea321 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 22 Feb 2022 09:45:20 +0000 Subject: [PATCH 7/7] reducing line length (using existing formatting style) --- .../main/java/im/vector/app/features/home/AvatarRenderer.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index 5b96caa3f1..3678808b2d 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -167,7 +167,10 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active @AnyThread @Throws - fun adaptiveShortcutDrawable(glideRequests: GlideRequests, matrixItem: MatrixItem, iconSize: Int, adaptiveIconSize: Int, adaptiveIconOuterSides: Float): Bitmap { + fun adaptiveShortcutDrawable(glideRequests: GlideRequests, + matrixItem: MatrixItem, iconSize: Int, + adaptiveIconSize: Int, + adaptiveIconOuterSides: Float): Bitmap { return glideRequests .asBitmap() .avatarOrText(matrixItem, iconSize)