src/org/gege/caldavsyncadapter/Event.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

michael@0 1 /**
michael@0 2 * Copyright (c) 2012-2013, Gerald Garcia, Timo Berger
michael@0 3 *
michael@0 4 * This file is part of Andoid Caldav Sync Adapter Free.
michael@0 5 *
michael@0 6 * Andoid Caldav Sync Adapter Free is free software: you can redistribute
michael@0 7 * it and/or modify it under the terms of the GNU General Public License
michael@0 8 * as published by the Free Software Foundation, either version 3 of the
michael@0 9 * License, or at your option any later version.
michael@0 10 *
michael@0 11 * Andoid Caldav Sync Adapter Free is distributed in the hope that
michael@0 12 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
michael@0 13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
michael@0 14 * GNU General Public License for more details.
michael@0 15 *
michael@0 16 * You should have received a copy of the GNU General Public License
michael@0 17 * along with Andoid Caldav Sync Adapter Free.
michael@0 18 * If not, see <http://www.gnu.org/licenses/>.
michael@0 19 *
michael@0 20 */
michael@0 21 package org.gege.caldavsyncadapter;
michael@0 22
michael@0 23 import android.content.ContentValues;
michael@0 24 import android.provider.CalendarContract.Events;
michael@0 25 import android.util.Log;
michael@0 26
michael@0 27 /**
michael@0 28 * abstract class for Calendar and Android events
michael@0 29 */
michael@0 30 abstract public class Event {
michael@0 31 private static final String TAG = "Event";
michael@0 32
michael@0 33 /**
michael@0 34 * stores the ETAG of an event
michael@0 35 */
michael@0 36 public static String ETAG = Events.SYNC_DATA1;
michael@0 37
michael@0 38 /**
michael@0 39 * internal Tag used to identify deleted events
michael@0 40 */
michael@0 41 public static String INTERNALTAG = Events.SYNC_DATA2;
michael@0 42
michael@0 43 /**
michael@0 44 * store the whole VEVENT in here
michael@0 45 * missing TAGs they might be missing for google update
michael@0 46 *
michael@0 47 * CREATED:20130906T102857Z
michael@0 48 * DTSTAMP:20130906T102857Z
michael@0 49 * LAST-MODIFIED:20130906T102857Z
michael@0 50 * SEQUENCE:0
michael@0 51 */
michael@0 52 public static String RAWDATA = Events.SYNC_DATA3;
michael@0 53
michael@0 54 /**
michael@0 55 * stores the UID of an Event
michael@0 56 * example: UID:e6be67c6-eff0-44f8-a1a0-6c2cb1029944-caldavsyncadapter
michael@0 57 */
michael@0 58 public static String UID = Events.SYNC_DATA4;
michael@0 59
michael@0 60 /**
michael@0 61 * the event transformed into ContentValues
michael@0 62 */
michael@0 63 public ContentValues ContentValues = new ContentValues();
michael@0 64
michael@0 65 abstract public String getETag();
michael@0 66 abstract public void setETag(String ETag);
michael@0 67
michael@0 68 /**
michael@0 69 * returns a list of all items that are comparable with this sync adapter
michael@0 70 * @return a list of all items that are comparable with this sync adapter
michael@0 71 */
michael@0 72 public static java.util.ArrayList<String> getComparableItems() {
michael@0 73 java.util.ArrayList<String> Result = new java.util.ArrayList<String>();
michael@0 74 Result.add(Events.DTSTART);
michael@0 75 Result.add(Events.DTEND);
michael@0 76 Result.add(Events.EVENT_TIMEZONE);
michael@0 77 Result.add(Events.EVENT_END_TIMEZONE);
michael@0 78 Result.add(Events.ALL_DAY);
michael@0 79 Result.add(Events.DURATION);
michael@0 80 Result.add(Events.TITLE);
michael@0 81 Result.add(Events.CALENDAR_ID);
michael@0 82 Result.add(Events._SYNC_ID);
michael@0 83 //Result.add(Events.SYNC_DATA1);
michael@0 84 Result.add(ETAG);
michael@0 85 Result.add(Events.DESCRIPTION);
michael@0 86 Result.add(Events.EVENT_LOCATION);
michael@0 87 Result.add(Events.ACCESS_LEVEL);
michael@0 88 Result.add(Events.STATUS);
michael@0 89 Result.add(Events.RDATE);
michael@0 90 Result.add(Events.RRULE);
michael@0 91 Result.add(Events.EXRULE);
michael@0 92 Result.add(Events.EXDATE);
michael@0 93 Result.add(UID);
michael@0 94
michael@0 95 return Result;
michael@0 96 }
michael@0 97
michael@0 98 /**
michael@0 99 * sets the AndroidCalendarId for this event
michael@0 100 * @param ID the AndroidCalendarId for this event
michael@0 101 */
michael@0 102 public void setAndroidCalendarId(long ID) {
michael@0 103 if (this.ContentValues.containsKey(Events.CALENDAR_ID))
michael@0 104 this.ContentValues.remove(Events.CALENDAR_ID);
michael@0 105
michael@0 106 this.ContentValues.put(Events.CALENDAR_ID, ID);
michael@0 107 }
michael@0 108
michael@0 109 /**
michael@0 110 * returns the AndroidCalendarId for this event.
michael@0 111 * @return the AndroidCalendarId for this event
michael@0 112 */
michael@0 113 public long getAndroidCalendarId() {
michael@0 114 long Result = -1;
michael@0 115 if (this.ContentValues.containsKey(Events.CALENDAR_ID))
michael@0 116 Result = this.ContentValues.getAsLong(Events.CALENDAR_ID);
michael@0 117 return Result;
michael@0 118 }
michael@0 119
michael@0 120 /**
michael@0 121 * returns the UID for this event. you can also check, whether the UID was stored from server. the V1.7 release and before didn't save them.
michael@0 122 * example: UID:e6be67c6-eff0-44f8-a1a0-6c2cb1029944-caldavsyncadapter
michael@0 123 * @return the UID for this event
michael@0 124 */
michael@0 125 public String getUID() {
michael@0 126 String Result = "";
michael@0 127 if (this.ContentValues.containsKey(UID))
michael@0 128 Result = this.ContentValues.getAsString(UID);
michael@0 129
michael@0 130 return Result;
michael@0 131 }
michael@0 132
michael@0 133 /**
michael@0 134 * compares the given ContentValues with the current ones for differences
michael@0 135 * @param calendarEventValues the contentValues of the calendar event
michael@0 136 * @return if the events are different
michael@0 137 */
michael@0 138 public boolean checkEventValuesChanged(ContentValues calendarEventValues) {
michael@0 139 boolean Result = false;
michael@0 140 Object ValueAndroid = null;
michael@0 141 Object ValueCalendar = null;
michael@0 142 java.util.ArrayList<String> CompareItems = Event.getComparableItems();
michael@0 143
michael@0 144 for (String Key: CompareItems) {
michael@0 145
michael@0 146 if (this.ContentValues.containsKey(Key))
michael@0 147 ValueAndroid = this.ContentValues.get(Key);
michael@0 148 else
michael@0 149 ValueAndroid = null;
michael@0 150
michael@0 151 if (calendarEventValues.containsKey(Key))
michael@0 152 ValueCalendar = calendarEventValues.get(Key);
michael@0 153 else
michael@0 154 ValueCalendar = null;
michael@0 155
michael@0 156 /*
michael@0 157 * TODO: Sync is designed to "Server always wins", should be a general option for this adapter
michael@0 158 */
michael@0 159 if (ValueAndroid != null) {
michael@0 160 if (ValueCalendar != null) {
michael@0 161 if (!ValueAndroid.toString().equals(ValueCalendar.toString())) {
michael@0 162 Log.d(TAG, "difference in " + Key.toString() + ":" + ValueAndroid.toString() + " <> " + ValueCalendar.toString());
michael@0 163 this.ContentValues.put(Key,ValueCalendar.toString());
michael@0 164 Result = true;
michael@0 165 }
michael@0 166 } else {
michael@0 167 Log.d(TAG, "difference in " + Key.toString() + ":" + ValueAndroid.toString() + " <> null");
michael@0 168 this.ContentValues.putNull(Key);
michael@0 169 Result = true;
michael@0 170 }
michael@0 171 } else {
michael@0 172 if (ValueCalendar != null) {
michael@0 173 Log.d(TAG, "difference in " + Key.toString() + ":null <> " + ValueCalendar.toString());
michael@0 174 this.ContentValues.put(Key, ValueCalendar.toString());
michael@0 175 Result = true;
michael@0 176 } else {
michael@0 177 // both null -> this is ok
michael@0 178 }
michael@0 179 }
michael@0 180 }
michael@0 181
michael@0 182 return Result;
michael@0 183 }
michael@0 184 }

mercurial