1
0
mirror of https://github.com/etesync/android synced 2024-12-26 16:38:34 +00:00

Detect VCard/4 support per sync, too

This commit is contained in:
Ricki Hirner 2015-08-02 16:11:53 +02:00
parent ece6be0f9d
commit 3225a4bbc1
12 changed files with 45 additions and 40 deletions

View File

@ -44,17 +44,14 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
List<ResourceInfo> collections = info.getAddressBooks(); List<ResourceInfo> collections = info.getAddressBooks();
// two address books // two address books
assertEquals(2, collections.size()); assertEquals(2, collections.size());
// first one
ResourceInfo collection = collections.get(0); ResourceInfo collection = collections.get(0);
assertEquals(TestConstants.roboHydra.resolve("/dav/addressbooks/test/default-v4.vcf/").toString(), collection.getURL()); assertEquals(TestConstants.roboHydra.resolve("/dav/addressbooks/test/default.vcf/").toString(), collection.getURL());
assertEquals("Default Address Book", collection.getDescription()); assertEquals("Default Address Book", collection.getDescription());
assertEquals(VCardVersion.V4_0, collection.getVCardVersion());
// second one // second one
collection = collections.get(1); collection = collections.get(1);
assertEquals("https://my.server/absolute:uri/my-address-book/", collection.getURL()); assertEquals("https://my.server/absolute:uri/my-address-book/", collection.getURL());
assertEquals("Absolute URI VCard3 Book", collection.getDescription()); assertEquals("Absolute URI VCard Book", collection.getDescription());
assertEquals(VCardVersion.V3_0, collection.getVCardVersion());
/*** CalDAV ***/ /*** CalDAV ***/
assertTrue(info.isCalDAV()); assertTrue(info.isCalDAV());
collections = info.getCalendars(); collections = info.getCalendars();

View File

