mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-09 16:18:55 +01:00
Avoid modifying adapter on a background thread
This commit is contained in:
parent
eec5547558
commit
e69b05c32e
@ -74,30 +74,31 @@ class AutoCompleteTextViewAdapter(
|
||||
override fun getFilter() = object : Filter() {
|
||||
override fun performFiltering(constraint: CharSequence?): FilterResults {
|
||||
val filterResults = FilterResults()
|
||||
if (constraint != null) {
|
||||
resultList.clear()
|
||||
if (autoComplete) {
|
||||
val searchString = constraint.toString().normalizeString()
|
||||
contacts.forEach {
|
||||
if (it.getNameToDisplay().contains(searchString, true)) {
|
||||
resultList.add(it)
|
||||
}
|
||||
if (constraint != null && autoComplete) {
|
||||
val searchString = constraint.toString().normalizeString()
|
||||
val results = mutableListOf<Contact>()
|
||||
contacts.forEach {
|
||||
if (it.getNameToDisplay().contains(searchString, true)) {
|
||||
results.add(it)
|
||||
}
|
||||
|
||||
resultList.sortWith(compareBy<Contact>
|
||||
{ it.name.startsWith(searchString, true) }.thenBy
|
||||
{ it.name.contains(searchString, true) })
|
||||
resultList.reverse()
|
||||
|
||||
filterResults.values = resultList
|
||||
filterResults.count = resultList.size
|
||||
}
|
||||
|
||||
results.sortWith(compareBy<Contact>
|
||||
{ it.name.startsWith(searchString, true) }.thenBy
|
||||
{ it.name.contains(searchString, true) })
|
||||
results.reverse()
|
||||
|
||||
filterResults.values = results
|
||||
filterResults.count = results.size
|
||||
}
|
||||
return filterResults
|
||||
}
|
||||
|
||||
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
|
||||
if ((results?.count ?: -1) > 0) {
|
||||
if (results != null && results.count > 0) {
|
||||
resultList.clear()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
resultList.addAll(results.values as List<Contact>)
|
||||
notifyDataSetChanged()
|
||||
} else {
|
||||
notifyDataSetInvalidated()
|
||||
|
Loading…
x
Reference in New Issue
Block a user