diff --git a/presentation/src/main/java/com/moez/QKSMS/common/util/extensions/VCardExtension.kt b/presentation/src/main/java/com/moez/QKSMS/common/util/extensions/VCardExtension.kt new file mode 100644 index 00000000..8099e399 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/common/util/extensions/VCardExtension.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 Moez Bhatti + * + * This file is part of QKSMS. + * + * QKSMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QKSMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QKSMS. If not, see . + */ + +package com.moez.QKSMS.common.util.extensions + +import ezvcard.VCard + +fun VCard.getDisplayName(): String? { + return formattedName?.value + ?: telephoneNumbers?.firstOrNull()?.text + ?: emails?.firstOrNull()?.value +} 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 3563798b..f01bb088 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 @@ -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() + } } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt index 9e068137..3d464d51 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt @@ -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 } } -} \ No newline at end of file +} diff --git a/presentation/src/main/res/layout/mms_vcard_list_item.xml b/presentation/src/main/res/layout/mms_vcard_list_item.xml index b237b016..5e9d33e2 100644 --- a/presentation/src/main/res/layout/mms_vcard_list_item.xml +++ b/presentation/src/main/res/layout/mms_vcard_list_item.xml @@ -27,7 +27,9 @@ + android:layout_height="wrap_content" + android:paddingTop="8dp" + android:paddingBottom="8dp"> - \ No newline at end of file +