show proper letters on the fastscroller, no matter the sorting
This commit is contained in:
parent
3e78be6e88
commit
cfc1eddc33
|
@ -9,6 +9,7 @@ import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
|||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
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_SURNAME
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.activities.GroupContactsActivity
|
||||
|
@ -242,7 +243,24 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
|
||||
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
|
||||
try {
|
||||
val name = contacts[position].getAvatarLetterName(context)
|
||||
val contact = contacts[position]
|
||||
var name = when {
|
||||
contact.isABusinessContact() -> contact.getFullCompany()
|
||||
context.config.sorting and SORT_BY_SURNAME != 0 && contact.surname.isNotEmpty() -> contact.surname
|
||||
context.config.sorting and SORT_BY_MIDDLE_NAME != 0 && contact.middleName.isNotEmpty() -> contact.middleName
|
||||
context.config.sorting and SORT_BY_FIRST_NAME != 0 && contact.firstName.isNotEmpty() -> contact.firstName
|
||||
context.config.startNameWithSurname -> contact.surname
|
||||
else -> contact.firstName
|
||||
}
|
||||
|
||||
if (name.isEmpty() && contact.emails.isNotEmpty()) {
|
||||
name = contact.emails.first().value
|
||||
}
|
||||
|
||||
if (name.isEmpty()) {
|
||||
name = contact.getNameToDisplay()
|
||||
}
|
||||
|
||||
var character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||
if (!character.areLettersOnly()) {
|
||||
character = "#"
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.simplemobiletools.contacts.pro.models
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.simplemobiletools.commons.extensions.normalizeString
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||
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.helpers.SMT_PRIVATE
|
||||
|
||||
|
@ -142,22 +140,4 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
fun isPrivate() = source == SMT_PRIVATE
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue