Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c86ea108 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Handle VCard attachments with no name

Fixes #1812
parent cda924f0
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 Moez Bhatti <moez.bhatti@gmail.com>
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

package com.moez.QKSMS.common.util.extensions

import ezvcard.VCard

fun VCard.getDisplayName(): String? {
    return formattedName?.value
            ?: telephoneNumbers?.firstOrNull()?.text
            ?: emails?.firstOrNull()?.value
}
+7 −1
Original line number Diff line number Diff line
@@ -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()
                    }
        }
    }

+8 −2
Original line number Diff line number Diff line
@@ -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()) {
+5 −4
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/vCardBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        android:layout_height="wrap_content"
        android:paddingTop="8dp"
        android:paddingBottom="8dp">

        <ImageView
            android:id="@+id/vCardAvatar"
@@ -45,7 +47,6 @@
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingStart="12dp"
            android:paddingTop="8dp"
            android:paddingEnd="12dp"
            android:textColor="?android:attr/textColorPrimary"
            app:layout_constraintStart_toEndOf="@id/vCardAvatar"
@@ -59,11 +60,11 @@
            android:layout_height="wrap_content"
            android:paddingStart="12dp"
            android:paddingEnd="12dp"
            android:paddingBottom="8dp"
            android:text="@string/compose_vcard_label"
            android:textColor="?android:attr/textColorTertiary"
            app:layout_constraintStart_toStartOf="@id/name"
            app:layout_constraintTop_toBottomOf="@id/name"
            app:layout_constraintBottom_toBottomOf="parent"
            app:textSize="secondary" />

    </androidx.constraintlayout.widget.ConstraintLayout>