Handle VCard attachments with no name

Fixes #1812
This commit is contained in:
Moez Bhatti
2021-10-28 17:14:35 -04:00
parent cda924f097
commit c86ea1082d
4 changed files with 48 additions and 7 deletions
@@ -21,10 +21,12 @@ package com.moez.QKSMS.feature.compose
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.bumptech.glide.Glide
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.common.util.extensions.getDisplayName
import com.moez.QKSMS.extensions.mapNotNull
import com.moez.QKSMS.model.Attachment
import ezvcard.Ezvcard
@@ -78,9 +80,13 @@ class AttachmentAdapter @Inject constructor(
is Attachment.Contact -> Observable.just(attachment.vCard)
.mapNotNull { vCard -> Ezvcard.parse(vCard).first() }
.map { vcard -> vcard.getDisplayName() ?: "" }
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { vcard -> holder.name?.text = vcard.formattedName.value }
.subscribe { displayName ->
holder.name?.text = displayName
holder.name?.isVisible = displayName.isNotEmpty()
}
}
}
@@ -21,9 +21,11 @@ package com.moez.QKSMS.feature.compose.part
import android.content.Context
import android.view.Gravity
import android.widget.FrameLayout
import androidx.core.view.isVisible
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.getDisplayName
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
@@ -61,9 +63,13 @@ class VCardBinder @Inject constructor(colors: Colors, private val context: Conte
Observable.just(part.getUri())
.map(context.contentResolver::openInputStream)
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
.map { vcard -> vcard.getDisplayName() ?: "" }
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { vcard -> holder.name?.text = vcard.formattedName.value }
.subscribe { displayName ->
holder.name?.text = displayName
holder.name.isVisible = displayName.isNotEmpty()
}
val params = holder.vCardBackground.layoutParams as FrameLayout.LayoutParams
if (!message.isMe()) {
@@ -81,4 +87,4 @@ class VCardBinder @Inject constructor(colors: Colors, private val context: Conte
}
}
}
}