@ -105,19 +105,17 @@ public class WebDavResourceTest extends InstrumentationTestCase {
assertEquals("useless-member", ab.getName()); assertEquals("useless-member", ab.getName());
assertFalse(ab.isAddressBook()); assertFalse(ab.isAddressBook());
// the second one is a VCard4-capable address book (referenced by relative URI) // the second one is an address book (referenced by relative URI)
ab = dav.getMembers().get(1); ab = dav.getMembers().get(1);
assertEquals(TestConstants.roboHydra.resolve("/dav/addressbooks/test/default-v4.vcf/"), ab.getLocation()); assertEquals(TestConstants.roboHydra.resolve("/dav/addressbooks/test/default.vcf/"), ab.getLocation());
assertEquals("default-v4.vcf", ab.getName()); assertEquals("default.vcf", ab.getName());
assertTrue(ab.isAddressBook()); assertTrue(ab.isAddressBook());
assertEquals(VCardVersion.V4_0, ab.getVCardVersion());
// the third one is a (non-VCard4-capable) address book (referenced by an absolute URI) // the third one is an address book (referenced by an absolute URI)
ab = dav.getMembers().get(2); ab = dav.getMembers().get(2);
assertEquals(new URI("https://my.server/absolute:uri/my-address-book/"), ab.getLocation()); assertEquals(new URI("https://my.server/absolute:uri/my-address-book/"), ab.getLocation());
assertEquals("my-address-book", ab.getName()); assertEquals("my-address-book", ab.getName());
assertTrue(ab.isAddressBook()); assertTrue(ab.isAddressBook());
assertNull(ab.getVCardVersion());
} }
public void testPropfindCalendars() throws Exception { public void testPropfindCalendars() throws Exception {

View File

@ -132,7 +132,7 @@ exports.getBodyParts = function(conf) {
</propstat>\ </propstat>\
</response>\ </response>\
<response>\ <response>\
<href>/dav/addressbooks/test/default-v4.vcf</href>\ <href>/dav/addressbooks/test/default.vcf</href>\
<propstat>\ <propstat>\
<prop xmlns:CARD="urn:ietf:params:xml:ns:carddav">\ <prop xmlns:CARD="urn:ietf:params:xml:ns:carddav">\
<resourcetype>\ <resourcetype>\
@ -140,10 +140,6 @@ exports.getBodyParts = function(conf) {
<CARD:addressbook/>\ <CARD:addressbook/>\
</resourcetype>\ </resourcetype>\
<CARD:addressbook-description>Default Address Book</CARD:addressbook-description>\ <CARD:addressbook-description>Default Address Book</CARD:addressbook-description>\
<CARD:supported-address-data>\
<CARD:address-data-type content-type="text/vcard" version="3.0" />\
<CARD:address-data-type content-type="text/vcard" version="4.0" />\
</CARD:supported-address-data>\
</prop>\ </prop>\
<status>HTTP/1.1 200 OK</status>\ <status>HTTP/1.1 200 OK</status>\
</propstat>\ </propstat>\
@ -156,7 +152,7 @@ exports.getBodyParts = function(conf) {
<collection/>\ <collection/>\
<CARD:addressbook/>\ <CARD:addressbook/>\
</resourcetype>\ </resourcetype>\
<CARD:addressbook-description>Absolute URI VCard3 Book</CARD:addressbook-description>\ <CARD:addressbook-description>Absolute URI VCard Book</CARD:addressbook-description>\
</prop>\ </prop>\
<status>HTTP/1.1 200 OK</status>\ <status>HTTP/1.1 200 OK</status>\
</propstat>\ </propstat>\

View File

@ -91,11 +91,6 @@ public class DavResourceFinder implements Closeable {
resource.getDescription(), resource.getColor() resource.getDescription(), resource.getColor()
); );
VCardVersion version = resource.getVCardVersion();
if (version == null)
version = VCardVersion.V3_0; // VCard 3.0 MUST be supported
info.setVCardVersion(version);
addressBooks.add(info); addressBooks.add(info);
} }
serverInfo.setAddressBooks(addressBooks); serverInfo.setAddressBooks(addressBooks);

View File

@ -48,6 +48,7 @@ import java.io.InputStream;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -55,6 +56,8 @@ import java.util.Locale;
import java.util.Set; import java.util.Set;
import at.bitfire.davdroid.syncadapter.AccountSettings; import at.bitfire.davdroid.syncadapter.AccountSettings;
import at.bitfire.davdroid.webdav.WebDavResource;
import ezvcard.VCardVersion;
import ezvcard.parameter.AddressType; import ezvcard.parameter.AddressType;
import ezvcard.parameter.EmailType; import ezvcard.parameter.EmailType;
import ezvcard.parameter.ImppType; import ezvcard.parameter.ImppType;
@ -75,9 +78,8 @@ public class LocalAddressBook extends LocalCollection<Contact> {
protected final static String COLUMN_UNKNOWN_PROPERTIES = RawContacts.SYNC3; protected final static String COLUMN_UNKNOWN_PROPERTIES = RawContacts.SYNC3;
final protected AccountSettings accountSettings; final protected AccountSettings accountSettings;
/* database fields */ /* database fields */
@ -125,9 +127,10 @@ public class LocalAddressBook extends LocalCollection<Contact> {
} }
@Override @Override
public void updateMetaData(String displayName, String color) public void updateMetaData(WebDavResource resource)
{ {
// address books don't have a display name or color in Android final VCardVersion vCardVersion = resource.getVCardVersion();
accountSettings.setAddressBookVCardVersion(vCardVersion != null ? vCardVersion : VCardVersion.V3_0);
} }

View File

@ -22,6 +22,7 @@ import android.database.Cursor;
import android.database.DatabaseUtils; import android.database.DatabaseUtils;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.CalendarContract; import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees; import android.provider.CalendarContract.Attendees;
@ -60,12 +61,14 @@ import org.apache.commons.lang3.StringUtils;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import at.bitfire.davdroid.DAVUtils; import at.bitfire.davdroid.DAVUtils;
import at.bitfire.davdroid.DateUtils; import at.bitfire.davdroid.DateUtils;
import at.bitfire.davdroid.webdav.WebDavResource;
import lombok.Cleanup; import lombok.Cleanup;
import lombok.Getter; import lombok.Getter;
@ -193,12 +196,17 @@ public class LocalCalendar extends LocalCollection<Event> {
} }
@Override @Override
public void updateMetaData(String displayName, String color) throws LocalStorageException { public void updateMetaData(WebDavResource resource) throws LocalStorageException {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
final String displayName = resource.getDisplayName();
if (displayName != null) if (displayName != null)
values.put(Calendars.CALENDAR_DISPLAY_NAME, displayName); values.put(Calendars.CALENDAR_DISPLAY_NAME, displayName);
final String color = resource.getColor();
if (color != null) if (color != null)
values.put(Calendars.CALENDAR_COLOR, DAVUtils.CalDAVtoARGBColor(color)); values.put(Calendars.CALENDAR_COLOR, DAVUtils.CalDAVtoARGBColor(color));
try { try {
if (values.size() > 0) if (values.size() > 0)
providerClient.update(ContentUris.withAppendedId(calendarsURI(), id), values, null, null); providerClient.update(ContentUris.withAppendedId(calendarsURI(), id), values, null, null);

View File

@ -18,6 +18,7 @@ import android.content.OperationApplicationException;
import android.database.Cursor; import android.database.Cursor;
import android.database.DatabaseUtils; import android.database.DatabaseUtils;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.CalendarContract; import android.provider.CalendarContract;
import android.util.Log; import android.util.Log;
@ -25,9 +26,11 @@ import android.util.Log;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import at.bitfire.davdroid.webdav.WebDavResource;
import lombok.Cleanup; import lombok.Cleanup;
/** /**
@ -74,9 +77,6 @@ public abstract class LocalCollection<T extends Resource> {
abstract protected String entryColumnUID(); abstract protected String entryColumnUID();
/** ID of the collection (for instance, CalendarContract.Calendars._ID) */
// protected long id;
/** SQL filter expression */ /** SQL filter expression */
String sqlFilter; String sqlFilter;
@ -95,8 +95,8 @@ public abstract class LocalCollection<T extends Resource> {
abstract public void setCTag(String cTag) throws LocalStorageException; abstract public void setCTag(String cTag) throws LocalStorageException;
/** gets the CTag of the collection */ /** gets the CTag of the collection */
abstract public String getCTag() throws LocalStorageException; abstract public String getCTag() throws LocalStorageException;
/** update locally stored collection properties */ /** update locally stored collection properties (e.g. display name and color) from a WebDavResource */
abstract public void updateMetaData(String displayName, String color) throws LocalStorageException; abstract public void updateMetaData(WebDavResource resource) throws LocalStorageException;
// content provider (= database) querying // content provider (= database) querying

View File

@ -18,6 +18,7 @@ import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.CalendarContract;
import android.util.Log; import android.util.Log;
import net.fortuna.ical4j.model.Date; import net.fortuna.ical4j.model.Date;
@ -35,10 +36,12 @@ import net.fortuna.ical4j.util.TimeZones;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dmfs.provider.tasks.TaskContract; import org.dmfs.provider.tasks.TaskContract;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import at.bitfire.davdroid.DAVUtils; import at.bitfire.davdroid.DAVUtils;
import at.bitfire.davdroid.DateUtils; import at.bitfire.davdroid.DateUtils;
import at.bitfire.davdroid.webdav.WebDavResource;
import lombok.Cleanup; import lombok.Cleanup;
import lombok.Getter; import lombok.Getter;
@ -132,12 +135,17 @@ public class LocalTaskList extends LocalCollection<Task> {
} }
@Override @Override
public void updateMetaData(String displayName, String color) throws LocalStorageException { public void updateMetaData(WebDavResource resource) throws LocalStorageException {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
final String displayName = resource.getDisplayName();
if (displayName != null) if (displayName != null)
values.put(TaskContract.TaskLists.LIST_NAME, displayName); values.put(TaskContract.TaskLists.LIST_NAME, displayName);
final String color = resource.getColor();
if (color != null) if (color != null)
values.put(TaskContract.TaskLists.LIST_COLOR, DAVUtils.CalDAVtoARGBColor(color)); values.put(TaskContract.TaskLists.LIST_COLOR, DAVUtils.CalDAVtoARGBColor(color));
try { try {
if (values.size() > 0) if (values.size() > 0)
providerClient.update(ContentUris.withAppendedId(taskListsURI(account), id), values, null, null); providerClient.update(ContentUris.withAppendedId(taskListsURI(account), id), values, null, null);

View File

@ -59,8 +59,6 @@ public class ServerInfo implements Serializable {
description, description,
color; color;
VCardVersion vCardVersion;
String timezone; String timezone;
@ -75,7 +73,6 @@ public class ServerInfo implements Serializable {
description = src.description; description = src.description;
color = src.color; color = src.color;
vCardVersion = src.vCardVersion;
timezone = src.timezone; timezone = src.timezone;
} }

View File

@ -76,7 +76,6 @@ public class AccountSettings {
for (ServerInfo.ResourceInfo addressBook : serverInfo.getAddressBooks()) for (ServerInfo.ResourceInfo addressBook : serverInfo.getAddressBooks())
if (addressBook.isEnabled()) { if (addressBook.isEnabled()) {
bundle.putString(KEY_ADDRESSBOOK_URL, addressBook.getURL()); bundle.putString(KEY_ADDRESSBOOK_URL, addressBook.getURL());
bundle.putString(KEY_ADDRESSBOOK_VCARD_VERSION, addressBook.getVCardVersion().getVersion());
break; break;
} }
return bundle; return bundle;
@ -146,6 +145,10 @@ public class AccountSettings {
version = VCardVersion.valueOfByStr(versionStr); version = VCardVersion.valueOfByStr(versionStr);
return version; return version;
} }
public void setAddressBookVCardVersion(VCardVersion version) {
accountManager.setUserData(account, KEY_ADDRESSBOOK_VCARD_VERSION, version.getVersion());
}
// update from previous account settings // update from previous account settings

View File

@ -47,7 +47,7 @@ public class SyncManager {
// PHASE 1: fetch collection properties // PHASE 1: fetch collection properties
remote.getProperties(); remote.getProperties();
final WebDavResource collectionResource = remote.getCollection(); final WebDavResource collectionResource = remote.getCollection();
local.updateMetaData(collectionResource.getDisplayName(), collectionResource.getColor()); local.updateMetaData(collectionResource);
// PHASE 2: push local changes to server // PHASE 2: push local changes to server
int deletedRemotely = pushDeleted(), int deletedRemotely = pushDeleted(),

View File

@ -58,7 +58,6 @@ public class HttpPropfind extends HttpEntityEnclosingRequestBaseHC4 {
propfind.prop.resourcetype = new DavProp.ResourceType(); propfind.prop.resourcetype = new DavProp.ResourceType();
propfind.prop.currentUserPrivilegeSet = new LinkedList<>(); propfind.prop.currentUserPrivilegeSet = new LinkedList<>();
propfind.prop.addressbookDescription = new DavProp.AddressbookDescription(); propfind.prop.addressbookDescription = new DavProp.AddressbookDescription();
propfind.prop.supportedAddressData = new LinkedList<>();
break; break;
case CALDAV_COLLECTIONS: case CALDAV_COLLECTIONS:
depth = 1; depth = 1;
@ -75,6 +74,7 @@ public class HttpPropfind extends HttpEntityEnclosingRequestBaseHC4 {
propfind.prop.resourcetype = new DavProp.ResourceType(); propfind.prop.resourcetype = new DavProp.ResourceType();
propfind.prop.displayname = new DavProp.DisplayName(); propfind.prop.displayname = new DavProp.DisplayName();
propfind.prop.calendarColor = new DavProp.CalendarColor(); propfind.prop.calendarColor = new DavProp.CalendarColor();
propfind.prop.supportedAddressData = new LinkedList<>();
break; break;
case MEMBERS_ETAG: case MEMBERS_ETAG:
depth = 1; depth = 1;