mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
make sure we use the proper letter at the contact colored avatar
This commit is contained in:
@ -290,12 +290,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||||||
contact_tmb.beVisibleIf(showContactThumbnails)
|
contact_tmb.beVisibleIf(showContactThumbnails)
|
||||||
|
|
||||||
if (showContactThumbnails) {
|
if (showContactThumbnails) {
|
||||||
val avatarName = when {
|
val avatarName = contact.getAvatarLetterName(context)
|
||||||
contact.isABusinessContact() -> contact.getFullCompany()
|
|
||||||
config.startNameWithSurname -> contact.surname
|
|
||||||
else -> contact.firstName
|
|
||||||
}
|
|
||||||
|
|
||||||
val placeholderImage = BitmapDrawable(resources, context.getContactLetterIcon(avatarName))
|
val placeholderImage = BitmapDrawable(resources, context.getContactLetterIcon(avatarName))
|
||||||
if (contact.photoUri.isEmpty() && contact.photo == null) {
|
if (contact.photoUri.isEmpty() && contact.photo == null) {
|
||||||
contact_tmb.setImageDrawable(placeholderImage)
|
contact_tmb.setImageDrawable(placeholderImage)
|
||||||
|
@ -242,17 +242,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
|
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
|
||||||
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
|
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
|
||||||
try {
|
try {
|
||||||
val contact = contacts[position]
|
val name = contacts[position].getAvatarLetterName(context)
|
||||||
var name = when {
|
|
||||||
contact.isABusinessContact() -> contact.getFullCompany()
|
|
||||||
config.startNameWithSurname -> contact.surname
|
|
||||||
else -> contact.firstName
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name.isEmpty() && contact.emails.isNotEmpty()) {
|
|
||||||
name = contact.emails.first().value
|
|
||||||
}
|
|
||||||
|
|
||||||
var character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
var character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||||
if (!character.areLettersOnly()) {
|
if (!character.areLettersOnly()) {
|
||||||
character = "#"
|
character = "#"
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.simplemobiletools.contacts.pro.models
|
package com.simplemobiletools.contacts.pro.models
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.telephony.PhoneNumberUtils
|
import android.telephony.PhoneNumberUtils
|
||||||
import com.simplemobiletools.commons.extensions.normalizeString
|
import com.simplemobiletools.commons.extensions.normalizeString
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
||||||
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
||||||
|
|
||||||
@ -140,4 +142,22 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||||||
fun isPrivate() = source == SMT_PRIVATE
|
fun isPrivate() = source == SMT_PRIVATE
|
||||||
|
|
||||||
fun getSignatureKey() = if (photoUri.isNotEmpty()) photoUri else hashCode()
|
fun getSignatureKey() = if (photoUri.isNotEmpty()) photoUri else hashCode()
|
||||||
|
|
||||||
|
fun getAvatarLetterName(context: Context): String {
|
||||||
|
var name = when {
|
||||||
|
isABusinessContact() -> getFullCompany()
|
||||||
|
context.config.startNameWithSurname -> surname
|
||||||
|
else -> firstName
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.isEmpty() && emails.isNotEmpty()) {
|
||||||
|
name = emails.first().value
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
name = getNameToDisplay()
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user