mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-05-29 18:19:22 +02:00
handle showing and deleting local private groups
This commit is contained in:
parent
b28e85727d
commit
30a7c1770d
@ -13,7 +13,9 @@ import com.simplemobiletools.contacts.R
|
|||||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.dialogs.RenameGroupDialog
|
import com.simplemobiletools.contacts.dialogs.RenameGroupDialog
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
|
import com.simplemobiletools.contacts.extensions.dbHelper
|
||||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||||
|
import com.simplemobiletools.contacts.helpers.FIRST_GROUP_ID
|
||||||
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
|
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
|
||||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||||
import com.simplemobiletools.contacts.models.Group
|
import com.simplemobiletools.contacts.models.Group
|
||||||
@ -97,7 +99,11 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
|
|||||||
selectedPositions.sortedDescending().forEach {
|
selectedPositions.sortedDescending().forEach {
|
||||||
val group = groups[it]
|
val group = groups[it]
|
||||||
groupsToRemove.add(group)
|
groupsToRemove.add(group)
|
||||||
ContactsHelper(activity).deleteGroup(group.id)
|
if (group.id >= FIRST_GROUP_ID) {
|
||||||
|
activity.dbHelper.deleteGroup(group.id)
|
||||||
|
} else {
|
||||||
|
ContactsHelper(activity).deleteGroup(group.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
groups.removeAll(groupsToRemove)
|
groups.removeAll(groupsToRemove)
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ const val CONTACT_ID = "contact_id"
|
|||||||
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
||||||
const val IS_PRIVATE = "is_private"
|
const val IS_PRIVATE = "is_private"
|
||||||
const val GROUP = "group"
|
const val GROUP = "group"
|
||||||
|
const val FIRST_GROUP_ID = 10000
|
||||||
|
|
||||||
const val LOCATION_CONTACTS_TAB = 1
|
const val LOCATION_CONTACTS_TAB = 1
|
||||||
const val LOCATION_FAVORITES_TAB = 2
|
const val LOCATION_FAVORITES_TAB = 2
|
||||||
|
@ -390,6 +390,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
groups.addAll(activity.dbHelper.getGroups())
|
||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import com.google.gson.Gson
|
|||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.extensions.getBlobValue
|
import com.simplemobiletools.commons.extensions.getBlobValue
|
||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
import com.simplemobiletools.commons.extensions.getIntValue
|
||||||
|
import com.simplemobiletools.commons.extensions.getLongValue
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import com.simplemobiletools.contacts.extensions.getByteArray
|
import com.simplemobiletools.contacts.extensions.getByteArray
|
||||||
import com.simplemobiletools.contacts.extensions.getPhotoThumbnailSize
|
import com.simplemobiletools.contacts.extensions.getPhotoThumbnailSize
|
||||||
@ -37,7 +38,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val COL_TITLE = "title"
|
private val COL_TITLE = "title"
|
||||||
|
|
||||||
private val FIRST_CONTACT_ID = 1000000
|
private val FIRST_CONTACT_ID = 1000000
|
||||||
private val FIRST_GROUP_ID = 10000
|
|
||||||
|
|
||||||
private val mDb = writableDatabase
|
private val mDb = writableDatabase
|
||||||
|
|
||||||
@ -162,12 +162,29 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
return mDb.update(GROUPS_TABLE_NAME, contactValues, selection, selectionArgs) == 1
|
return mDb.update(GROUPS_TABLE_NAME, contactValues, selection, selectionArgs) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteGroup(id: Long) = deleteGroups(arrayOf(id.toString()))
|
||||||
|
|
||||||
fun deleteGroups(ids: Array<String>) {
|
fun deleteGroups(ids: Array<String>) {
|
||||||
val args = TextUtils.join(", ", ids)
|
val args = TextUtils.join(", ", ids)
|
||||||
val selection = "$GROUPS_TABLE_NAME.$COL_ID IN ($args)"
|
val selection = "$GROUPS_TABLE_NAME.$COL_ID IN ($args)"
|
||||||
mDb.delete(GROUPS_TABLE_NAME, selection, null)
|
mDb.delete(GROUPS_TABLE_NAME, selection, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getGroups(): ArrayList<Group> {
|
||||||
|
val groups = ArrayList<Group>()
|
||||||
|
val projection = arrayOf(COL_ID, COL_TITLE)
|
||||||
|
val cursor = mDb.query(GROUPS_TABLE_NAME, projection, null, null, null, null, null)
|
||||||
|
cursor.use {
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
val id = cursor.getLongValue(COL_ID)
|
||||||
|
val title = cursor.getStringValue(COL_TITLE)
|
||||||
|
val group = Group(id, title)
|
||||||
|
groups.add(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
|
||||||
private fun fillGroupValues(group: Group): ContentValues {
|
private fun fillGroupValues(group: Group): ContentValues {
|
||||||
return ContentValues().apply {
|
return ContentValues().apply {
|
||||||
put(COL_TITLE, group.title)
|
put(COL_TITLE, group.title)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user