Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar service #325

Merged
merged 12 commits into from
Dec 8, 2012
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".Services.CalendarSyncService"></service>
</application>

</manifest>
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
<string name="preference_calendar_synch_title">Synchronize with calendar</string>
<string name="preference_calendar_name_summary">Choose calendar MobileOrg will use</string>
<string name="preference_calendar_name">Calendar name</string>
<string name="preference_calendar_pull_summary">Assimilate calendar entries not inserted by MobileOrg and add them to capture file. EXPERIMENTAL!</string>
<string name="preference_calendar_pull">Assimilate calendar entries</string>
<string name="preference_calendar_pull_delete_summary">Delete entries that have been assimilated from the calendar</string>
<string name="preference_calendar_pull_delete">Delete on assimilation</string>
<string name="preference_clear_calendar_promt">Clear phone calendar</string>
<string name="preference_clear_calendar_promt_message">Are you sure you want to clear the phones\' calendar?</string>
<string name="preference_calendar_reminder_summary">Add reminders for scheduled items to calendar</string>
Expand Down
12 changes: 12 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@
android:key="calendarHabits"
android:summary="@string/preference_calendar_show_habits_summary"
android:title="@string/preference_calendar_show_habits" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="calendarEnabled"
android:key="calendarPull"
android:summary="@string/preference_calendar_pull_summary"
android:title="@string/preference_calendar_pull" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="calendarPull"
android:key="calendarPullDelete"
android:summary="@string/preference_calendar_pull_delete_summary"
android:title="@string/preference_calendar_pull_delete" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_other" >
<PreferenceScreen
Expand Down
7 changes: 7 additions & 0 deletions src/com/matburt/mobileorg/Gui/Outline/OutlineActionMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.matburt.mobileorg.Gui.Capture.EditActivity;
import com.matburt.mobileorg.OrgData.OrgFile;
import com.matburt.mobileorg.OrgData.OrgNode;
import com.matburt.mobileorg.Services.CalendarSyncService;
import com.matburt.mobileorg.Services.TimeclockService;
import com.matburt.mobileorg.util.OrgFileNotFoundException;
import com.matburt.mobileorg.util.OrgUtils;
Expand Down Expand Up @@ -209,6 +210,12 @@ private void deleteFileNode() {
try {
OrgFile file = new OrgFile(node.fileId, resolver);
file.removeFile(resolver);

Intent calDeleteIntent = new Intent(context, CalendarSyncService.class);
calDeleteIntent.putExtra(CalendarSyncService.CLEARDB, true);
calDeleteIntent.putExtra(CalendarSyncService.FILELIST, new String[] {file.filename});
context.startService(calDeleteIntent);

OrgUtils.announceSyncDone(context);
} catch (OrgFileNotFoundException e) {}
}
Expand Down
12 changes: 6 additions & 6 deletions src/com/matburt/mobileorg/Gui/Outline/OutlineItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.matburt.mobileorg.R;
import com.matburt.mobileorg.Gui.Theme.DefaultTheme;
import com.matburt.mobileorg.OrgData.OrgFileParser;
import com.matburt.mobileorg.OrgData.OrgNode;
import com.matburt.mobileorg.OrgData.OrgProviderUtils;

import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Typeface;
Expand All @@ -25,6 +19,12 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.matburt.mobileorg.R;
import com.matburt.mobileorg.Gui.Theme.DefaultTheme;
import com.matburt.mobileorg.OrgData.OrgFileParser;
import com.matburt.mobileorg.OrgData.OrgNode;
import com.matburt.mobileorg.OrgData.OrgProviderUtils;

