mirror of
https://github.com/etesync/android
synced 2025-01-23 06:01:01 +00:00
Local event/contact: Add a way to add/update as dirty
This commit is contained in:
parent
d98d58360e
commit
231684e0d4
@ -20,6 +20,9 @@ import android.provider.ContactsContract.RawContacts.Data;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import com.etesync.syncadapter.model.UnknownProperties;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@ -27,8 +30,6 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import com.etesync.syncadapter.model.UnknownProperties;
|
||||
import at.bitfire.vcard4android.AndroidAddressBook;
|
||||
import at.bitfire.vcard4android.AndroidContact;
|
||||
import at.bitfire.vcard4android.AndroidContactFactory;
|
||||
@ -44,6 +45,8 @@ import static at.bitfire.vcard4android.GroupMethod.GROUP_VCARDS;
|
||||
public class LocalContact extends AndroidContact implements LocalResource {
|
||||
public static final String COLUMN_HASHCODE = ContactsContract.RawContacts.SYNC3;
|
||||
|
||||
private boolean saveAsDirty = false; // When true, the resource will be saved as dirty
|
||||
|
||||
protected final Set<Long>
|
||||
cachedGroupMemberships = new HashSet<>(),
|
||||
groupMemberships = new HashSet<>();
|
||||
@ -166,24 +169,40 @@ public class LocalContact extends AndroidContact implements LocalResource {
|
||||
public int update(Contact contact) throws ContactsStorageException {
|
||||
int result = super.update(contact);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
if (!saveAsDirty && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N))
|
||||
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||
updateHashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int updateAsDirty(Contact contact) throws ContactsStorageException {
|
||||
saveAsDirty = true;
|
||||
return this.update(contact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri create() throws ContactsStorageException {
|
||||
Uri uri = super.create();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
if (!saveAsDirty && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N))
|
||||
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||
updateHashCode();
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
public Uri createAsDirty() throws ContactsStorageException {
|
||||
saveAsDirty = true;
|
||||
return this.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildContact(ContentProviderOperation.Builder builder, boolean update) {
|
||||
super.buildContact(builder, update);
|
||||
builder.withValue(ContactsContract.RawContacts.DIRTY, saveAsDirty ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code from the contact's data (VCard) and group memberships.
|
||||
* @return hash code of contact data (including group memberships)
|
||||
|
@ -11,6 +11,7 @@ package com.etesync.syncadapter.resource;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentValues;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.CalendarContract;
|
||||
@ -18,11 +19,12 @@ import android.provider.CalendarContract.Events;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import at.bitfire.ical4android.AndroidCalendar;
|
||||
import at.bitfire.ical4android.AndroidEvent;
|
||||
import at.bitfire.ical4android.AndroidEventFactory;
|
||||
@ -38,6 +40,8 @@ public class LocalEvent extends AndroidEvent implements LocalResource {
|
||||
COLUMN_UID = Build.VERSION.SDK_INT >= 17 ? Events.UID_2445 : Events.SYNC_DATA2,
|
||||
COLUMN_SEQUENCE = CalendarContract.Events.SYNC_DATA3;
|
||||
|
||||
private boolean saveAsDirty = false; // When true, the resource will be saved as dirty
|
||||
|
||||
@Getter
|
||||
protected String fileName;
|
||||
@Getter
|
||||
@ -108,7 +112,7 @@ public class LocalEvent extends AndroidEvent implements LocalResource {
|
||||
|
||||
builder.withValue(COLUMN_UID, event.uid)
|
||||
.withValue(COLUMN_SEQUENCE, eventToBuild.sequence)
|
||||
.withValue(CalendarContract.Events.DIRTY, 0)
|
||||
.withValue(CalendarContract.Events.DIRTY, saveAsDirty ? 1 : 0)
|
||||
.withValue(CalendarContract.Events.DELETED, 0);
|
||||
|
||||
if (buildException)
|
||||
@ -118,6 +122,15 @@ public class LocalEvent extends AndroidEvent implements LocalResource {
|
||||
.withValue(COLUMN_ETAG, eTag);
|
||||
}
|
||||
|
||||
public Uri addAsDirty() throws CalendarStorageException {
|
||||
saveAsDirty = true;
|
||||
return this.add();
|
||||
}
|
||||
|
||||
public Uri updateAsDirty(Event event) throws CalendarStorageException {
|
||||
saveAsDirty = true;
|
||||
return this.update(event);
|
||||
}
|
||||
|
||||
/* custom queries */
|
||||
|
||||
@ -155,7 +168,6 @@ public class LocalEvent extends AndroidEvent implements LocalResource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Factory implements AndroidEventFactory {
|
||||
static final Factory INSTANCE = new Factory();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user