mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-09 08:08:49 +01:00
handle local contact Starred toggling
This commit is contained in:
parent
e2a5381a74
commit
9634199605
@ -1446,17 +1446,21 @@ class ContactsHelper(val activity: Activity) {
|
||||
}
|
||||
|
||||
fun addFavorites(contacts: ArrayList<Contact>) {
|
||||
toggleLocalFavorites(contacts, true)
|
||||
if (activity.hasContactPermissions()) {
|
||||
toggleFavorites(contacts, true)
|
||||
}
|
||||
Thread {
|
||||
toggleLocalFavorites(contacts, true)
|
||||
if (activity.hasContactPermissions()) {
|
||||
toggleFavorites(contacts, true)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun removeFavorites(contacts: ArrayList<Contact>) {
|
||||
toggleLocalFavorites(contacts, false)
|
||||
if (activity.hasContactPermissions()) {
|
||||
toggleFavorites(contacts, false)
|
||||
}
|
||||
Thread {
|
||||
toggleLocalFavorites(contacts, false)
|
||||
if (activity.hasContactPermissions()) {
|
||||
toggleFavorites(contacts, false)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
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) {
|
||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id.toString() }.toTypedArray()
|
||||
activity.dbHelper.toggleFavorites(localContacts, addToFavorites)
|
||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id }.toTypedArray()
|
||||
LocalContactsHelper(activity).toggleFavorites(localContacts, addToFavorites)
|
||||
}
|
||||
|
||||
fun deleteContact(contact: Contact) {
|
||||
|
@ -5,10 +5,7 @@ import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import android.text.TextUtils
|
||||
import com.google.gson.Gson
|
||||
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.contacts.pro.extensions.applyRegexFiltering
|
||||
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.*
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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? {
|
||||
val contactValues = fillGroupValues(group)
|
||||
val id = mDb.insert(GROUPS_TABLE_NAME, null, contactValues)
|
||||
|
@ -21,6 +21,13 @@ class LocalContactsHelper(val activity: Activity) {
|
||||
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 {
|
||||
if (uri.isEmpty()) {
|
||||
return ByteArray(0)
|
||||
|
@ -14,6 +14,9 @@ interface ContactsDao {
|
||||
@Query("SELECT * FROM contacts WHERE id = :id")
|
||||
fun getContactWithId(id: Int): LocalContact
|
||||
|
||||
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
|
||||
fun updateStarred(isStarred: Int, id: Int)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertOrUpdate(contact: LocalContact): Long
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user