mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-09 08:08:49 +01:00
improving the performance at fetching local contacts
This commit is contained in:
parent
a1ab751882
commit
27592706ce
@ -16,9 +16,16 @@ import com.simplemobiletools.contacts.pro.models.LocalContact
|
|||||||
import com.simplemobiletools.contacts.pro.models.Organization
|
import com.simplemobiletools.contacts.pro.models.Organization
|
||||||
|
|
||||||
class LocalContactsHelper(val context: Context) {
|
class LocalContactsHelper(val context: Context) {
|
||||||
fun getAllContacts() = context.contactsDB.getContacts().map { convertLocalContactToContact(it) }.toMutableList() as ArrayList<Contact>
|
fun getAllContacts(): ArrayList<Contact> {
|
||||||
|
val contacts = context.contactsDB.getContacts()
|
||||||
|
val storedGroups = ContactsHelper(context).getStoredGroupsSync()
|
||||||
|
return contacts.map { convertLocalContactToContact(it, storedGroups) }.toMutableList() as ArrayList<Contact>
|
||||||
|
}
|
||||||
|
|
||||||
fun getContactWithId(id: Int) = convertLocalContactToContact(context.contactsDB.getContactWithId(id))
|
fun getContactWithId(id: Int): Contact? {
|
||||||
|
val storedGroups = ContactsHelper(context).getStoredGroupsSync()
|
||||||
|
return convertLocalContactToContact(context.contactsDB.getContactWithId(id), storedGroups)
|
||||||
|
}
|
||||||
|
|
||||||
fun insertOrUpdateContact(contact: Contact): Boolean {
|
fun insertOrUpdateContact(contact: Contact): Boolean {
|
||||||
val localContact = convertContactToLocalContact(contact)
|
val localContact = convertContactToLocalContact(contact)
|
||||||
@ -74,7 +81,7 @@ class LocalContactsHelper(val context: Context) {
|
|||||||
return scaledSizePhotoData
|
return scaledSizePhotoData
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertLocalContactToContact(localContact: LocalContact?): Contact? {
|
private fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
||||||
if (localContact == null) {
|
if (localContact == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -89,8 +96,6 @@ class LocalContactsHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val storedGroups = ContactsHelper(context).getStoredGroupsSync()
|
|
||||||
|
|
||||||
return context.getEmptyContact().apply {
|
return context.getEmptyContact().apply {
|
||||||
id = localContact.id!!
|
id = localContact.id!!
|
||||||
prefix = localContact.prefix
|
prefix = localContact.prefix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user