mirror of https://github.com/etesync/android
* support for phonetic names (closes #19) * update contacts.xml, tested with 4.0 (Samsung), 4.2 (Cyanogen), 4.3 (Cyanogen) (fixes #5, fixes #6, fixes #7) * smarter error handling (1): notify sync manager in case of HTTP auth errors * smarter error handling (2): just ignore the dubious resources instead of notifying Android sync service * refactoring: created DavSyncAdapter and move common code to it * version bump to 0.3.4-alphapull/2/head
parent
c87fb7bedd
commit
5db8bcb9d8
@ -1,54 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ContactsSource xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ContactsAccountType
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<EditSchema>
|
||||
<DataKind
|
||||
kind="name"
|
||||
maxOccurs="1"
|
||||
supportsDisplayName="true"
|
||||
supportsMiddleName="true"
|
||||
supportsFamilyName="true"
|
||||
supportsPhoneticFamilyName="false"
|
||||
supportsPhoneticGivenName="false"
|
||||
supportsPhoneticMiddleName="false"
|
||||
supportsPrefix="true"
|
||||
supportsSuffix="true" />
|
||||
|
||||
<DataKind
|
||||
kind="photo"
|
||||
maxOccurs="1" />
|
||||
|
||||
<DataKind kind="phone">
|
||||
<Type type="fax_home" />
|
||||
<Type type="fax_work" />
|
||||
<Type type="home" />
|
||||
<Type type="mobile" />
|
||||
<Type type="other_fax" />
|
||||
<Type type="pager" />
|
||||
<Type type="work" />
|
||||
<Type type="work_mobile" />
|
||||
<Type type="work_pager" />
|
||||
</DataKind>
|
||||
|
||||
<DataKind kind="email">
|
||||
<Type type="home" />
|
||||
<Type type="work" />
|
||||
<Type type="other" />
|
||||
</DataKind>
|
||||
|
||||
<DataKind
|
||||
kind="nickname"
|
||||
maxOccurs="1" />
|
||||
|
||||
<DataKind kind="website" />
|
||||
<DataKind kind="note" />
|
||||
|
||||
<DataKind
|
||||
dateWithTime="false"
|
||||
kind="event">
|
||||
<Type
|
||||
maxOccurs="1"
|
||||
type="birthday"
|
||||
yearOptional="false" />
|
||||
</DataKind>
|
||||
</EditSchema>
|
||||
</ContactsSource>
|
||||
<DataKind
|
||||
kind="name"
|
||||
maxOccurs="1"
|
||||
supportsDisplayName="true"
|
||||
supportsMiddleName="true"
|
||||
supportsFamilyName="true"
|
||||
supportsPhoneticFamilyName="true"
|
||||
supportsPhoneticGivenName="true"
|
||||
supportsPhoneticMiddleName="true"
|
||||
supportsPrefix="true"
|
||||
supportsSuffix="true" />
|
||||
|
||||
<DataKind
|
||||
kind="photo"
|
||||
maxOccurs="1" />
|
||||
|
||||
<DataKind kind="phone">
|
||||
<Type type="fax_home" />
|
||||
<Type type="fax_work" />
|
||||
<Type type="home" />
|
||||
<Type type="mobile" />
|
||||
<Type type="other_fax" />
|
||||
<Type type="pager" />
|
||||
<Type type="work" />
|
||||
<Type type="work_mobile" />
|
||||
<Type type="work_pager" />
|
||||
</DataKind>
|
||||
|
||||
<DataKind kind="email">
|
||||
<Type type="home" />
|
||||
<Type type="work" />
|
||||
<Type type="other" />
|
||||
</DataKind>
|
||||
|
||||
<DataKind
|
||||
kind="nickname"
|
||||
maxOccurs="1" />
|
||||
|
||||
<DataKind kind="website" />
|
||||
<DataKind
|
||||
kind="note"
|
||||
maxOccurs="1" />
|
||||
|
||||
<DataKind
|
||||
dateWithTime="false"
|
||||
kind="event">
|
||||
<Type
|
||||
maxOccurs="1"
|
||||
type="birthday"
|
||||
yearOptional="false" />
|
||||
</DataKind>
|
||||
</EditSchema>
|
||||
</ContactsAccountType>
|
||||
|
@ -0,0 +1,46 @@
|
||||
package at.bitfire.davdroid.ical4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fortuna.ical4j.model.ValidationException;
|
||||
import net.fortuna.ical4j.vcard.Group;
|
||||
import net.fortuna.ical4j.vcard.Parameter;
|
||||
import net.fortuna.ical4j.vcard.Property;
|
||||
import net.fortuna.ical4j.vcard.PropertyFactory;
|
||||
|
||||
public class PhoneticFirstName extends Property {
|
||||
private static final long serialVersionUID = 8096989375023262021L;
|
||||
|
||||
public static final String PROPERTY_NAME = "PHONETIC-FIRST-NAME";
|
||||
|
||||
protected String phoneticFirstName;
|
||||
|
||||
|
||||
public PhoneticFirstName(String value) {
|
||||
super(PROPERTY_NAME);
|
||||
|
||||
phoneticFirstName = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return phoneticFirstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws ValidationException {
|
||||
}
|
||||
|
||||
public static class Factory implements PropertyFactory<Property> {
|
||||
@Override
|
||||
public PhoneticFirstName createProperty(List<Parameter> params, String value) {
|
||||
return new PhoneticFirstName(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhoneticFirstName createProperty(Group group, List<Parameter> params, String value) {
|
||||
return new PhoneticFirstName(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package at.bitfire.davdroid.ical4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fortuna.ical4j.model.ValidationException;
|
||||
import net.fortuna.ical4j.vcard.Group;
|
||||
import net.fortuna.ical4j.vcard.Parameter;
|
||||
import net.fortuna.ical4j.vcard.Property;
|
||||
import net.fortuna.ical4j.vcard.PropertyFactory;
|
||||
|
||||
public class PhoneticLastName extends Property {
|
||||
private static final long serialVersionUID = 8637699713562385556L;
|
||||
|
||||
public static final String PROPERTY_NAME = "PHONETIC-LAST-NAME";
|
||||
|
||||
protected String phoneticFirstName;
|
||||
|
||||
|
||||
public PhoneticLastName(String value) {
|
||||
super(PROPERTY_NAME);
|
||||
|
||||
phoneticFirstName = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return phoneticFirstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws ValidationException {
|
||||
}
|
||||
|
||||
public static class Factory implements PropertyFactory<Property> {
|
||||
@Override
|
||||
public PhoneticLastName createProperty(List<Parameter> params, String value) {
|
||||
return new PhoneticLastName(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhoneticLastName createProperty(Group group, List<Parameter> params, String value) {
|
||||
return new PhoneticLastName(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package at.bitfire.davdroid.ical4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fortuna.ical4j.model.ValidationException;
|
||||
import net.fortuna.ical4j.vcard.Group;
|
||||
import net.fortuna.ical4j.vcard.Parameter;
|
||||
import net.fortuna.ical4j.vcard.Property;
|
||||
import net.fortuna.ical4j.vcard.PropertyFactory;
|
||||
|
||||
public class PhoneticMiddleName extends Property {
|
||||
private static final long serialVersionUID = 1310410178765057503L;
|
||||
|
||||
public static final String PROPERTY_NAME = "PHONETIC-MIDDLE-NAME";
|
||||
|
||||
protected String phoneticFirstName;
|
||||
|
||||
|
||||
public PhoneticMiddleName(String value) {
|
||||
super(PROPERTY_NAME);
|
||||
|
||||
phoneticFirstName = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return phoneticFirstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws ValidationException {
|
||||
}
|
||||
|
||||
public static class Factory implements PropertyFactory<Property> {
|
||||
@Override
|
||||
public PhoneticMiddleName createProperty(List<Parameter> params, String value) {
|
||||
return new PhoneticMiddleName(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhoneticMiddleName createProperty(Group group, List<Parameter> params, String value) {
|
||||
return new PhoneticMiddleName(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.auth.AuthenticationException;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.AbstractThreadedSyncAdapter;
|
||||
import android.content.ContentProviderClient;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.OperationApplicationException;
|
||||
import android.content.SyncResult;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import at.bitfire.davdroid.resource.IncapableResourceException;
|
||||
import at.bitfire.davdroid.resource.LocalCollection;
|
||||
import at.bitfire.davdroid.resource.RemoteCollection;
|
||||
import at.bitfire.davdroid.webdav.InvalidDavResponseException;
|
||||
|
||||
public abstract class DavSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
private final static String TAG = "davdroid.DavSyncAdapter";
|
||||
|
||||
protected AccountManager accountManager;
|
||||
|
||||
|
||||
public DavSyncAdapter(Context context) {
|
||||
super(context, true);
|
||||
accountManager = AccountManager.get(context);
|
||||
}
|
||||
|
||||
|
||||
protected abstract Map<LocalCollection, RemoteCollection> getSyncPairs(Account account, ContentProviderClient provider);
|
||||
|
||||
|
||||
@Override
|
||||
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
|
||||
Log.i(TAG, "Performing sync for authority " + authority);
|
||||
|
||||
// set class loader for iCal4j ResourceLoader
|
||||
Thread.currentThread().setContextClassLoader(getContext().getClassLoader());
|
||||
|
||||
SyncManager syncManager = new SyncManager(account, accountManager);
|
||||
|
||||
Map<LocalCollection, RemoteCollection> syncCollections = getSyncPairs(account, provider);
|
||||
if (syncCollections == null)
|
||||
Log.i(TAG, "Nothing to synchronize");
|
||||
else
|
||||
try {
|
||||
for (Map.Entry<LocalCollection, RemoteCollection> entry : syncCollections.entrySet())
|
||||
syncManager.synchronize(entry.getKey(), entry.getValue(), extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult);
|
||||
|
||||
} catch (AuthenticationException ex) {
|
||||
syncResult.stats.numAuthExceptions++;
|
||||
Log.e(TAG, "HTTP authorization error", ex);
|
||||
} catch (InvalidDavResponseException ex) {
|
||||
syncResult.stats.numParseExceptions++;
|
||||
Log.e(TAG, "Invalid DAV response", ex);
|
||||
} catch (HttpException ex) {
|
||||
syncResult.stats.numIoExceptions++;
|
||||
Log.e(TAG, "HTTP error", ex);
|
||||
} catch (OperationApplicationException ex) {
|
||||
syncResult.databaseError = true;
|
||||
Log.e(TAG, "Content provider operation error", ex);
|
||||
} catch (RemoteException ex) {
|
||||
syncResult.databaseError = true;
|
||||
Log.e(TAG, "Remote process (content provider?) died", ex);
|
||||
} catch (IOException ex) {
|
||||
syncResult.stats.numIoExceptions++;
|
||||
Log.e(TAG, "I/O error", ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
|
||||
public class InvalidDavResponseException extends HttpException {
|
||||
private static final long serialVersionUID = -2118919144443165706L;
|
||||
|
||||
public InvalidDavResponseException() {
|
||||
super("Invalid DAV response");
|
||||
}
|
||||
}
|
Loading…
Reference in new issue