sort contacts directly after fetching, while still on a background thread

This commit is contained in:
tibbi 2018-11-19 22:58:30 +01:00
parent b6ef90272a
commit 5c78872c4e
6 changed files with 5 additions and 25 deletions

View File

@ -86,11 +86,6 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
group_contacts_placeholder_2.beVisibleIf(groupContacts.isEmpty())
group_contacts_placeholder.beVisibleIf(groupContacts.isEmpty())
group_contacts_list.beVisibleIf(groupContacts.isNotEmpty())
Contact.sorting = config.sorting
Contact.startWithSurname = config.startNameWithSurname
groupContacts.sort()
updateContacts(groupContacts)
}
}

View File

@ -58,10 +58,6 @@ class InsertOrEditContactActivity : SimpleActivity() {
}
private fun gotContacts(contacts: ArrayList<Contact>) {
Contact.sorting = config.sorting
Contact.startWithSurname = config.startNameWithSurname
contacts.sort()
ContactsAdapter(this, contacts, null, LOCATION_INSERT_OR_EDIT, null, existing_contact_list, existing_contact_fastscroller) {
Intent(applicationContext, EditContactActivity::class.java).apply {
data = getContactPublicUri(it as Contact)

View File

@ -99,10 +99,6 @@ class SelectContactActivity : SimpleActivity() {
val contactSources = getVisibleContactSources()
contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
Contact.sorting = config.sorting
Contact.startWithSurname = config.startNameWithSurname
contacts.sort()
runOnUiThread {
updatePlaceholderVisibility(contacts)
SelectContactsAdapter(this, contacts, ArrayList(), false, select_contact_list) {

View File

@ -6,12 +6,11 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.SelectContactsAdapter
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
import com.simplemobiletools.contacts.pro.models.Contact
import kotlinx.android.synthetic.main.layout_select_contact.view.*
class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayList<Contact>, val selectContacts: ArrayList<Contact>? = null,
class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayList<Contact>, selectContacts: ArrayList<Contact>? = null,
val callback: (addedContacts: ArrayList<Contact>, removedContacts: ArrayList<Contact>) -> Unit) {
private var view = activity.layoutInflater.inflate(R.layout.layout_select_contact, null)
private var initiallySelectedContacts = ArrayList<Contact>()
@ -27,10 +26,6 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL
initiallySelectedContacts = selectContacts
}
Contact.sorting = activity.config.sorting
Contact.startWithSurname = activity.config.startNameWithSurname
allContacts.sort()
activity.runOnUiThread {
view.apply {
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true, select_contact_list)

View File

@ -108,9 +108,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
config.lastUsedContactSource = grouped?.key ?: ""
}
Contact.sorting = config.sorting
Contact.startWithSurname = config.startNameWithSurname
contacts.sort()
allContacts = contacts
val filtered = when {
@ -253,9 +250,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
it.websites.any { it.contains(text, true) }
} as ArrayList
Contact.sorting = config.sorting
Contact.startWithSurname = config.startNameWithSurname
filtered.sort()
filtered.sortBy { !getProperText(it.getNameToDisplay(), shouldNormalize).startsWith(text, true) }
if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) {

View File

@ -82,6 +82,10 @@ class ContactsHelper(val activity: Activity) {
resultContacts.firstOrNull { it.contactId == key }?.groups = groups.valueAt(i)
}
Contact.sorting = activity.config.sorting
Contact.startWithSurname = activity.config.startNameWithSurname
resultContacts.sort()
activity.runOnUiThread {
callback(resultContacts)
}