Shortcuts: avoid crash when retrieving images

This commit is contained in:
ganfra 2020-06-16 17:50:43 +02:00
parent 46378845e9
commit 10d78a3102
2 changed files with 7 additions and 3 deletions

View file

@ -75,6 +75,7 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active
} }
@AnyThread @AnyThread
@Throws
fun shortcutDrawable(context: Context, glideRequest: GlideRequests, matrixItem: MatrixItem, iconSize: Int): Bitmap { fun shortcutDrawable(context: Context, glideRequest: GlideRequests, matrixItem: MatrixItem, iconSize: Int): Bitmap {
return glideRequest return glideRequest
.asBitmap() .asBitmap()

View file

@ -61,11 +61,14 @@ class ShortcutsHandler @Inject constructor(
.take(n = 4) // Android only allows us to create 4 shortcuts .take(n = 4) // Android only allows us to create 4 shortcuts
.map { room -> .map { room ->
val intent = RoomDetailActivity.shortcutIntent(context, room.roomId) val intent = RoomDetailActivity.shortcutIntent(context, room.roomId)
val bitmap = avatarRenderer.shortcutDrawable(context, GlideApp.with(context), room.toMatrixItem(), iconSize) val bitmap = try {
avatarRenderer.shortcutDrawable(context, GlideApp.with(context), room.toMatrixItem(), iconSize)
} catch (failure: Throwable) {
null
}
ShortcutInfoCompat.Builder(context, room.roomId) ShortcutInfoCompat.Builder(context, room.roomId)
.setShortLabel(room.displayName) .setShortLabel(room.displayName)
.setIcon(bitmap.toProfileImageIcon()) .setIcon(bitmap?.toProfileImageIcon())
.setIntent(intent) .setIntent(intent)
.build() .build()
} }