allow renaming local groups
This commit is contained in:
parent
93cf31b2f2
commit
ddfebfdb1f
|
@ -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,14 +35,18 @@ class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val
|
|||
}
|
||||
|
||||
group.title = newTitle
|
||||
Thread {
|
||||
if (group.isPrivateSecretGroup()) {
|
||||
activity.dbHelper.renameGroup(group)
|
||||
activity.groupsDB.insertOrUpdate(group)
|
||||
} else {
|
||||
ContactsHelper(activity).renameGroup(group)
|
||||
}
|
||||
activity.runOnUiThread {
|
||||
callback()
|
||||
dismiss()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String>) {
|
||||
|
@ -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<Contact>, groupId: Long) {
|
||||
contacts.forEach {
|
||||
val currentGroupIds = it.groups.map { it.id } as ArrayList<Long>
|
||||
|
|
Loading…
Reference in New Issue