diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt index ea9180fb..835bc5e5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt @@ -4,7 +4,7 @@ import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.contacts.pro.R -import com.simplemobiletools.contacts.pro.extensions.dbHelper +import com.simplemobiletools.contacts.pro.extensions.groupsDB import com.simplemobiletools.contacts.pro.helpers.ContactsHelper import com.simplemobiletools.contacts.pro.models.Group import kotlinx.android.synthetic.main.dialog_rename_group.view.* @@ -35,13 +35,17 @@ class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val } group.title = newTitle - if (group.isPrivateSecretGroup()) { - activity.dbHelper.renameGroup(group) - } else { - ContactsHelper(activity).renameGroup(group) - } - callback() - dismiss() + Thread { + if (group.isPrivateSecretGroup()) { + activity.groupsDB.insertOrUpdate(group) + } else { + ContactsHelper(activity).renameGroup(group) + } + activity.runOnUiThread { + callback() + dismiss() + } + }.start() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/DBHelper.kt index f80d0b79..bfd27e66 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/DBHelper.kt @@ -80,13 +80,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont db.execSQL("REPLACE INTO sqlite_sequence (name, seq) VALUES ('$GROUPS_TABLE_NAME', $FIRST_GROUP_ID)") } - fun renameGroup(group: Group): Boolean { - val contactValues = fillGroupValues(group) - val selection = "$COL_ID = ?" - val selectionArgs = arrayOf(group.id.toString()) - return mDb.update(GROUPS_TABLE_NAME, contactValues, selection, selectionArgs) == 1 - } - fun deleteGroup(id: Long) = deleteGroups(arrayOf(id.toString())) private fun deleteGroups(ids: Array) { @@ -95,12 +88,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont mDb.delete(GROUPS_TABLE_NAME, selection, null) } - private fun fillGroupValues(group: Group): ContentValues { - return ContentValues().apply { - put(COL_TITLE, group.title) - } - } - fun addContactsToGroup(contacts: ArrayList, groupId: Long) { contacts.forEach { val currentGroupIds = it.groups.map { it.id } as ArrayList