Skip to content

Commit

Permalink
fix sorting issue FossifyOrg#186
Browse files Browse the repository at this point in the history
  • Loading branch information
Honk2 committed Jan 5, 2025
1 parent f49876e commit 9976cee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,9 +131,23 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
}

private fun setupLetterFastScroller(contacts: ArrayList<Contact>) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,23 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
}

private fun setupLetterFastScroller(contacts: List<Contact>) {
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) {
Expand Down

0 comments on commit 9976cee

Please sign in to comment.