Skip to content

Commit

Permalink
Merge branch 'release/0.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy Enns committed Mar 13, 2015
2 parents 0ff43fe + 9ff09a7 commit 20f24b8
Show file tree
Hide file tree
Showing 18 changed files with 717 additions and 711 deletions.
4 changes: 2 additions & 2 deletions ACalDAV/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.we.acaldav"
android:versionCode="004"
android:versionName="0.0.4">
android:versionCode="005"
android:versionName="0.0.5">

<uses-sdk
android:minSdkVersion="14"
Expand Down
111 changes: 56 additions & 55 deletions ACalDAV/src/org/gege/caldavsyncadapter/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import android.provider.CalendarContract.Events;
import android.util.Log;

import java.util.ArrayList;

/**
* abstract class for Calendar and Android events
*/
Expand Down Expand Up @@ -69,29 +71,28 @@ abstract public class Event {
* @return a list of all items that are comparable with this sync adapter
*/
public static java.util.ArrayList<String> getComparableItems() {
java.util.ArrayList<String> Result = new java.util.ArrayList<String>();
Result.add(Events.DTSTART);
Result.add(Events.DTEND);
Result.add(Events.EVENT_TIMEZONE);
Result.add(Events.EVENT_END_TIMEZONE);
Result.add(Events.ALL_DAY);
Result.add(Events.DURATION);
Result.add(Events.TITLE);
Result.add(Events.CALENDAR_ID);
Result.add(Events._SYNC_ID);
//Result.add(Events.SYNC_DATA1);
Result.add(ETAG);
Result.add(Events.DESCRIPTION);
Result.add(Events.EVENT_LOCATION);
Result.add(Events.ACCESS_LEVEL);
Result.add(Events.STATUS);
Result.add(Events.RDATE);
Result.add(Events.RRULE);
Result.add(Events.EXRULE);
Result.add(Events.EXDATE);
Result.add(UID);

return Result;
ArrayList<String> lcResult = new ArrayList<String>();
lcResult.add(Events.DTSTART);
lcResult.add(Events.DTEND);
lcResult.add(Events.EVENT_TIMEZONE);
lcResult.add(Events.EVENT_END_TIMEZONE);
lcResult.add(Events.ALL_DAY);
lcResult.add(Events.DURATION);
lcResult.add(Events.TITLE);
lcResult.add(Events.CALENDAR_ID);
lcResult.add(Events._SYNC_ID);
lcResult.add(ETAG);
lcResult.add(Events.DESCRIPTION);
lcResult.add(Events.EVENT_LOCATION);
lcResult.add(Events.ACCESS_LEVEL);
lcResult.add(Events.STATUS);
lcResult.add(Events.RDATE);
lcResult.add(Events.RRULE);
lcResult.add(Events.EXRULE);
lcResult.add(Events.EXDATE);
lcResult.add(UID);

return lcResult;
}

abstract public String getETag();
Expand All @@ -104,11 +105,11 @@ public static java.util.ArrayList<String> getComparableItems() {
* @return the AndroidCalendarId for this event
*/
public long getAndroidCalendarId() {
long Result = -1;
long lcResult = -1;
if (this.ContentValues.containsKey(Events.CALENDAR_ID)) {
Result = this.ContentValues.getAsLong(Events.CALENDAR_ID);
lcResult = this.ContentValues.getAsLong(Events.CALENDAR_ID);
}
return Result;
return lcResult;
}

/**
Expand All @@ -132,12 +133,12 @@ public void setAndroidCalendarId(long ID) {
* @return the UID for this event
*/
public String getUID() {
String Result = "";
String lcResult = "";
if (this.ContentValues.containsKey(UID)) {
Result = this.ContentValues.getAsString(UID);
lcResult = this.ContentValues.getAsString(UID);
}

return Result;
return lcResult;
}

/**
Expand All @@ -147,54 +148,54 @@ public String getUID() {
* @return if the events are different
*/
public boolean checkEventValuesChanged(ContentValues calendarEventValues) {
boolean Result = false;
Object ValueAndroid = null;
Object ValueCalendar = null;
java.util.ArrayList<String> CompareItems = Event.getComparableItems();
boolean lcResult = false;
Object lcValueAndroid = null;
Object lcValueCalendar = null;
java.util.ArrayList<String> lcCompareItems = Event.getComparableItems();

for (String Key : CompareItems) {
for (String key : lcCompareItems) {

if (this.ContentValues.containsKey(Key)) {
ValueAndroid = this.ContentValues.get(Key);
if (this.ContentValues.containsKey(key)) {
lcValueAndroid = this.ContentValues.get(key);
} else {
ValueAndroid = null;
lcValueAndroid = null;
}

if (calendarEventValues.containsKey(Key)) {
ValueCalendar = calendarEventValues.get(Key);
if (calendarEventValues.containsKey(key)) {
lcValueCalendar = calendarEventValues.get(key);
} else {
ValueCalendar = null;
lcValueCalendar = null;
}

/*
* TODO: Sync is designed to "Server always wins", should be a general option for this adapter
*/
if (ValueAndroid != null) {
if (ValueCalendar != null) {
if (!ValueAndroid.toString().equals(ValueCalendar.toString())) {
Log.d(TAG, "difference in " + Key.toString() + ":" + ValueAndroid.toString()
+ " <> " + ValueCalendar.toString());
this.ContentValues.put(Key, ValueCalendar.toString());
Result = true;
if (lcValueAndroid != null) {
if (lcValueCalendar != null) {
if (!lcValueAndroid.toString().equals(lcValueCalendar.toString())) {
Log.d(TAG, "difference in " + key.toString() + ":" + lcValueAndroid.toString()
+ " <> " + lcValueCalendar.toString());
this.ContentValues.put(key, lcValueCalendar.toString());
lcResult = true;
}
} else {
Log.d(TAG, "difference in " + Key.toString() + ":" + ValueAndroid.toString()
Log.d(TAG, "difference in " + key.toString() + ":" + lcValueAndroid.toString()
+ " <> null");
this.ContentValues.putNull(Key);
Result = true;
this.ContentValues.putNull(key);
lcResult = true;
}
} else {
if (ValueCalendar != null) {
Log.d(TAG, "difference in " + Key.toString() + ":null <> " + ValueCalendar
if (lcValueCalendar != null) {
Log.d(TAG, "difference in " + key.toString() + ":null <> " + lcValueCalendar
.toString());
this.ContentValues.put(Key, ValueCalendar.toString());
Result = true;
this.ContentValues.put(key, lcValueCalendar.toString());
lcResult = true;
} else {
// both null -> this is ok
}
}
}

return Result;
return lcResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Reminders;
import android.util.Log;

import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
Expand Down Expand Up @@ -103,16 +104,9 @@ public class AndroidEvent extends org.gege.caldavsyncadapter.Event {

private Calendar mCalendar = null;

/* private Account mAccount = null;
private ContentProviderClient mProvider = null;*/

//public AndroidEvent(Account account, ContentProviderClient provider, Uri uri, Uri calendarUri) {
public AndroidEvent(Uri uri, Uri calendarUri) {
super();
this.setUri(uri);
/* this.mAccount = account;
this.mProvider = provider;*/
//this.setCounterpartUri(calendarUri);
mAndroidCalendarUri = calendarUri;
}

Expand Down Expand Up @@ -170,7 +164,6 @@ public boolean readContentValues(Cursor cur) {
this.ContentValues
.put(Events.CALENDAR_ID, cur.getString(cur.getColumnIndex(Events.CALENDAR_ID)));
this.ContentValues.put(Events._SYNC_ID, cur.getString(cur.getColumnIndex(Events._SYNC_ID)));
//this.ContentValues.put(Events.SYNC_DATA1, cur.getString(cur.getColumnIndex(Events.SYNC_DATA1))); //not needed here, eTag has already been read
this.ContentValues
.put(Events.DESCRIPTION, cur.getString(cur.getColumnIndex(Events.DESCRIPTION)));
this.ContentValues.put(Events.EVENT_LOCATION,
Expand Down Expand Up @@ -274,7 +267,7 @@ public boolean readAttendees(Cursor cur) {
}

} catch (URISyntaxException e) {
e.printStackTrace();
Log.e(getETag(), e.getMessage());
}
return true;
}
Expand Down Expand Up @@ -329,30 +322,8 @@ public boolean createIcs(String strUid) {
TimeZone timeZone = null;
Thread.currentThread().setContextClassLoader(App.getContext().getClassLoader());
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();

//TODO: do not simply create the ics-file new. take into account the RAWDATA if available
/*
* dtstart=1365598800000
* dtend=1365602400000
* eventTimezone=Europe/Berlin
* eventEndTimezone=null
* duration=null
* allDay=0
* rrule=null
* rdate=null
* exrule=null
* exdate=null
* title=Einurlner Termin
* description=null
* eventLocation=null
* accessLevel=0
* eventStatus=0
*
* calendar_id=4
* lastDate=-197200128
* sync_data1=null
* _sync_id=null
* dirty=1
*/

try {
mCalendar = new Calendar();
Expand All @@ -365,18 +336,6 @@ public boolean createIcs(String strUid) {
mCalendar.getComponents().add(event);
PropertyList propEvent = event.getProperties();

// DTSTAMP -> is created by new VEvent() automatical
//na

// CREATED
//na

// LAST-MODIFIED
//na

// SEQUENCE
//na

// DTSTART
long lngStart = this.ContentValues.getAsLong(Events.DTSTART);
String strTZStart = this.ContentValues.getAsString(Events.EVENT_TIMEZONE);
Expand Down Expand Up @@ -577,37 +536,10 @@ public boolean createIcs(String strUid) {
}

} catch (ParseException e) {
e.printStackTrace();
Log.e(getETag(), e.getMessage());
}

return result;
}

/**
* marks the android event as already handled
*
* @see AndroidEvent#cInternalTag
* @see SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri,
* DavCalendar, SyncStats)
*/
// public boolean tagAndroidEvent() throws RemoteException {
//
// ContentValues values = new ContentValues();
// values.put(Event.INTERNALTAG, 1);
//
// int RowCount = this.mProvider
// .update(asSyncAdapter(this.getUri(), this.mAccount.name, this.mAccount.type),
// values, null, null);
// //Log.e(TAG,"Rows updated: " + RowCount.toString());
//
// return (RowCount == 1);
// }

/* private static Uri asSyncAdapter(Uri uri, String account, String accountType) {
return uri.buildUpon()
.appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")
.appendQueryParameter(Calendars.ACCOUNT_NAME, account)
.appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
}*/
}

Loading

0 comments on commit 20f24b8

Please sign in to comment.