mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
handle local contact Starred toggling
This commit is contained in:
@ -1446,17 +1446,21 @@ class ContactsHelper(val activity: Activity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addFavorites(contacts: ArrayList<Contact>) {
|
fun addFavorites(contacts: ArrayList<Contact>) {
|
||||||
toggleLocalFavorites(contacts, true)
|
Thread {
|
||||||
if (activity.hasContactPermissions()) {
|
toggleLocalFavorites(contacts, true)
|
||||||
toggleFavorites(contacts, true)
|
if (activity.hasContactPermissions()) {
|
||||||
}
|
toggleFavorites(contacts, true)
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeFavorites(contacts: ArrayList<Contact>) {
|
fun removeFavorites(contacts: ArrayList<Contact>) {
|
||||||
toggleLocalFavorites(contacts, false)
|
Thread {
|
||||||
if (activity.hasContactPermissions()) {
|
toggleLocalFavorites(contacts, false)
|
||||||
toggleFavorites(contacts, false)
|
if (activity.hasContactPermissions()) {
|
||||||
}
|
toggleFavorites(contacts, false)
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
|
private fun toggleFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
|
||||||
@ -1481,8 +1485,8 @@ class ContactsHelper(val activity: Activity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleLocalFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
|
private fun toggleLocalFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
|
||||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id.toString() }.toTypedArray()
|
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id }.toTypedArray()
|
||||||
activity.dbHelper.toggleFavorites(localContacts, addToFavorites)
|
LocalContactsHelper(activity).toggleFavorites(localContacts, addToFavorites)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteContact(contact: Contact) {
|
fun deleteContact(contact: Contact) {
|
||||||
|
@ -5,10 +5,7 @@ import android.content.ContentValues
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import android.database.sqlite.SQLiteOpenHelper
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.net.Uri
|
|
||||||
import android.provider.MediaStore
|
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
@ -18,8 +15,6 @@ import com.simplemobiletools.commons.extensions.getLongValue
|
|||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import com.simplemobiletools.contacts.pro.extensions.applyRegexFiltering
|
import com.simplemobiletools.contacts.pro.extensions.applyRegexFiltering
|
||||||
import com.simplemobiletools.contacts.pro.extensions.config
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import com.simplemobiletools.contacts.pro.extensions.getByteArray
|
|
||||||
import com.simplemobiletools.contacts.pro.extensions.getPhotoThumbnailSize
|
|
||||||
import com.simplemobiletools.contacts.pro.models.*
|
import com.simplemobiletools.contacts.pro.models.*
|
||||||
|
|
||||||
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
||||||
@ -98,15 +93,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
mDb.delete(CONTACTS_TABLE_NAME, selection, null)
|
mDb.delete(CONTACTS_TABLE_NAME, selection, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleFavorites(ids: Array<String>, addToFavorites: Boolean) {
|
|
||||||
val contactValues = ContentValues()
|
|
||||||
contactValues.put(COL_STARRED, if (addToFavorites) 1 else 0)
|
|
||||||
|
|
||||||
val args = TextUtils.join(", ", ids)
|
|
||||||
val selection = "$COL_ID IN ($args)"
|
|
||||||
mDb.update(CONTACTS_TABLE_NAME, contactValues, selection, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun insertGroup(group: Group): Group? {
|
fun insertGroup(group: Group): Group? {
|
||||||
val contactValues = fillGroupValues(group)
|
val contactValues = fillGroupValues(group)
|
||||||
val id = mDb.insert(GROUPS_TABLE_NAME, null, contactValues)
|
val id = mDb.insert(GROUPS_TABLE_NAME, null, contactValues)
|
||||||
|
@ -21,6 +21,13 @@ class LocalContactsHelper(val activity: Activity) {
|
|||||||
return activity.contactsDB.insertOrUpdate(localContact) > 0
|
return activity.contactsDB.insertOrUpdate(localContact) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toggleFavorites(ids: Array<Int>, addToFavorites: Boolean) {
|
||||||
|
val isStarred = if (addToFavorites) 1 else 0
|
||||||
|
ids.forEach {
|
||||||
|
activity.contactsDB.updateStarred(isStarred, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getPhotoByteArray(uri: String): ByteArray {
|
private fun getPhotoByteArray(uri: String): ByteArray {
|
||||||
if (uri.isEmpty()) {
|
if (uri.isEmpty()) {
|
||||||
return ByteArray(0)
|
return ByteArray(0)
|
||||||
|
@ -14,6 +14,9 @@ interface ContactsDao {
|
|||||||
@Query("SELECT * FROM contacts WHERE id = :id")
|
@Query("SELECT * FROM contacts WHERE id = :id")
|
||||||
fun getContactWithId(id: Int): LocalContact
|
fun getContactWithId(id: Int): LocalContact
|
||||||
|
|
||||||
|
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
|
||||||
|
fun updateStarred(isStarred: Int, id: Int)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insertOrUpdate(contact: LocalContact): Long
|
fun insertOrUpdate(contact: LocalContact): Long
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user