From 9976cee5873eebf168234e1e3debad891b86f742 Mon Sep 17 00:00:00 2001 From: Honk2 Date: Sun, 5 Jan 2025 23:49:09 +0100 Subject: [PATCH] fix sorting issue #186 --- .../fossify/phone/fragments/ContactsFragment.kt | 17 ++++++++++++++++- .../phone/fragments/FavoritesFragment.kt | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/phone/fragments/ContactsFragment.kt b/app/src/main/kotlin/org/fossify/phone/fragments/ContactsFragment.kt index fdaa9e3e..d0e7d32f 100644 --- a/app/src/main/kotlin/org/fossify/phone/fragments/ContactsFragment.kt +++ b/app/src/main/kotlin/org/fossify/phone/fragments/ContactsFragment.kt @@ -13,6 +13,7 @@ import org.fossify.phone.activities.SimpleActivity import org.fossify.phone.adapters.ContactsAdapter import org.fossify.phone.databinding.FragmentContactsBinding import org.fossify.phone.databinding.FragmentLettersLayoutBinding +import org.fossify.phone.extensions.config import org.fossify.phone.extensions.launchCreateNewContactIntent import org.fossify.phone.extensions.startContactDetailsIntent import org.fossify.phone.interfaces.RefreshItemsListener @@ -130,9 +131,23 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag } private fun setupLetterFastScroller(contacts: ArrayList) { + val sorting = context.config.sorting binding.letterFastscroller.setupWithRecyclerView(binding.fragmentList, { position -> try { - val name = contacts[position].getNameToDisplay() + val contact = contacts[position] + var name = when { + contact.isABusinessContact() -> contact.getFullCompany() + sorting and SORT_BY_SURNAME != 0 && contact.surname.isNotEmpty() -> contact.surname + sorting and SORT_BY_MIDDLE_NAME != 0 && contact.middleName.isNotEmpty() -> contact.middleName + sorting and SORT_BY_FIRST_NAME != 0 && contact.firstName.isNotEmpty() -> contact.firstName + context.config.startNameWithSurname -> contact.surname + else -> contact.firstName + } + + if (name.isEmpty()) { + name = contact.getNameToDisplay() + } + val character = if (name.isNotEmpty()) name.substring(0, 1) else "" FastScrollItemIndicator.Text(character.uppercase(Locale.getDefault()).normalizeString()) } catch (e: Exception) { diff --git a/app/src/main/kotlin/org/fossify/phone/fragments/FavoritesFragment.kt b/app/src/main/kotlin/org/fossify/phone/fragments/FavoritesFragment.kt index beb190bb..6f15009b 100644 --- a/app/src/main/kotlin/org/fossify/phone/fragments/FavoritesFragment.kt +++ b/app/src/main/kotlin/org/fossify/phone/fragments/FavoritesFragment.kt @@ -181,9 +181,23 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa } private fun setupLetterFastScroller(contacts: List) { + val sorting = context.config.sorting binding.letterFastscroller.setupWithRecyclerView(binding.fragmentList, { position -> try { - val name = contacts[position].getNameToDisplay() + val contact = contacts[position] + var name = when { + contact.isABusinessContact() -> contact.getFullCompany() + sorting and SORT_BY_SURNAME != 0 && contact.surname.isNotEmpty() -> contact.surname + sorting and SORT_BY_MIDDLE_NAME != 0 && contact.middleName.isNotEmpty() -> contact.middleName + sorting and SORT_BY_FIRST_NAME != 0 && contact.firstName.isNotEmpty() -> contact.firstName + context.config.startNameWithSurname -> contact.surname + else -> contact.firstName + } + + if (name.isEmpty()) { + name = contact.getNameToDisplay() + } + val character = if (name.isNotEmpty()) name.substring(0, 1) else "" FastScrollItemIndicator.Text(character.uppercase(Locale.getDefault()).normalizeString()) } catch (e: Exception) {