Commit 127e3273 authored by Ricki Hirner's avatar Ricki Hirner 🐑

Improve DavResourceFinder

* check whether user-given URL actually provides CalDAV/CardDAV before trusting the current-user-principal
  as there may be different principals for CalDAV and CardDAV (if both services are completely separated)
parent 557e69f1
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.resource;
public class InvalidResourceException extends Exception {
private static final long serialVersionUID = 1593585432655578220L;
public InvalidResourceException(String message) {
super(message);
}
public InvalidResourceException(Throwable throwable) {
super(throwable);
}
}
......@@ -73,7 +73,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
throw new CalendarStorageException("Couldn't acquire ContentProviderClient for " + CalendarContract.AUTHORITY);
ContentValues values = new ContentValues();
values.put(Calendars.NAME, info.getURL());
values.put(Calendars.NAME, info.getUrl());
values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor);
......
......@@ -58,7 +58,7 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
throw new CalendarStorageException("Couldn't access OpenTasks provider");
ContentValues values = new ContentValues();
values.put(TaskLists._SYNC_ID, info.getURL());
values.put(TaskLists._SYNC_ID, info.getUrl());
values.put(TaskLists.LIST_NAME, info.getTitle());
values.put(TaskLists.LIST_COLOR, info.color != null ? info.color : defaultColor);
values.put(TaskLists.OWNER, account.name);
......
......@@ -10,11 +10,11 @@ package at.bitfire.davdroid.resource;
import com.squareup.okhttp.HttpUrl;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import at.bitfire.dav4android.UrlUtils;
import lombok.Data;
import lombok.RequiredArgsConstructor;
......@@ -27,10 +27,10 @@ public class ServerInfo implements Serializable {
private String errorMessage;
private List<ResourceInfo>
addressBooks = new LinkedList<>(),
calendars = new LinkedList<>(),
taskLists = new LinkedList<>();
private ResourceInfo
addressBooks[] = new ResourceInfo[0],
calendars[] = new ResourceInfo[0],
taskLists[] = new ResourceInfo[0];
public boolean hasEnabledCalendars() {
......@@ -43,8 +43,9 @@ public class ServerInfo implements Serializable {
@RequiredArgsConstructor(suppressConstructorProperties=true)
@Data
public static class ResourceInfo implements Cloneable, Serializable {
public enum Type {
public static class ResourceInfo implements Serializable {
public enum Type {
ADDRESS_BOOK,
CALENDAR
}
......@@ -54,7 +55,7 @@ public class ServerInfo implements Serializable {
final Type type;
final boolean readOnly;
final String URL, // absolute URL of resource
final String url, // absolute URL of resource
title,
description;
final Integer color;
......@@ -75,7 +76,7 @@ public class ServerInfo implements Serializable {
type = src.type;
readOnly = src.readOnly;
URL = src.URL;
url = src.url;
title = src.title;
description = src.description;
color = src.color;
......@@ -83,14 +84,5 @@ public class ServerInfo implements Serializable {
timezone = src.timezone;
}
// some logic
public String getTitle() {
if (title == null) {
HttpUrl url = HttpUrl.parse(URL);
return url != null ? url.toString() : "–";
} else
return title;
}
}
}
......@@ -29,7 +29,6 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;
import java.util.List;
import at.bitfire.davdroid.Constants;
......@@ -107,7 +106,7 @@ public class AccountDetailsFragment extends Fragment implements TextWatcher {
LocalAddressBook addressBook = new LocalAddressBook(account, provider);
// set URL
addressBook.setURL(resource.getURL());
addressBook.setURL(resource.getUrl());
// set Settings
ContentValues settings = new ContentValues(2);
......@@ -150,7 +149,7 @@ public class AccountDetailsFragment extends Fragment implements TextWatcher {
void createLocalCollection(Account account, ServerInfo.ResourceInfo resource) throws ContactsStorageException;
}
protected void addSync(Account account, String authority, List<ServerInfo.ResourceInfo> resourceList, AddSyncCallback callback) {
protected void addSync(Account account, String authority, ServerInfo.ResourceInfo[] resourceList, AddSyncCallback callback) {
boolean sync = false;
for (ServerInfo.ResourceInfo resource : resourceList)
if (resource.isEnabled()) {
......
......@@ -70,7 +70,7 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
((AddAccountActivity)getActivity()).serverInfo = serverInfo;
Fragment nextFragment;
if (!serverInfo.getTaskLists().isEmpty() && !LocalTaskList.tasksProviderAvailable(getActivity().getContentResolver()))
if (serverInfo.getTaskLists().length > 0 && !LocalTaskList.tasksProviderAvailable(getActivity().getContentResolver()))
nextFragment = new InstallAppsFragment();
else
nextFragment = new SelectCollectionsFragment();
......
......@@ -56,11 +56,11 @@ public class SelectCollectionsAdapter extends BaseAdapter implements ListAdapter
this.context = context;
this.serverInfo = serverInfo;
nAddressBooks = serverInfo.getAddressBooks().size();
nAddressBooks = serverInfo.getAddressBooks().length;
nAddressBookHeadings = nAddressBooks == 0 ? 0 : 1;
nCalendars = serverInfo.getCalendars().size();
nCalendars = serverInfo.getCalendars().length;
nCalendarHeadings = nCalendars == 0 ? 0 : 1;
nTaskLists = serverInfo.getTaskLists().size();
nTaskLists = serverInfo.getTaskLists().length;
nTaskListHeadings = nTaskLists == 0 ? 0 : 1;
}
......@@ -76,15 +76,15 @@ public class SelectCollectionsAdapter extends BaseAdapter implements ListAdapter
public Object getItem(int position) {
if (position >= nAddressBookHeadings &&
position < (nAddressBookHeadings + nAddressBooks))
return serverInfo.getAddressBooks().get(position - nAddressBookHeadings);
return serverInfo.getAddressBooks()[position - nAddressBookHeadings];
else if (position >= (nAddressBookHeadings + nAddressBooks + nCalendarHeadings) &&
(position < (nAddressBookHeadings + nAddressBooks + nCalendarHeadings + nCalendars)))
return serverInfo.getCalendars().get(position - (nAddressBookHeadings + nAddressBooks + nCalendarHeadings));
return serverInfo.getCalendars()[position - (nAddressBookHeadings + nAddressBooks + nCalendarHeadings)];
else if (position >= (nAddressBookHeadings + nAddressBooks + nCalendarHeadings + nCalendars + nTaskListHeadings) &&
(position < (nAddressBookHeadings + nAddressBooks + nCalendarHeadings + nCalendars + nTaskListHeadings + nTaskLists)))
return serverInfo.getTaskLists().get(position - (nAddressBookHeadings + nAddressBooks + nCalendarHeadings + nCalendars + nTaskListHeadings));
return serverInfo.getTaskLists()[position - (nAddressBookHeadings + nAddressBooks + nCalendarHeadings + nCalendars + nTaskListHeadings)];
return null;
}
......@@ -198,7 +198,7 @@ public class SelectCollectionsAdapter extends BaseAdapter implements ListAdapter
String description = info.getDescription();
if (description == null)
description = info.getURL();
description = info.getUrl();
// FIXME escape HTML
view.setText(Html.fromHtml(title + "<br/>" + description));
......
Subproject commit a22eb4eb193c8f22180369791df3671e1cab6f1c
Subproject commit e7218aeb8ad8a96620208140bc7b86f63bf05fad
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