mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-07 04:43:24 +01:00
Workaround some potential exceptions
This commit is contained in:
parent
09956f809d
commit
b6012f6e2b
@ -24,9 +24,13 @@ fun View.setupDocumentPreview(
|
||||
filename.text = title
|
||||
}
|
||||
|
||||
val size = context.getFileSizeFromUri(uri)
|
||||
file_size.beVisible()
|
||||
file_size.text = size.formatSize()
|
||||
try {
|
||||
val size = context.getFileSizeFromUri(uri)
|
||||
file_size.beVisible()
|
||||
file_size.text = size.formatSize()
|
||||
} catch (e: Exception) {
|
||||
file_size.beGone()
|
||||
}
|
||||
|
||||
val textColor = context.getProperTextColor()
|
||||
val primaryColor = context.getProperPrimaryColor()
|
||||
@ -82,13 +86,19 @@ fun View.setupVCardPreview(
|
||||
}
|
||||
|
||||
parseVCardFromUri(activity, uri) { vCards ->
|
||||
val title = vCards.firstOrNull()?.parseNameFromVCard()
|
||||
val imageIcon = if (title != null) {
|
||||
SimpleContactsHelper(activity).getContactLetterIcon(title)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
activity.runOnUiThread {
|
||||
if (vCards.isEmpty()) {
|
||||
vcard_title.beVisible()
|
||||
vcard_title.text = context.getString(R.string.unknown_error_occurred)
|
||||
return@runOnUiThread
|
||||
}
|
||||
val title = vCards.firstOrNull()?.parseNameFromVCard()
|
||||
val imageIcon = if (title != null) {
|
||||
SimpleContactsHelper(activity).getContactLetterIcon(title)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
arrayOf(vcard_photo, vcard_title).forEach {
|
||||
it.beVisible()
|
||||
}
|
||||
|
@ -8,7 +8,12 @@ import ezvcard.VCard
|
||||
|
||||
fun parseVCardFromUri(context: Context, uri: Uri, callback: (vCards: List<VCard>) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
val inputStream = context.contentResolver.openInputStream(uri)
|
||||
val inputStream = try {
|
||||
context.contentResolver.openInputStream(uri)
|
||||
} catch (e: Exception) {
|
||||
callback(emptyList())
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
val vCards = Ezvcard.parse(inputStream).all()
|
||||
callback(vCards)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user