forked from upstream-mirrors/quik
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
}
|
||||||
@@ -21,10 +21,12 @@ package com.moez.QKSMS.feature.compose
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkAdapter
|
import com.moez.QKSMS.common.base.QkAdapter
|
||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
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.extensions.mapNotNull
|
||||||
import com.moez.QKSMS.model.Attachment
|
import com.moez.QKSMS.model.Attachment
|
||||||
import ezvcard.Ezvcard
|
import ezvcard.Ezvcard
|
||||||
@@ -78,9 +80,13 @@ class AttachmentAdapter @Inject constructor(
|
|||||||
|
|
||||||
is Attachment.Contact -> Observable.just(attachment.vCard)
|
is Attachment.Contact -> Observable.just(attachment.vCard)
|
||||||
.mapNotNull { vCard -> Ezvcard.parse(vCard).first() }
|
.mapNotNull { vCard -> Ezvcard.parse(vCard).first() }
|
||||||
|
.map { vcard -> vcard.getDisplayName() ?: "" }
|
||||||
.subscribeOn(Schedulers.computation())
|
.subscribeOn(Schedulers.computation())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.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.content.Context
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
import com.moez.QKSMS.common.base.QkViewHolder
|
||||||
import com.moez.QKSMS.common.util.Colors
|
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.resolveThemeColor
|
||||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||||
import com.moez.QKSMS.common.util.extensions.setTint
|
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())
|
Observable.just(part.getUri())
|
||||||
.map(context.contentResolver::openInputStream)
|
.map(context.contentResolver::openInputStream)
|
||||||
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
|
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
|
||||||
|
.map { vcard -> vcard.getDisplayName() ?: "" }
|
||||||
.subscribeOn(Schedulers.computation())
|
.subscribeOn(Schedulers.computation())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.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
|
val params = holder.vCardBackground.layoutParams as FrameLayout.LayoutParams
|
||||||
if (!message.isMe()) {
|
if (!message.isMe()) {
|
||||||
|
|||||||
@@ -27,7 +27,9 @@
|
|||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/vCardBackground"
|
android:id="@+id/vCardBackground"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/vCardAvatar"
|
android:id="@+id/vCardAvatar"
|
||||||
@@ -45,7 +47,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="12dp"
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="12dp"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
app:layout_constraintStart_toEndOf="@id/vCardAvatar"
|
app:layout_constraintStart_toEndOf="@id/vCardAvatar"
|
||||||
@@ -59,11 +60,11 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="12dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="12dp"
|
||||||
android:paddingBottom="8dp"
|
|
||||||
android:text="@string/compose_vcard_label"
|
android:text="@string/compose_vcard_label"
|
||||||
android:textColor="?android:attr/textColorTertiary"
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
app:layout_constraintStart_toStartOf="@id/name"
|
app:layout_constraintStart_toStartOf="@id/name"
|
||||||
app:layout_constraintTop_toBottomOf="@id/name"
|
app:layout_constraintTop_toBottomOf="@id/name"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:textSize="secondary" />
|
app:textSize="secondary" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user