1
0
mirror of https://github.com/etesync/android synced 2025-01-11 08:10:58 +00:00

Use last path segment as collection display name if there's no DAV:displayName

* use last path segment as collection display name if there's no DAV:displayName
* add Contacts Provider Settings again to show contacts without groups in all clients (bluetooth cars etc.)
This commit is contained in:
Ricki Hirner 2016-03-31 00:52:10 +02:00
parent a283cbbae5
commit 2280f899ee
5 changed files with 43 additions and 6 deletions

View File

@ -17,8 +17,8 @@ android {
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 22 targetSdkVersion 22
versionCode 92 versionCode 93
versionName "1.0.2" versionName "1.0.3"
buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"
} }

View File

@ -8,9 +8,20 @@
package at.bitfire.davdroid; package at.bitfire.davdroid;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import org.w3c.dom.Text;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import ezvcard.util.StringUtils;
import okhttp3.HttpUrl;
public class DavUtils { public class DavUtils {
public static String ARGBtoCalDAVColor(int colorWithAlpha) { public static String ARGBtoCalDAVColor(int colorWithAlpha) {
@ -19,4 +30,16 @@ public class DavUtils {
return String.format("#%06X%02X", color, alpha); return String.format("#%06X%02X", color, alpha);
} }
public static String lastSegmentOfUrl(@NonNull String url) {
// the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy
List<String> segments = new LinkedList<>(HttpUrl.parse(url).pathSegments());
Collections.reverse(segments);
for (String segment : segments)
if (!TextUtils.isEmpty(segment))
return segment;
return "/";
}
} }

View File

@ -35,6 +35,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import at.bitfire.davdroid.App; import at.bitfire.davdroid.App;
import at.bitfire.davdroid.DavUtils;
import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.CollectionInfo;
import at.bitfire.ical4android.AndroidCalendar; import at.bitfire.ical4android.AndroidCalendar;
import at.bitfire.ical4android.AndroidCalendarFactory; import at.bitfire.ical4android.AndroidCalendarFactory;
@ -43,6 +44,7 @@ import at.bitfire.ical4android.CalendarStorageException;
import at.bitfire.ical4android.DateUtils; import at.bitfire.ical4android.DateUtils;
import at.bitfire.vcard4android.ContactsStorageException; import at.bitfire.vcard4android.ContactsStorageException;
import lombok.Cleanup; import lombok.Cleanup;
import okhttp3.HttpUrl;
public class LocalCalendar extends AndroidCalendar implements LocalCollection { public class LocalCalendar extends AndroidCalendar implements LocalCollection {
@ -89,7 +91,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
private static ContentValues valuesFromCollectionInfo(CollectionInfo info) { private static ContentValues valuesFromCollectionInfo(CollectionInfo info) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Calendars.NAME, info.url); values.put(Calendars.NAME, info.url);
values.put(Calendars.CALENDAR_DISPLAY_NAME, info.displayName); values.put(Calendars.CALENDAR_DISPLAY_NAME, !TextUtils.isEmpty(info.displayName) ? info.displayName : DavUtils.lastSegmentOfUrl(info.url));
values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor); values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor);
if (info.readOnly) if (info.readOnly)

View File

@ -15,18 +15,21 @@ import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils;
import org.dmfs.provider.tasks.TaskContract.TaskLists; import org.dmfs.provider.tasks.TaskContract.TaskLists;
import org.dmfs.provider.tasks.TaskContract.Tasks; import org.dmfs.provider.tasks.TaskContract.Tasks;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import at.bitfire.davdroid.DavUtils;
import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.CollectionInfo;
import at.bitfire.ical4android.AndroidTaskList; import at.bitfire.ical4android.AndroidTaskList;
import at.bitfire.ical4android.AndroidTaskListFactory; import at.bitfire.ical4android.AndroidTaskListFactory;
import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.CalendarStorageException;
import at.bitfire.ical4android.TaskProvider; import at.bitfire.ical4android.TaskProvider;
import lombok.Cleanup; import lombok.Cleanup;
import okhttp3.HttpUrl;
public class LocalTaskList extends AndroidTaskList implements LocalCollection { public class LocalTaskList extends AndroidTaskList implements LocalCollection {
@ -67,7 +70,7 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
private static ContentValues valuesFromCollectionInfo(CollectionInfo info) { private static ContentValues valuesFromCollectionInfo(CollectionInfo info) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(TaskLists._SYNC_ID, info.url); values.put(TaskLists._SYNC_ID, info.url);
values.put(TaskLists.LIST_NAME, info.displayName); values.put(TaskLists.LIST_NAME, !TextUtils.isEmpty(info.displayName) ? info.displayName : DavUtils.lastSegmentOfUrl(info.url));
values.put(TaskLists.LIST_COLOR, info.color != null ? info.color : defaultColor); values.put(TaskLists.LIST_COLOR, info.color != null ? info.color : defaultColor);
values.put(TaskLists.SYNC_ENABLED, 1); values.put(TaskLists.SYNC_ENABLED, 1);
values.put(TaskLists.VISIBLE, 1); values.put(TaskLists.VISIBLE, 1);

View File

@ -10,9 +10,11 @@ package at.bitfire.davdroid.syncadapter;
import android.accounts.Account; import android.accounts.Account;
import android.content.ContentProviderClient; import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.SyncResult; import android.content.SyncResult;
import android.os.Bundle; import android.os.Bundle;
import android.provider.ContactsContract;
import org.apache.commons.codec.Charsets; import org.apache.commons.codec.Charsets;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -85,14 +87,21 @@ public class ContactsSyncManager extends SyncManager {
protected void prepare() throws ContactsStorageException { protected void prepare() throws ContactsStorageException {
// prepare local address book // prepare local address book
localCollection = new LocalAddressBook(account, provider); localCollection = new LocalAddressBook(account, provider);
LocalAddressBook localAddressBook = localAddressBook();
String url = remote.url; String url = remote.url;
String lastUrl = localAddressBook().getURL(); String lastUrl = localAddressBook.getURL();
if (!url.equals(lastUrl)) { if (!url.equals(lastUrl)) {
App.log.info("Selected address book has changed from " + lastUrl + " to " + url + ", deleting all local contacts"); App.log.info("Selected address book has changed from " + lastUrl + " to " + url + ", deleting all local contacts");
((LocalAddressBook)localCollection).deleteAll(); localAddressBook.deleteAll();
} }
// set up Contacts Provider Settings
ContentValues settings = new ContentValues(2);
settings.put(ContactsContract.Settings.SHOULD_SYNC, 1);
settings.put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1);
localAddressBook.updateSettings(settings);
collectionURL = HttpUrl.parse(url); collectionURL = HttpUrl.parse(url);
davCollection = new DavAddressBook(httpClient, collectionURL); davCollection = new DavAddressBook(httpClient, collectionURL);