add support for updating local contacts

This commit is contained in:
tibbi 2018-11-05 22:49:20 +01:00
parent 79e46c43d5
commit 23c5ab8297
3 changed files with 5 additions and 6 deletions

View File

@ -902,7 +902,7 @@ class ContactsHelper(val activity: Activity) {
fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean { fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean {
activity.toast(R.string.updating) activity.toast(R.string.updating)
if (contact.source == SMT_PRIVATE) { if (contact.source == SMT_PRIVATE) {
return activity.dbHelper.updateContact(contact) return LocalContactsHelper(activity).insertOrUpdateContact(contact)
} }
try { try {
@ -1213,7 +1213,7 @@ class ContactsHelper(val activity: Activity) {
fun insertContact(contact: Contact): Boolean { fun insertContact(contact: Contact): Boolean {
if (contact.source == SMT_PRIVATE) { if (contact.source == SMT_PRIVATE) {
return LocalContactsHelper(activity).insertContact(contact) return LocalContactsHelper(activity).insertOrUpdateContact(contact)
} }
try { try {

View File

@ -16,10 +16,9 @@ class LocalContactsHelper(val activity: Activity) {
fun getContactWithId(id: Int) = convertLocalContactToContact(activity.contactsDB.getContactWithId(id)) fun getContactWithId(id: Int) = convertLocalContactToContact(activity.contactsDB.getContactWithId(id))
fun insertContact(contact: Contact): Boolean { fun insertOrUpdateContact(contact: Contact): Boolean {
val localContact = convertContactToLocalContact(contact) val localContact = convertContactToLocalContact(contact)
activity.contactsDB.insertOrUpdate(localContact) return activity.contactsDB.insertOrUpdate(localContact) > 0
return true
} }
private fun getPhotoByteArray(uri: String): ByteArray { private fun getPhotoByteArray(uri: String): ByteArray {

View File

@ -15,7 +15,7 @@ interface ContactsDao {
fun getContactWithId(id: Int): LocalContact fun getContactWithId(id: Int): LocalContact
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(contact: LocalContact) fun insertOrUpdate(contact: LocalContact): Long
@Query("DELETE FROM contacts WHERE id IN (:ids)") @Query("DELETE FROM contacts WHERE id IN (:ids)")
fun deleteContactIds(ids: String) fun deleteContactIds(ids: String)