handle local group deleting

This commit is contained in:
tibbi 2018-11-06 20:46:26 +01:00
parent 55ce3efb05
commit 2408cabd81
2 changed files with 12 additions and 17 deletions

View File

@ -13,7 +13,7 @@ import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.dialogs.RenameGroupDialog
import com.simplemobiletools.contacts.pro.extensions.config
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.GROUPS_TAB_MASK
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
@ -92,7 +92,9 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
private fun askConfirmDelete() {
ConfirmationDialog(activity) {
Thread {
deleteGroups()
}.start()
}
}
@ -105,13 +107,14 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
val positions = getSelectedItemPositions()
groupsToRemove.forEach {
if (it.isPrivateSecretGroup()) {
activity.dbHelper.deleteGroup(it.id!!)
activity.groupsDB.deleteGroupId(it.id!!)
} else {
ContactsHelper(activity).deleteGroup(it.id!!)
}
}
groups.removeAll(groupsToRemove)
activity.runOnUiThread {
if (groups.isEmpty()) {
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
finishActMode()
@ -119,6 +122,7 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
removeSelectedItems(positions)
}
}
}
private fun setupView(view: View, group: Group) {
view.apply {

View File

@ -6,7 +6,6 @@ import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.graphics.BitmapFactory
import android.text.TextUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.extensions.getBlobValue
@ -80,14 +79,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 deleteGroup(id: Long) = deleteGroups(arrayOf(id.toString()))
private fun deleteGroups(ids: Array<String>) {
val args = TextUtils.join(", ", ids)
val selection = "$GROUPS_TABLE_NAME.$COL_ID IN ($args)"
mDb.delete(GROUPS_TABLE_NAME, selection, null)
}
fun addContactsToGroup(contacts: ArrayList<Contact>, groupId: Long) {
contacts.forEach {
val currentGroupIds = it.groups.map { it.id } as ArrayList<Long>