From b28e85727d9c6c1e66a3d0b806c5a2b237c97720 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 21 Mar 2018 17:40:51 +0100 Subject: [PATCH] fix local database group inserting --- .../contacts/helpers/ContactsHelper.kt | 2 +- .../com/simplemobiletools/contacts/helpers/DBHelper.kt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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 7bab4b00..ff3ab534 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -395,7 +395,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { fun createNewGroup(title: String, accountName: String, accountType: String): Group? { if (accountType == SMT_PRIVATE) { - return activity.dbHelper.insertGroup(title) + return activity.dbHelper.insertGroup(Group(0, title)) } val operations = ArrayList() 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 af80c3ef..5b9a3c8a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -145,10 +145,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont mDb.update(CONTACTS_TABLE_NAME, contactValues, selection, null) } - fun insertGroup(group: Group): Boolean { + fun insertGroup(group: Group): Group? { val contactValues = fillGroupValues(group) - val id = mDb.insert(GROUPS_TABLE_NAME, null, contactValues).toInt() - return id != -1 + val id = mDb.insert(GROUPS_TABLE_NAME, null, contactValues) + return if (id == -1L) { + null + } else { + Group(id, group.title) + } } fun updateGroup(group: Group): Boolean {