Fixed emoji display in contacts' name
This commit is contained in:
parent
4495fe5273
commit
66bd8f26b5
4 changed files with 21 additions and 4 deletions
|
@ -178,6 +178,9 @@ dependencies {
|
||||||
implementation 'com.google.android.material:material:1.2.1'
|
implementation 'com.google.android.material:material:1.2.1'
|
||||||
implementation 'com.google.android:flexbox:2.0.0'
|
implementation 'com.google.android:flexbox:2.0.0'
|
||||||
|
|
||||||
|
implementation 'androidx.emoji:emoji:1.1.0'
|
||||||
|
implementation 'androidx.emoji:emoji-bundled:1.1.0'
|
||||||
|
|
||||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||||
kapt 'com.github.bumptech.glide:compiler:4.11.0'
|
kapt 'com.github.bumptech.glide:compiler:4.11.0'
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.linphone.activities.main.viewmodels.ListTopBarViewModel
|
||||||
import org.linphone.contact.Contact
|
import org.linphone.contact.Contact
|
||||||
import org.linphone.databinding.ContactListCellBinding
|
import org.linphone.databinding.ContactListCellBinding
|
||||||
import org.linphone.databinding.GenericListHeaderBinding
|
import org.linphone.databinding.GenericListHeaderBinding
|
||||||
|
import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.HeaderAdapter
|
import org.linphone.utils.HeaderAdapter
|
||||||
import org.linphone.utils.SelectionListAdapter
|
import org.linphone.utils.SelectionListAdapter
|
||||||
|
@ -109,7 +110,7 @@ class ContactsListAdapter(
|
||||||
|
|
||||||
override fun getHeaderViewForPosition(context: Context, position: Int): View {
|
override fun getHeaderViewForPosition(context: Context, position: Int): View {
|
||||||
val contact = getItem(position)
|
val contact = getItem(position)
|
||||||
val firstLetter = contact.fullName?.first().toString()
|
val firstLetter = AppUtils.getInitials(contact.fullName ?: "", 1)
|
||||||
val binding: GenericListHeaderBinding = DataBindingUtil.inflate(
|
val binding: GenericListHeaderBinding = DataBindingUtil.inflate(
|
||||||
LayoutInflater.from(context),
|
LayoutInflater.from(context),
|
||||||
R.layout.generic_list_header, null, false
|
R.layout.generic_list_header, null, false
|
||||||
|
|
|
@ -29,6 +29,8 @@ import android.os.Vibrator
|
||||||
import android.telephony.PhoneStateListener
|
import android.telephony.PhoneStateListener
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
import androidx.emoji.bundled.BundledEmojiCompatConfig
|
||||||
|
import androidx.emoji.text.EmojiCompat
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
@ -233,6 +235,8 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||||
Log.i("[Context] Registering phone state listener")
|
Log.i("[Context] Registering phone state listener")
|
||||||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
|
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
|
||||||
|
|
||||||
|
EmojiCompat.init(BundledEmojiCompatConfig(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.content.*
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
|
import androidx.emoji.text.EmojiCompat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
|
@ -93,15 +94,23 @@ class AppUtils {
|
||||||
return HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
return HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getInitials(displayName: String): String {
|
fun getInitials(displayName: String, limit: Int = 2): String {
|
||||||
if (displayName.isEmpty()) return ""
|
if (displayName.isEmpty()) return ""
|
||||||
|
|
||||||
|
val emoji = EmojiCompat.get()
|
||||||
val split = displayName.toUpperCase(Locale.getDefault()).split(" ")
|
val split = displayName.toUpperCase(Locale.getDefault()).split(" ")
|
||||||
var initials = ""
|
var initials = ""
|
||||||
|
var characters = 0
|
||||||
|
|
||||||
for (i in split.indices) {
|
for (i in split.indices) {
|
||||||
if (split[i].isNotEmpty()) {
|
if (split[i].isNotEmpty()) {
|
||||||
initials += split[i][0]
|
if (emoji.hasEmojiGlyph(split[i])) {
|
||||||
if (initials.length >= 2) break
|
initials += emoji.process(split[i])
|
||||||
|
} else {
|
||||||
|
initials += split[i][0]
|
||||||
|
}
|
||||||
|
characters += 1
|
||||||
|
if (characters >= limit) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initials
|
return initials
|
||||||
|
|
Loading…
Reference in a new issue