Format phone number when displaying conversation title

This commit is contained in:
Moez Bhatti
2018-03-13 20:13:27 -07:00
parent 7b116f0cc2
commit 3279d64b43
@@ -18,10 +18,12 @@
*/ */
package data.model package data.model
import android.telephony.PhoneNumberUtils
import io.realm.RealmList import io.realm.RealmList
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.Index import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import java.util.*
open class Conversation : RealmObject() { open class Conversation : RealmObject() {
@@ -34,8 +36,8 @@ open class Conversation : RealmObject() {
fun getTitle(): String { fun getTitle(): String {
var title = "" var title = ""
recipients.forEachIndexed { index, recipient -> recipients.forEachIndexed { index, recipient ->
val name = recipient.contact?.name val name = recipient.contact?.name?.takeIf { it.isNotBlank() }
title += if (name.isNullOrBlank()) recipient.address else name title += name ?: PhoneNumberUtils.formatNumber(recipient.address, Locale.getDefault().country)
if (index < recipients.size - 1) { if (index < recipients.size - 1) {
title += ", " title += ", "
} }