From 55a89375012234313a91af5814f5ce0b2c0579b9 Mon Sep 17 00:00:00 2001 From: gavine99 Date: Thu, 6 Feb 2025 11:47:30 +1100 Subject: [PATCH] changes to gracefully handle a failure to get contact attachment data from provider --- .../QKSMS/feature/compose/AttachmentAdapter.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/AttachmentAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/AttachmentAdapter.kt index 3761d404..682e7415 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/AttachmentAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/AttachmentAdapter.kt @@ -74,11 +74,19 @@ class AttachmentAdapter @Inject constructor( val attachment = getItem(position) if (attachment.isVCard(context)) { - val displayName = Ezvcard.parse( - String(attachment.getResourceBytes(context)) - ).first().getDisplayName() ?: "" - holder.name.text = displayName - holder.name.isVisible = displayName.isNotEmpty() + try { + val displayName = Ezvcard.parse( + String(attachment.getResourceBytes(context)) + ).first().getDisplayName() ?: "" + holder.name.text = displayName + holder.name.isVisible = displayName.isNotEmpty() + } catch (e: Exception) { + // npe from Ezvcard first() call above can be thrown if resource bytes cannot + // be retrieved from contact resource provider + holder.vCardAvatar.setImageResource(android.R.drawable.ic_delete) + holder.name.text = context.getString(R.string.attachment_missing) + holder.name.isVisible = true + } return }