mirror of
https://github.com/etesync/android
synced 2024-11-13 19:29:01 +00:00
add contacts.xml and birthday (couldn't test it)
This commit is contained in:
parent
b9a13bf7de
commit
6ee010905e
@ -1,3 +1,54 @@
|
||||
<ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<EditSchema/>
|
||||
</ContactsAccountType>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ContactsSource 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>
|
||||
|
@ -20,5 +20,5 @@ public class Constants {
|
||||
ACCOUNT_KEY_ADDRESSBOOK_PATH = "addressbook_path",
|
||||
ACCOUNT_KEY_ADDRESSBOOK_CTAG = "addressbook_ctag",
|
||||
|
||||
WEB_URL_HELP = "http://davdroid.bitfire.at/configuration";
|
||||
WEB_URL_HELP = "http://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app";
|
||||
}
|
||||
|
@ -18,8 +18,14 @@ public class Starred extends Property {
|
||||
|
||||
public Starred(String value) {
|
||||
super(PROPERTY_NAME);
|
||||
|
||||
isStarred = Integer.parseInt(value) > 0;
|
||||
|
||||
try {
|
||||
isStarred = Integer.parseInt(value) > 0;
|
||||
} catch(NumberFormatException ex) {
|
||||
// value is not an integer, assume it's true because
|
||||
// otherwise, the property would probably not be present
|
||||
isStarred = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,6 +24,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import net.fortuna.ical4j.data.ParserException;
|
||||
import net.fortuna.ical4j.model.Date;
|
||||
import net.fortuna.ical4j.model.ValidationException;
|
||||
import net.fortuna.ical4j.vcard.GroupRegistry;
|
||||
import net.fortuna.ical4j.vcard.ParameterFactoryRegistry;
|
||||
@ -33,6 +34,7 @@ import net.fortuna.ical4j.vcard.PropertyFactoryRegistry;
|
||||
import net.fortuna.ical4j.vcard.VCard;
|
||||
import net.fortuna.ical4j.vcard.VCardBuilder;
|
||||
import net.fortuna.ical4j.vcard.VCardOutputter;
|
||||
import net.fortuna.ical4j.vcard.property.BDay;
|
||||
import net.fortuna.ical4j.vcard.property.Email;
|
||||
import net.fortuna.ical4j.vcard.property.Fn;
|
||||
import net.fortuna.ical4j.vcard.property.N;
|
||||
@ -60,8 +62,10 @@ public class Contact extends Resource {
|
||||
@Getter @Setter private String displayName;
|
||||
@Getter @Setter private String prefix, givenName, middleName, familyName, suffix;
|
||||
@Getter @Setter private String[] nickNames;
|
||||
|
||||
|
||||
@Getter @Setter private byte[] photo;
|
||||
|
||||
@Getter @Setter private Date birthDay;
|
||||
|
||||
|
||||
public Contact(String name, String ETag) {
|
||||
@ -174,6 +178,9 @@ public class Contact extends Resource {
|
||||
}
|
||||
}
|
||||
|
||||
for (Property p : vcard.getProperties(Id.BDAY))
|
||||
birthDay = ((BDay)p).getDate();
|
||||
|
||||
for (Property p : vcard.getProperties(Id.URL))
|
||||
URLs.add(((Url)p).getUri());
|
||||
|
||||
@ -213,7 +220,10 @@ public class Contact extends Resource {
|
||||
Log.w(TAG, "Couldn't encode photo");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (birthDay != null)
|
||||
properties.add(new BDay(birthDay));
|
||||
|
||||
if (familyName != null || middleName != null || givenName != null)
|
||||
properties.add(new N(familyName, givenName, StringUtils.split(middleName),
|
||||
StringUtils.split(prefix), StringUtils.split(suffix)));
|
||||
|
@ -9,9 +9,11 @@ package at.bitfire.davdroid.resource;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.ParseException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.fortuna.ical4j.model.Date;
|
||||
import net.fortuna.ical4j.vcard.Parameter.Id;
|
||||
import net.fortuna.ical4j.vcard.parameter.Type;
|
||||
import net.fortuna.ical4j.vcard.property.Telephone;
|
||||
@ -28,6 +30,7 @@ import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.ContactsContract.CommonDataKinds;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Email;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Nickname;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Note;
|
||||
@ -212,9 +215,24 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
||||
cursor = providerClient.query(dataURI(), new String[] { Photo.PHOTO },
|
||||
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||
new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
|
||||
while (cursor.moveToNext())
|
||||
if (cursor.moveToNext())
|
||||
c.setPhoto(cursor.getBlob(0));
|
||||
|
||||
// events (birthday)
|
||||
cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
|
||||
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
|
||||
while (cursor.moveToNext())
|
||||
try {
|
||||
switch (cursor.getInt(0)) {
|
||||
case CommonDataKinds.Event.TYPE_BIRTHDAY:
|
||||
c.setBirthDay(new Date(cursor.getString(1)));
|
||||
break;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
Log.w(TAG, "Ignoring event with unknown date format: " + cursor.getString(0));
|
||||
}
|
||||
|
||||
// URLs
|
||||
cursor = providerClient.query(dataURI(), new String[] { Website.URL },
|
||||
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||
@ -303,6 +321,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
||||
if (contact.getPhoto() != null)
|
||||
pendingOperations.add(buildPhoto(newDataInsertBuilder(localID, backrefIdx), contact.getPhoto()).build());
|
||||
|
||||
if (contact.getBirthDay() != null)
|
||||
pendingOperations.add(buildBirthDay(newDataInsertBuilder(localID, backrefIdx), contact.getBirthDay()).build());
|
||||
|
||||
for (URI uri : contact.getURLs())
|
||||
pendingOperations.add(buildURL(newDataInsertBuilder(localID, backrefIdx), uri).build());
|
||||
|
||||
@ -414,6 +435,13 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
||||
.withValue(Photo.PHOTO, photo);
|
||||
}
|
||||
|
||||
protected Builder buildBirthDay(Builder builder, Date birthDay) {
|
||||
return builder
|
||||
.withValue(Data.MIMETYPE, CommonDataKinds.Event.CONTENT_ITEM_TYPE)
|
||||
.withValue(CommonDataKinds.Event.TYPE, CommonDataKinds.Event.TYPE_BIRTHDAY)
|
||||
.withValue(CommonDataKinds.Event.START_DATE, birthDay.toString());
|
||||
}
|
||||
|
||||
protected Builder buildURL(Builder builder, URI uri) {
|
||||
return builder
|
||||
.withValue(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE)
|
||||
|
Loading…
Reference in New Issue
Block a user