Commit 275335ad authored by Ricki Hirner's avatar Ricki Hirner 🐑

New resource detection

* new resource detection: only CalDAV yet
parent f824386d
......@@ -43,7 +43,7 @@ public class ServerInfo implements Serializable {
@RequiredArgsConstructor(suppressConstructorProperties=true)
@Data
public static class ResourceInfo implements Serializable {
public static class ResourceInfo implements Cloneable, Serializable {
public enum Type {
ADDRESS_BOOK,
CALENDAR
......@@ -64,19 +64,24 @@ public class ServerInfo implements Serializable {
// copy constructor
public ResourceInfo(ResourceInfo src) {
enabled = src.enabled;
type = src.type;
readOnly = src.readOnly;
URL = src.URL;
title = src.title;
description = src.description;
color = src.color;
@Override
public ResourceInfo clone() {
return new ResourceInfo(this);
}
timezone = src.timezone;
}
private ResourceInfo(ResourceInfo src) {
enabled = src.enabled;
type = src.type;
readOnly = src.readOnly;
URL = src.URL;
title = src.title;
description = src.description;
color = src.color;
timezone = src.timezone;
}
// some logic
......
......@@ -9,6 +9,7 @@ package at.bitfire.davdroid.syncadapter;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.ContentProviderClient;
......@@ -77,8 +78,8 @@ public class AccountSettings {
}
// check whether Android version has changed
int lastAndroidVersion = NumberUtils.toInt(accountManager.getUserData(account, KEY_LAST_ANDROID_VERSION));
if (lastAndroidVersion < Build.VERSION.SDK_INT) {
String lastAndroidVersionInt = accountManager.getUserData(account, KEY_LAST_ANDROID_VERSION);
if (lastAndroidVersionInt != null && NumberUtils.toInt(lastAndroidVersionInt) < Build.VERSION.SDK_INT) {
// notify user
showNotification(Constants.NOTIFICATION_ANDROID_VERSION_UPDATED,
context.getString(R.string.settings_android_update_title),
......@@ -89,6 +90,7 @@ public class AccountSettings {
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void showNotification(int id, String title, String message) {
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder n = new Notification.Builder(context);
......
......@@ -23,6 +23,7 @@ import com.squareup.okhttp.ResponseBody;
import org.apache.commons.codec.Charsets;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
......@@ -72,7 +73,10 @@ public class ContactsSyncManager extends SyncManager {
// prepare local address book
localCollection = new LocalAddressBook(account, provider);
collectionURL = HttpUrl.parse(localAddressBook().getURL());
String url = localAddressBook().getURL();
if (url == null)
throw new ContactsStorageException("Couldn't get address book URL");
collectionURL = HttpUrl.parse(url);
davCollection = new DavAddressBook(httpClient, collectionURL);
}
......@@ -101,7 +105,16 @@ public class ContactsSyncManager extends SyncManager {
@Override
protected void listRemote() throws IOException, HttpException, DavException {
// fetch list of remote VCards and build hash table to index file name
davAddressBook().addressbookQuery();
try {
davAddressBook().addressbookQuery();
} catch(HttpException e) {
if (e.status/100 == 4) {
Constants.log.warn("Server error on REPORT addressbook query, falling back to PROPFIND", e);
davAddressBook().propfind(1, GetETag.NAME);
}
}
remoteResources = new HashMap<>(davCollection.members.size());
for (DavResource vCard : davCollection.members) {
String fileName = vCard.fileName();
......
......@@ -202,7 +202,7 @@ abstract public class SyncManager {
Notification notification;
builder .setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getString(R.string.sync_error_title, account.name))
.setContentIntent(PendingIntent.getActivity(context, 0, detailsIntent, PendingIntent.FLAG_UPDATE_CURRENT));
.setContentIntent(PendingIntent.getActivity(context, 0, detailsIntent, PendingIntent.FLAG_CANCEL_CURRENT));
if (Build.VERSION.SDK_INT >= 20)
builder.setLocalOnly(true);
......
......@@ -60,7 +60,7 @@ public class TasksSyncAdapterService extends Service {
throw new CalendarStorageException("Couldn't access OpenTasks provider");
for (LocalTaskList taskList : (LocalTaskList[])LocalTaskList.find(account, provider, LocalTaskList.Factory.INSTANCE, null, null)) {
Constants.log.info("Synchronizing task list #" + taskList.getId() + ", URL: " + taskList.getName());
Constants.log.info("Synchronizing task list #" + taskList.getId() + ", URL: " + taskList.getSyncId());
TasksSyncManager syncManager = new TasksSyncManager(getContext(), account, extras, provider, syncResult, taskList);
syncManager.performSync();
}
......
......@@ -89,7 +89,7 @@ public class TasksSyncManager extends SyncManager {
int color = (pColor != null && pColor.color != null) ? pColor.color : LocalCalendar.defaultColor;
ContentValues values = new ContentValues(2);
Constants.log.info("Setting new calendar name \"" + displayName + "\" and color 0x" + Integer.toHexString(color));
Constants.log.info("Setting new task list name \"" + displayName + "\" and color 0x" + Integer.toHexString(color));
values.put(TaskLists.LIST_NAME, displayName);
values.put(TaskLists.LIST_COLOR, color);
localTaskList().update(values);
......
......@@ -103,16 +103,19 @@ public class AccountDetailsFragment extends Fragment implements TextWatcher {
@Override
public void createLocalCollection(Account account, ServerInfo.ResourceInfo resource) throws ContactsStorageException {
@Cleanup("release") ContentProviderClient provider = getActivity().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
LocalAddressBook addressBook = new LocalAddressBook(account, provider);
// set URL
addressBook.setURL(resource.getURL());
// set Settings
ContentValues settings = new ContentValues(2);
settings.put(ContactsContract.Settings.SHOULD_SYNC, 1);
settings.put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1);
addressBook.updateSettings(settings);
if (provider != null) {
LocalAddressBook addressBook = new LocalAddressBook(account, provider);
// set URL
addressBook.setURL(resource.getURL());
// set Settings
ContentValues settings = new ContentValues(2);
settings.put(ContactsContract.Settings.SHOULD_SYNC, 1);
settings.put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1);
addressBook.updateSettings(settings);
} else
Constants.log.error("Couldn't access Contacts Provider");
}
});
......
......@@ -110,8 +110,8 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
);
try {
DavResourceFinder finder = new DavResourceFinder(context);
finder.findResources(serverInfo);
DavResourceFinder finder = new DavResourceFinder(context, serverInfo);
finder.findResources();
} catch (URISyntaxException e) {
serverInfo.setErrorMessage(getContext().getString(R.string.exception_uri_syntax, e.getMessage()));
} catch (IOException e) {
......
......@@ -165,10 +165,10 @@ public class SelectCollectionsAdapter extends BaseAdapter implements ListAdapter
setContent((CheckedTextView)v, R.drawable.addressbook, (ServerInfo.ResourceInfo)getItem(position));
break;
case TYPE_CALENDARS_ROW:
setContent((CheckedTextView)v, R.drawable.calendar, (ServerInfo.ResourceInfo) getItem(position));
setContent((CheckedTextView)v, R.drawable.calendar, (ServerInfo.ResourceInfo)getItem(position));
break;
case TYPE_TASK_LISTS_ROW:
setContent((CheckedTextView)v, R.drawable.tasks, (ServerInfo.ResourceInfo) getItem(position));
setContent((CheckedTextView)v, R.drawable.tasks, (ServerInfo.ResourceInfo)getItem(position));
}
// disable task list selection if there's no local task provider
......
Subproject commit 429648cfae534dd0476f813c94ab1cae1f140223
Subproject commit b1ca2ff7383381a407baffd05a6b3532e4cd1690
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment