allow renaming local groups

This commit is contained in:
tibbi 2018-11-06 20:14:59 +01:00
parent 93cf31b2f2
commit ddfebfdb1f
2 changed files with 12 additions and 21 deletions

View File

@ -4,7 +4,7 @@ import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.contacts.pro.R 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.helpers.ContactsHelper
import com.simplemobiletools.contacts.pro.models.Group import com.simplemobiletools.contacts.pro.models.Group
import kotlinx.android.synthetic.main.dialog_rename_group.view.* 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 group.title = newTitle
if (group.isPrivateSecretGroup()) { Thread {
activity.dbHelper.renameGroup(group) if (group.isPrivateSecretGroup()) {
} else { activity.groupsDB.insertOrUpdate(group)
ContactsHelper(activity).renameGroup(group) } else {
} ContactsHelper(activity).renameGroup(group)
callback() }
dismiss() activity.runOnUiThread {
callback()
dismiss()
}
}.start()
} }
} }
} }

View File

@ -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)") 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())) fun deleteGroup(id: Long) = deleteGroups(arrayOf(id.toString()))
private fun deleteGroups(ids: Array<String>) { private fun deleteGroups(ids: Array<String>) {
@ -95,12 +88,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
mDb.delete(GROUPS_TABLE_NAME, selection, null) 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<Contact>, groupId: Long) { fun addContactsToGroup(contacts: ArrayList<Contact>, groupId: Long) {
contacts.forEach { contacts.forEach {
val currentGroupIds = it.groups.map { it.id } as ArrayList<Long> val currentGroupIds = it.groups.map { it.id } as ArrayList<Long>