public class OutlineItem extends RelativeLayout implements Checkable {

private TextView titleView;
Expand Down
4 changes: 2 additions & 2 deletions src/com/matburt/mobileorg/Gui/Theme/DefaultTheme.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.matburt.mobileorg.Gui.Theme;

import com.matburt.mobileorg.util.OrgUtils;

import android.content.Context;
import android.graphics.Color;

import com.matburt.mobileorg.util.OrgUtils;

public class DefaultTheme {

public int gray = Color.GRAY;
Expand Down
40 changes: 40 additions & 0 deletions src/com/matburt/mobileorg/OrgData/CalendarEntriesParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.matburt.mobileorg.OrgData;

import android.database.Cursor;

import com.matburt.mobileorg.Services.CalendarComptabilityWrappers.intEvents;

public class CalendarEntriesParser {

private int idColumn;
private int dtStartColumn;
private int dtEndColumn;
private int titleColumn;
private int descriptionColumn;
private int locationColumn;
private int allDayColumn;

public CalendarEntriesParser(intEvents events, Cursor cursor) {
dtStartColumn = cursor.getColumnIndexOrThrow(events.DTSTART);
dtEndColumn = cursor.getColumnIndexOrThrow(events.DTEND);
titleColumn = cursor.getColumnIndexOrThrow(events.TITLE);
idColumn = cursor.getColumnIndexOrThrow(events._ID);
descriptionColumn = cursor.getColumnIndexOrThrow(events.DESCRIPTION);
locationColumn = cursor.getColumnIndexOrThrow(events.EVENT_LOCATION);
allDayColumn = cursor.getColumnIndexOrThrow(events.ALL_DAY);
}

public CalendarEntry getEntryFromCursor(Cursor cursor) {
CalendarEntry entry = new CalendarEntry();

entry.dtStart = cursor.getLong(dtStartColumn);
entry.dtEnd = cursor.getLong(dtEndColumn);
entry.title = cursor.getString(titleColumn);
entry.id = cursor.getLong(idColumn);
entry.description = cursor.getString(descriptionColumn);
entry.location = cursor.getString(locationColumn);
entry.allDay = cursor.getInt(allDayColumn);

return entry;
}
}
43 changes: 43 additions & 0 deletions src/com/matburt/mobileorg/OrgData/CalendarEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.matburt.mobileorg.OrgData;

import android.text.TextUtils;

public class CalendarEntry {
public String title = "";
public String description = "";
public String location = "";
public long id = -1;
public long dtStart = 0;
public long dtEnd = 0;
public int allDay = 0;

@Override
public boolean equals(Object o) {
if (o instanceof OrgNodeDate) {
OrgNodeDate entry = (OrgNodeDate) o;
return this.dtStart == entry.beginTime
&& this.dtEnd == entry.endTime
&& entry.getTitle().startsWith(this.title);
}

return super.equals(o);
}

public OrgNode convertToOrgNode() {
OrgNode node = new OrgNode();
node.name = this.title;

boolean isAllDay = allDay > 0;
String date = OrgNodeDate.getDate(this.dtStart, this.dtEnd, isAllDay);
String formatedDate = OrgNodeTimeDate.formatDate(
OrgNodeTimeDate.TYPE.Timestamp, date);

String payload = formatedDate + "\n" + this.description;

if (TextUtils.isEmpty(this.location) == false)
payload += "\n:LOCATION: " + this.location;

node.setPayload(payload);
return node;
}
}
6 changes: 1 addition & 5 deletions src/com/matburt/mobileorg/OrgData/OrgFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.content.ContentResolver;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.matburt.mobileorg.OrgData.OrgContract.OrgData;
Expand Down Expand Up @@ -223,11 +222,8 @@ public static HashMap<String, String> getFilesFromIndex(String filecontents) {
Pattern indexOrgFilePattern = Pattern.compile(fileMatchPattern);
Matcher indexOrgFileMatcher = indexOrgFilePattern.matcher(filecontents);
HashMap<String, String> allOrgFiles = new HashMap<String, String>();

Log.d("MobileOrg", filecontents);


while (indexOrgFileMatcher.find()) {
Log.d("MobileOrg", "Key: " + indexOrgFileMatcher.group(1) + ":" + indexOrgFileMatcher.group(2));
allOrgFiles.put(indexOrgFileMatcher.group(1), indexOrgFileMatcher.group(2));
}

Expand Down
32 changes: 32 additions & 0 deletions src/com/matburt/mobileorg/OrgData/OrgNodeDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -16,6 +17,7 @@ public class OrgNodeDate {
public long endTime = 0;
public int allDay = 0;
public String type = "";
private String title = "";

private static final SimpleDateFormat dateTimeformatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private static final SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd");
Expand Down Expand Up @@ -73,11 +75,41 @@ private static long getDayInUTC(long time) {
return cal.getTimeInMillis();
}

public static String getDate(long dtStart, long dtEnd, boolean allDay) {
String date;

if (allDay)
date = dateformatter.format(new Date(dtStart));
else
date = dateTimeformatter.format(new Date(dtStart));

if (dtEnd > 0 && dtStart != dtEnd) {
long timeDiff = dtEnd - dtStart;

if(timeDiff <= DateUtils.DAY_IN_MILLIS) {
SimpleDateFormat timeformatter = new SimpleDateFormat("HH:mm");
String endTime = timeformatter.format(new Date(dtEnd));

date += "-" + endTime;
}
}

return date;
}

/**
* Whether an event is in the past. True if event ended 24 hours ago or
* sometime in the future.
*/
public boolean isInPast() {
return System.currentTimeMillis() - DateUtils.DAY_IN_MILLIS >= endTime;
}

public void setTitle(String title) {
this.title = title;
}

public String getTitle() {
return this.type + this.title;
}
}
5 changes: 4 additions & 1 deletion src/com/matburt/mobileorg/OrgData/OrgNodePayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,27 @@ public String getProperty(String property) {
}


public ArrayList<OrgNodeDate> getDates() {
public ArrayList<OrgNodeDate> getDates(String title) {
ArrayList<OrgNodeDate> result = new ArrayList<OrgNodeDate>();

try {
OrgNodeDate scheduledEntry = new OrgNodeDate(getScheduled());
scheduledEntry.type = "SC: ";
scheduledEntry.setTitle(title);
result.add(scheduledEntry);
} catch (IllegalArgumentException e) {}

try {
OrgNodeDate deadlineEntry = new OrgNodeDate(getDeadline());
deadlineEntry.type = "DL: ";
deadlineEntry.setTitle(title);
result.add(deadlineEntry);
} catch (IllegalArgumentException e) {}

try {
OrgNodeDate timestampEntry = new OrgNodeDate(getTimestamp());
timestampEntry.type = "";
timestampEntry.setTitle(title);
result.add(timestampEntry);
} catch (IllegalArgumentException e) {}

Expand Down
Loading