mirror of
https://github.com/etesync/android
synced 2024-12-26 08:28:17 +00:00
don't show calendars/address books as syncable in account when no calendars/address books were added; select only events from correct calendar when querying (fixes #37)
This commit is contained in:
parent
b2ab24afd2
commit
68bd43fe6a
@ -4,7 +4,7 @@
|
||||
<Preference android:title="DAVdroid Web site" >
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="http://davdroid.bitfire.at/?pk_campaign=in-app" />
|
||||
android:data="http://davdroid.bitfire.at/?pk_campaign=davdroid-app&pk_kwd=accounts" />
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
@ -60,6 +60,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
||||
protected String entryColumnAccountType() { return RawContacts.ACCOUNT_TYPE; }
|
||||
protected String entryColumnAccountName() { return RawContacts.ACCOUNT_NAME; }
|
||||
|
||||
protected String entryColumnParentID() { return null; /* maybe use RawContacts.DATA_SET some day? */ }
|
||||
protected String entryColumnID() { return RawContacts._ID; }
|
||||
protected String entryColumnRemoteName() { return RawContacts.SOURCE_ID; }
|
||||
protected String entryColumnETag() { return RawContacts.SYNC2; }
|
||||
@ -79,6 +80,11 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
||||
|
||||
/* collection operations */
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCTag() {
|
||||
return accountManager.getUserData(account, Constants.ACCOUNT_KEY_ADDRESSBOOK_CTAG);
|
||||
|
@ -11,6 +11,7 @@ import java.net.URISyntaxException;
|
||||
import java.text.ParseException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.fortuna.ical4j.model.Parameter;
|
||||
import net.fortuna.ical4j.model.ParameterList;
|
||||
@ -25,7 +26,9 @@ import net.fortuna.ical4j.model.property.Organizer;
|
||||
import net.fortuna.ical4j.model.property.RDate;
|
||||
import net.fortuna.ical4j.model.property.RRule;
|
||||
import net.fortuna.ical4j.model.property.Status;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
@ -51,7 +54,7 @@ import at.bitfire.davdroid.syncadapter.ServerInfo;
|
||||
public class LocalCalendar extends LocalCollection<Event> {
|
||||
private static final String TAG = "davdroid.LocalCalendar";
|
||||
|
||||
protected long id;
|
||||
@Getter protected long id;
|
||||
@Getter protected String path, cTag;
|
||||
|
||||
protected static String COLLECTION_COLUMN_CTAG = Calendars.CAL_SYNC1;
|
||||
@ -67,6 +70,7 @@ public class LocalCalendar extends LocalCollection<Event> {
|
||||
protected String entryColumnAccountType() { return Events.ACCOUNT_TYPE; }
|
||||
protected String entryColumnAccountName() { return Events.ACCOUNT_NAME; }
|
||||
|
||||
protected String entryColumnParentID() { return Events.CALENDAR_ID; }
|
||||
protected String entryColumnID() { return Events._ID; }
|
||||
protected String entryColumnRemoteName() { return Events._SYNC_ID; }
|
||||
protected String entryColumnETag() { return Events.SYNC_DATA1; }
|
||||
|
@ -39,6 +39,7 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
abstract protected String entryColumnAccountType();
|
||||
abstract protected String entryColumnAccountName();
|
||||
|
||||
abstract protected String entryColumnParentID();
|
||||
abstract protected String entryColumnID();
|
||||
abstract protected String entryColumnRemoteName();
|
||||
abstract protected String entryColumnETag();
|
||||
@ -57,6 +58,7 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
|
||||
// collection operations
|
||||
|
||||
abstract public long getId();
|
||||
abstract public String getCTag();
|
||||
abstract public void setCTag(String cTag);
|
||||
|
||||
@ -64,9 +66,12 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
// content provider (= database) querying
|
||||
|
||||
public Resource[] findDirty() throws RemoteException {
|
||||
String where = entryColumnDirty() + "=1";
|
||||
if (entryColumnParentID() != null)
|
||||
where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId());
|
||||
Cursor cursor = providerClient.query(entriesURI(),
|
||||
new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() },
|
||||
entryColumnDirty() + "=1", null, null);
|
||||
where, null, null);
|
||||
LinkedList<Resource> dirty = new LinkedList<Resource>();
|
||||
while (cursor.moveToNext())
|
||||
dirty.add(findById(cursor.getLong(0), cursor.getString(1), cursor.getString(2), true));
|
||||
@ -74,9 +79,12 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
}
|
||||
|
||||
public Resource[] findDeleted() throws RemoteException {
|
||||
String where = entryColumnDeleted() + "=1";
|
||||
if (entryColumnParentID() != null)
|
||||
where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId());
|
||||
Cursor cursor = providerClient.query(entriesURI(),
|
||||
new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() },
|
||||
entryColumnDeleted() + "=1", null, null);
|
||||
where, null, null);
|
||||
LinkedList<Resource> deleted = new LinkedList<Resource>();
|
||||
while (cursor.moveToNext())
|
||||
deleted.add(findById(cursor.getLong(0), cursor.getString(1), cursor.getString(2), false));
|
||||
@ -84,9 +92,12 @@ public abstract class LocalCollection<ResourceType extends Resource> {
|
||||
}
|
||||
|
||||
public Resource[] findNew() throws RemoteException {
|
||||
String where = entryColumnDirty() + "=1 AND " + entryColumnRemoteName() + " IS NULL";
|
||||
if (entryColumnParentID() != null)
|
||||
where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId());
|
||||
Cursor cursor = providerClient.query(entriesURI(),
|
||||
new String[] { entryColumnID() },
|
||||
entryColumnDirty() + "=1 AND " + entryColumnRemoteName() + " IS NULL", null, null);
|
||||
where, null, null);
|
||||
LinkedList<Resource> fresh = new LinkedList<Resource>();
|
||||
while (cursor.moveToNext()) {
|
||||
String uid = UUID.randomUUID().toString(),
|
||||
|
@ -141,16 +141,20 @@ public class SelectCollectionsFragment extends ListFragment {
|
||||
|
||||
if (!addressBooks.isEmpty()) {
|
||||
userData.putString(Constants.ACCOUNT_KEY_ADDRESSBOOK_PATH, addressBooks.get(0).getPath());
|
||||
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
|
||||
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
|
||||
}
|
||||
} else
|
||||
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 0);
|
||||
|
||||
if (accountManager.addAccountExplicitly(account, serverInfo.getPassword(), userData)) {
|
||||
// account created, now create calendars
|
||||
if (!calendars.isEmpty()) {
|
||||
for (ServerInfo.ResourceInfo calendar : calendars)
|
||||
LocalCalendar.create(account, getActivity().getContentResolver(), calendar);
|
||||
ContentResolver.setIsSyncable(account, CalendarContract.AUTHORITY, 1);
|
||||
ContentResolver.setSyncAutomatically(account, CalendarContract.AUTHORITY, true);
|
||||
}
|
||||
} else
|
||||
ContentResolver.setIsSyncable(account, CalendarContract.AUTHORITY, 0);
|
||||
|
||||
getActivity().finish();
|
||||
} else
|
||||
|
Loading…
Reference in New Issue
Block a user