improve contact sorting at New Conversation, prefer names starting with letters
This commit is contained in:
parent
96e78e3ddc
commit
d98c1abb96
|
@ -163,11 +163,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
contacts_letter_fastscroller.setupWithRecyclerView(contacts_list, { position ->
|
||||
try {
|
||||
val name = contacts[position].name
|
||||
var character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||
if (!character.areLettersOnly()) {
|
||||
character = "#"
|
||||
}
|
||||
|
||||
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()))
|
||||
} catch (e: Exception) {
|
||||
FastScrollItemIndicator.Text("")
|
||||
|
|
|
@ -403,7 +403,7 @@ fun Context.getAvailableContacts(callback: (ArrayList<Contact>) -> Unit) {
|
|||
it.phoneNumber.substring(startIndex)
|
||||
}.toMutableList() as ArrayList<Contact>
|
||||
|
||||
allContacts.sortBy { it.name.normalizeString().toLowerCase(Locale.getDefault()) }
|
||||
allContacts.sort()
|
||||
callback(allContacts)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,24 @@
|
|||
package com.simplemobiletools.smsmessenger.models
|
||||
|
||||
data class Contact(val id: Int, var name: String, var photoUri: String, var phoneNumber: String)
|
||||
import com.simplemobiletools.commons.extensions.normalizeString
|
||||
|
||||
data class Contact(val id: Int, var name: String, var photoUri: String, var phoneNumber: String) : Comparable<Contact> {
|
||||
override fun compareTo(other: Contact): Int {
|
||||
val firstString = name.normalizeString()
|
||||
val secondString = other.name.normalizeString()
|
||||
|
||||
return if (firstString.firstOrNull()?.isLetter() == true && secondString.firstOrNull()?.isLetter() == false) {
|
||||
-1
|
||||
} else if (firstString.firstOrNull()?.isLetter() == false && secondString.firstOrNull()?.isLetter() == true) {
|
||||
1
|
||||
} else {
|
||||
if (firstString.isEmpty() && secondString.isNotEmpty()) {
|
||||
1
|
||||
} else if (firstString.isNotEmpty() && secondString.isEmpty()) {
|
||||
-1
|
||||
} else {
|
||||
firstString.compareTo(secondString, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue