From 23c5ab829789ec08b28a3f1f775899c7b197221a Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 5 Nov 2018 22:49:20 +0100 Subject: [PATCH] add support for updating local contacts --- .../simplemobiletools/contacts/pro/helpers/ContactsHelper.kt | 4 ++-- .../contacts/pro/helpers/LocalContactsHelper.kt | 5 ++--- .../simplemobiletools/contacts/pro/interfaces/ContactsDao.kt | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index 87612c6d..20a9e2a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -902,7 +902,7 @@ class ContactsHelper(val activity: Activity) { fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean { activity.toast(R.string.updating) if (contact.source == SMT_PRIVATE) { - return activity.dbHelper.updateContact(contact) + return LocalContactsHelper(activity).insertOrUpdateContact(contact) } try { @@ -1213,7 +1213,7 @@ class ContactsHelper(val activity: Activity) { fun insertContact(contact: Contact): Boolean { if (contact.source == SMT_PRIVATE) { - return LocalContactsHelper(activity).insertContact(contact) + return LocalContactsHelper(activity).insertOrUpdateContact(contact) } try { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt index 1f05a698..0a158106 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt @@ -16,10 +16,9 @@ class LocalContactsHelper(val activity: Activity) { fun getContactWithId(id: Int) = convertLocalContactToContact(activity.contactsDB.getContactWithId(id)) - fun insertContact(contact: Contact): Boolean { + fun insertOrUpdateContact(contact: Contact): Boolean { val localContact = convertContactToLocalContact(contact) - activity.contactsDB.insertOrUpdate(localContact) - return true + return activity.contactsDB.insertOrUpdate(localContact) > 0 } private fun getPhotoByteArray(uri: String): ByteArray { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt index d8befe8d..2e26861e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt @@ -15,7 +15,7 @@ interface ContactsDao { fun getContactWithId(id: Int): LocalContact @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insertOrUpdate(contact: LocalContact) + fun insertOrUpdate(contact: LocalContact): Long @Query("DELETE FROM contacts WHERE id IN (:ids)") fun deleteContactIds(ids: String)