From dc43fb93f89c677b1f3f86cb73678443ef3bbedf Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 11 Feb 2018 20:50:08 +0100 Subject: [PATCH] add handling for updating local private contacts --- .../simplemobiletools/contacts/helpers/ContactsHelper.kt | 4 +++- .../com/simplemobiletools/contacts/helpers/DBHelper.kt | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index c245632a..d533380f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -328,7 +328,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) { } fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean { - return try { + return if (contact.source == SMT_PRIVATE) { + activity.dbHelper.update(contact) + } else try { activity.toast(R.string.updating) val operations = ArrayList() ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).apply { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 8efa77ed..9343a4e0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -61,6 +61,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return id != -1 } + fun update(contact: Contact): Boolean { + val contactValues = fillContactValues(contact) + val selection = "$COL_ID = ?" + val selectionArgs = arrayOf(contact.id.toString()) + return mDb.update(CONTACTS_TABLE_NAME, contactValues, selection, selectionArgs) == 1 + } + private fun fillContactValues(contact: Contact): ContentValues { return ContentValues().apply { put(COL_FIRST_NAME, contact.firstName)