diff --git a/app/src/androidTest/java/at/bitfire/davdroid/syncadapter/DavResourceFinderTest.java b/app/src/androidTest/java/at/bitfire/davdroid/syncadapter/DavResourceFinderTest.java index 4abde89c..e6e64dbc 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/syncadapter/DavResourceFinderTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/syncadapter/DavResourceFinderTest.java @@ -44,17 +44,14 @@ public class DavResourceFinderTest extends InstrumentationTestCase { List collections = info.getAddressBooks(); // two address books assertEquals(2, collections.size()); - // first one 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(VCardVersion.V4_0, collection.getVCardVersion()); // second one collection = collections.get(1); assertEquals("https://my.server/absolute:uri/my-address-book/", collection.getURL()); - assertEquals("Absolute URI VCard3 Book", collection.getDescription()); - assertEquals(VCardVersion.V3_0, collection.getVCardVersion()); - + assertEquals("Absolute URI VCard Book", collection.getDescription()); + /*** CalDAV ***/ assertTrue(info.isCalDAV()); collections = info.getCalendars(); diff --git a/app/src/androidTest/java/at/bitfire/davdroid/webdav/WebDavResourceTest.java b/app/src/androidTest/java/at/bitfire/davdroid/webdav/WebDavResourceTest.java index 09e28cb2..b4288ad3 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/webdav/WebDavResourceTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/webdav/WebDavResourceTest.java @@ -105,19 +105,17 @@ public class WebDavResourceTest extends InstrumentationTestCase { assertEquals("useless-member", ab.getName()); 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); - assertEquals(TestConstants.roboHydra.resolve("/dav/addressbooks/test/default-v4.vcf/"), ab.getLocation()); - assertEquals("default-v4.vcf", ab.getName()); + assertEquals(TestConstants.roboHydra.resolve("/dav/addressbooks/test/default.vcf/"), ab.getLocation()); + assertEquals("default.vcf", ab.getName()); 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); assertEquals(new URI("https://my.server/absolute:uri/my-address-book/"), ab.getLocation()); assertEquals("my-address-book", ab.getName()); assertTrue(ab.isAddressBook()); - assertNull(ab.getVCardVersion()); } public void testPropfindCalendars() throws Exception { diff --git a/app/src/androidTest/robohydra/plugins/dav/index.js b/app/src/androidTest/robohydra/plugins/dav/index.js index 476b4e51..b89b0176 100644 --- a/app/src/androidTest/robohydra/plugins/dav/index.js +++ b/app/src/androidTest/robohydra/plugins/dav/index.js @@ -132,7 +132,7 @@ exports.getBodyParts = function(conf) { \ \ \ - /dav/addressbooks/test/default-v4.vcf\ + /dav/addressbooks/test/default.vcf\ \ \ \ @@ -140,10 +140,6 @@ exports.getBodyParts = function(conf) { \ \ Default Address Book\ - \ - \ - \ - \ \ HTTP/1.1 200 OK\ \ @@ -156,7 +152,7 @@ exports.getBodyParts = function(conf) { \ \ \ - Absolute URI VCard3 Book\ + Absolute URI VCard Book\ \ HTTP/1.1 200 OK\ \ diff --git a/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java b/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java index 0801131d..f46a2e48 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java @@ -91,11 +91,6 @@ public class DavResourceFinder implements Closeable { 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); } serverInfo.setAddressBooks(addressBooks); diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java index 013b0cb5..c51abe75 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java @@ -48,6 +48,7 @@ import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -55,6 +56,8 @@ import java.util.Locale; import java.util.Set; import at.bitfire.davdroid.syncadapter.AccountSettings; +import at.bitfire.davdroid.webdav.WebDavResource; +import ezvcard.VCardVersion; import ezvcard.parameter.AddressType; import ezvcard.parameter.EmailType; import ezvcard.parameter.ImppType; @@ -75,9 +78,8 @@ public class LocalAddressBook extends LocalCollection { protected final static String COLUMN_UNKNOWN_PROPERTIES = RawContacts.SYNC3; - final protected AccountSettings accountSettings; - + /* database fields */ @@ -125,9 +127,10 @@ public class LocalAddressBook extends LocalCollection { } @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); } diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java index 3e7feb33..e64ffa39 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java @@ -22,6 +22,7 @@ import android.database.Cursor; import android.database.DatabaseUtils; import android.net.Uri; import android.os.Build; +import android.os.Bundle; import android.os.RemoteException; import android.provider.CalendarContract; import android.provider.CalendarContract.Attendees; @@ -60,12 +61,14 @@ import org.apache.commons.lang3.StringUtils; import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; import at.bitfire.davdroid.DAVUtils; import at.bitfire.davdroid.DateUtils; +import at.bitfire.davdroid.webdav.WebDavResource; import lombok.Cleanup; import lombok.Getter; @@ -193,12 +196,17 @@ public class LocalCalendar extends LocalCollection { } @Override - public void updateMetaData(String displayName, String color) throws LocalStorageException { + public void updateMetaData(WebDavResource resource) throws LocalStorageException { ContentValues values = new ContentValues(); + + final String displayName = resource.getDisplayName(); if (displayName != null) values.put(Calendars.CALENDAR_DISPLAY_NAME, displayName); + + final String color = resource.getColor(); if (color != null) values.put(Calendars.CALENDAR_COLOR, DAVUtils.CalDAVtoARGBColor(color)); + try { if (values.size() > 0) providerClient.update(ContentUris.withAppendedId(calendarsURI(), id), values, null, null); diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java index d5d93670..0583010b 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCollection.java @@ -18,6 +18,7 @@ import android.content.OperationApplicationException; import android.database.Cursor; import android.database.DatabaseUtils; import android.net.Uri; +import android.os.Bundle; import android.os.RemoteException; import android.provider.CalendarContract; import android.util.Log; @@ -25,9 +26,11 @@ import android.util.Log; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import at.bitfire.davdroid.webdav.WebDavResource; import lombok.Cleanup; /** @@ -74,9 +77,6 @@ public abstract class LocalCollection { abstract protected String entryColumnUID(); - /** ID of the collection (for instance, CalendarContract.Calendars._ID) */ - // protected long id; - /** SQL filter expression */ String sqlFilter; @@ -95,8 +95,8 @@ public abstract class LocalCollection { abstract public void setCTag(String cTag) throws LocalStorageException; /** gets the CTag of the collection */ abstract public String getCTag() throws LocalStorageException; - /** update locally stored collection properties */ - abstract public void updateMetaData(String displayName, String color) throws LocalStorageException; + /** update locally stored collection properties (e.g. display name and color) from a WebDavResource */ + abstract public void updateMetaData(WebDavResource resource) throws LocalStorageException; // content provider (= database) querying diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java index f22f7037..6c2250a1 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java @@ -18,6 +18,7 @@ import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; +import android.provider.CalendarContract; import android.util.Log; import net.fortuna.ical4j.model.Date; @@ -35,10 +36,12 @@ import net.fortuna.ical4j.util.TimeZones; import org.apache.commons.lang3.StringUtils; import org.dmfs.provider.tasks.TaskContract; +import java.util.HashMap; import java.util.LinkedList; import at.bitfire.davdroid.DAVUtils; import at.bitfire.davdroid.DateUtils; +import at.bitfire.davdroid.webdav.WebDavResource; import lombok.Cleanup; import lombok.Getter; @@ -132,12 +135,17 @@ public class LocalTaskList extends LocalCollection { } @Override - public void updateMetaData(String displayName, String color) throws LocalStorageException { + public void updateMetaData(WebDavResource resource) throws LocalStorageException { ContentValues values = new ContentValues(); + + final String displayName = resource.getDisplayName(); if (displayName != null) values.put(TaskContract.TaskLists.LIST_NAME, displayName); + + final String color = resource.getColor(); if (color != null) values.put(TaskContract.TaskLists.LIST_COLOR, DAVUtils.CalDAVtoARGBColor(color)); + try { if (values.size() > 0) providerClient.update(ContentUris.withAppendedId(taskListsURI(account), id), values, null, null); diff --git a/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java b/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java index 6ea6b2b9..a0f11e2c 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/ServerInfo.java @@ -59,8 +59,6 @@ public class ServerInfo implements Serializable { description, color; - VCardVersion vCardVersion; - String timezone; @@ -75,7 +73,6 @@ public class ServerInfo implements Serializable { description = src.description; color = src.color; - vCardVersion = src.vCardVersion; timezone = src.timezone; } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/AccountSettings.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/AccountSettings.java index 2daca32d..dd9f70d7 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/AccountSettings.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/AccountSettings.java @@ -76,7 +76,6 @@ public class AccountSettings { for (ServerInfo.ResourceInfo addressBook : serverInfo.getAddressBooks()) if (addressBook.isEnabled()) { bundle.putString(KEY_ADDRESSBOOK_URL, addressBook.getURL()); - bundle.putString(KEY_ADDRESSBOOK_VCARD_VERSION, addressBook.getVCardVersion().getVersion()); break; } return bundle; @@ -146,6 +145,10 @@ public class AccountSettings { version = VCardVersion.valueOfByStr(versionStr); return version; } + + public void setAddressBookVCardVersion(VCardVersion version) { + accountManager.setUserData(account, KEY_ADDRESSBOOK_VCARD_VERSION, version.getVersion()); + } // update from previous account settings diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index 0b49ebcb..24720ef7 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -47,7 +47,7 @@ public class SyncManager { // PHASE 1: fetch collection properties remote.getProperties(); final WebDavResource collectionResource = remote.getCollection(); - local.updateMetaData(collectionResource.getDisplayName(), collectionResource.getColor()); + local.updateMetaData(collectionResource); // PHASE 2: push local changes to server int deletedRemotely = pushDeleted(), diff --git a/app/src/main/java/at/bitfire/davdroid/webdav/HttpPropfind.java b/app/src/main/java/at/bitfire/davdroid/webdav/HttpPropfind.java index 07b1580a..1cb3daea 100644 --- a/app/src/main/java/at/bitfire/davdroid/webdav/HttpPropfind.java +++ b/app/src/main/java/at/bitfire/davdroid/webdav/HttpPropfind.java @@ -58,7 +58,6 @@ public class HttpPropfind extends HttpEntityEnclosingRequestBaseHC4 { propfind.prop.resourcetype = new DavProp.ResourceType(); propfind.prop.currentUserPrivilegeSet = new LinkedList<>(); propfind.prop.addressbookDescription = new DavProp.AddressbookDescription(); - propfind.prop.supportedAddressData = new LinkedList<>(); break; case CALDAV_COLLECTIONS: depth = 1; @@ -75,6 +74,7 @@ public class HttpPropfind extends HttpEntityEnclosingRequestBaseHC4 { propfind.prop.resourcetype = new DavProp.ResourceType(); propfind.prop.displayname = new DavProp.DisplayName(); propfind.prop.calendarColor = new DavProp.CalendarColor(); + propfind.prop.supportedAddressData = new LinkedList<>(); break; case MEMBERS_ETAG: depth = 1;