Big improvement on contacts list search performances
This commit is contained in:
parent
f815704338
commit
6c223aae31
3 changed files with 19 additions and 12 deletions
|
@ -56,20 +56,25 @@ class ContactsListViewModel : ViewModel() {
|
|||
super.onCleared()
|
||||
}
|
||||
|
||||
fun updateContactsList() {
|
||||
var list = arrayListOf<Contact>()
|
||||
list.addAll(if (sipContactsSelected.value == true) coreContext.contactsManager.sipContacts else coreContext.contactsManager.contacts)
|
||||
private fun getContactsList(): ArrayList<Contact> {
|
||||
return if (sipContactsSelected.value == true) coreContext.contactsManager.sipContacts else coreContext.contactsManager.contacts
|
||||
}
|
||||
|
||||
val filterValue = filter.value.orEmpty().toLowerCase(Locale.getDefault())
|
||||
if (filterValue.isNotEmpty()) {
|
||||
list = list.filter { contact ->
|
||||
contact.fullName?.toLowerCase(Locale.getDefault())?.contains(filterValue) ?: false
|
||||
fun updateContactsList() {
|
||||
val list: ArrayList<Contact>
|
||||
|
||||
val filterValue = filter.value.orEmpty()
|
||||
list = if (filterValue.isNotEmpty()) {
|
||||
getContactsList().filter { contact ->
|
||||
contact.fullName?.contains(filterValue, true) ?: false
|
||||
} as ArrayList<Contact>
|
||||
} else {
|
||||
getContactsList()
|
||||
}
|
||||
|
||||
// Prevent blinking items when list hasn't changed
|
||||
if (list.isEmpty() || list.size != contactsList.value.orEmpty().size) {
|
||||
contactsList.value = list
|
||||
contactsList.postValue(list)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.graphics.Bitmap
|
|||
import android.net.Uri
|
||||
import androidx.core.app.Person
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import java.text.Collator
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.core.Address
|
||||
|
@ -57,6 +56,7 @@ open class Contact : Comparable<Contact> {
|
|||
override fun compareTo(other: Contact): Int {
|
||||
val fn = fullName ?: ""
|
||||
val otherFn = other.fullName ?: ""
|
||||
|
||||
if (fn == otherFn) {
|
||||
if (phoneNumbers.size == other.phoneNumbers.size && phoneNumbers.size > 0) {
|
||||
if (phoneNumbers != other.phoneNumbers) {
|
||||
|
@ -84,9 +84,8 @@ open class Contact : Comparable<Contact> {
|
|||
val otherOrg = other.organization ?: ""
|
||||
return org.compareTo(otherOrg)
|
||||
}
|
||||
val collator = Collator.getInstance()
|
||||
collator.strength = Collator.NO_DECOMPOSITION
|
||||
return collator.compare(fn, otherFn)
|
||||
|
||||
return coreContext.collator.compare(fn, otherFn)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
|
|
@ -41,6 +41,7 @@ import java.math.BigInteger
|
|||
import java.nio.charset.StandardCharsets
|
||||
import java.security.KeyStore
|
||||
import java.security.MessageDigest
|
||||
import java.text.Collator
|
||||
import java.util.*
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
|
@ -84,6 +85,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
|||
"$sdkVersion ($sdkBranch, $sdkBuildType)"
|
||||
}
|
||||
|
||||
val collator = Collator.getInstance()
|
||||
val contactsManager: ContactsManager by lazy {
|
||||
ContactsManager(context)
|
||||
}
|
||||
|
@ -308,6 +310,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
|||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
|
||||
|
||||
EmojiCompat.init(BundledEmojiCompatConfig(context))
|
||||
collator.strength = Collator.NO_DECOMPOSITION
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
|
|
Loading…
Reference in a new issue