Permalink
Browse files

Merge remote-tracking branch 'origin/calendar'

* origin/calendar:
  Fixed scheduling of allDay events. Added DL: and SC: infront of scheduled and deadline items.
  Fixes timezone issue #197.
  Adapted search function to find all timestamped tasks.
  "LOCATION" property will be inserted into calendar as location.
  Enabled adding of timestamped entries to calendar.
  ADD_CHILD nodes now get proper file id.
  • Loading branch information...
matburt committed Mar 29, 2012
2 parents 3c02dd8 + 05641d1 commit a2f4e43846b61323a68819dd682f47613c85831c
@@ -281,8 +281,8 @@ private void save() {
} else if (this.actionMode.equals(ACTIONMODE_ADDCHILD)) {
MobileOrgApplication appInst = (MobileOrgApplication) this.getApplication();
OrgDatabase orgDB = appInst.getDB();
- long file_id = orgDB.addOrUpdateFile(OrgFile.CAPTURE_FILE, OrgFile.CAPTURE_FILE_ALIAS, "", true);
Long parent = this.node_id;
+ long file_id = this.orgDB.getFileId(this.orgDB.getFilenameFromNodeId(parent));
long node_id = orgDB.addNode(parent, newTitle, newTodo, newPriority, newTags, file_id);
boolean addTimestamp = PreferenceManager.getDefaultSharedPreferences(
@@ -1,9 +1,17 @@
package com.matburt.mobileorg.Parsing;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.TextUtils;
+import android.text.format.DateUtils;
+import android.text.format.Time;
+import android.util.Log;
public class NodePayload {
private StringBuilder payload = new StringBuilder();
@@ -14,10 +22,8 @@
private String content = null;
private String scheduled = null;
-
private String deadline = null;
- @SuppressWarnings("unused")
- private String timestamp = null;
+ private ArrayList<String> timestamps = new ArrayList<String>();
private String id = null; // Can be :ID: (or :ORIGINAL_ID: for agendas.org)
@@ -35,7 +41,7 @@ public void setContent(String content) {
public String getContent() {
if(this.content == null)
- this.content = cleanPayload();
+ cleanPayload();
return this.content;
}
@@ -56,20 +62,38 @@ public String getNewPayloadResidue() {
public String getId() {
if(this.id == null)
- this.stripTags();
+ this.stripProperties();
return this.id;
}
- private String cleanPayload() {
+ public String getProperty(String property) {
+ String residue = getPayloadResidue();
+ final Pattern propertiesLine = Pattern.compile(":"+property+":([^\\n]+)");
+ Matcher propm = propertiesLine.matcher(residue);
+
+ if(propm.find())
+ return propm.group(1).trim();
+ else
+ return "";
+ }
+
+ private void cleanPayload() {
this.scheduled = stripDate("SCHEDULED:");
this.deadline = stripDate("DEADLINE:");
- this.timestamp = stripDate("");
+ stripTimestamps();
- stripTags();
+ stripProperties();
stripFileProperties();
- return payload.toString().trim();
+ this.content = payload.toString().trim();
+ }
+
+ private void stripTimestamps() {
+ String date = "";
+ while((date = stripDate("")).equals("") == false) {
+ this.timestamps.add(date);
+ }
}
private String stripDate(String scheduled) {
@@ -94,7 +118,7 @@ private String stripDate(String scheduled) {
}
// TODO Convert to use pattern
- private void stripTags() {
+ private void stripProperties() {
final Pattern propertiesLine = Pattern.compile(":[A-Za-z_]+:");
Matcher propm = propertiesLine.matcher(this.payload);
@@ -109,7 +133,6 @@ private void stripTags() {
} else
end = payload.indexOf("\n", propm.end());
-
if(end == -1)
end = propm.end();
else {
@@ -124,7 +147,6 @@ private void stripTags() {
}
}
- // TODO Convert to use Pattern
private void stripFileProperties() {
while (true) {
int start = payload.indexOf("#+");
@@ -140,19 +162,90 @@ private void stripFileProperties() {
}
}
+
/**
* Returns a string containing the time at which a todo is scheduled or deadlined.
*/
- public String getDate() {
- if(this.scheduled == null)
+ public ArrayList<DateEntry> getDates() {
+ ArrayList<DateEntry> result = new ArrayList<DateEntry>();
+
+ if(this.scheduled == null) {
this.scheduled = stripDate("SCHEDULED:");
+ DateEntry scheduledEntry = getDateEntry(this.scheduled);
+ if(scheduledEntry != null) {
+ scheduledEntry.type = "SC: ";
+ result.add(scheduledEntry);
+ }
+ }
- if(TextUtils.isEmpty(this.scheduled) && this.deadline == null) {
+ if(this.deadline == null) {
this.deadline = stripDate("DEADLINE:");
- return this.deadline;
+ DateEntry deadlineEntry = getDateEntry(this.deadline);
+ if(deadlineEntry != null) {
+ deadlineEntry.type = "DL: ";
+ result.add(deadlineEntry);
+ }
}
- return this.scheduled;
+ stripTimestamps();
+ for(String timestamp: this.timestamps) {
+ DateEntry timestampEntry = getDateEntry(timestamp);
+ if(timestampEntry != null)
+ result.add(timestampEntry);
+ }
+
+ return result;
+ }
+
+ public class DateEntry {
+ public long beginTime;
+ public long endTime;
+ public int allDay;
+ public String type = "";
+ }
+
+ private DateEntry getDateEntry(String date)
+ throws IllegalArgumentException {
+ final Pattern schedulePattern = Pattern
+ .compile("(\\d{4}-\\d{2}-\\d{2})(?:[^\\d]*)(\\d{1,2}\\:\\d{2})?\\-?(\\d{1,2}\\:\\d{2})?");
+
+ Matcher propm = schedulePattern.matcher(date);
+ DateEntry result = new DateEntry();
+
+ if (propm.find()) {
+ try {
+ if(propm.group(2) == null) { // event is an entire day event
+ result.beginTime = getTimeInMs(propm.group(1), "00:00").getTime();
+ result.beginTime += TimeZone.getTimeZone(
+ Time.getCurrentTimezone()).getOffset(
+ result.beginTime);
+
+ result.endTime = result.beginTime; // + DateUtils.DAY_IN_MILLIS;
+ result.allDay = 1;
+ }
+ else if (propm.group(2) != null) { // has hh:mm entry
+ result.beginTime = getTimeInMs(propm.group(1), propm.group(2)).getTime();
+ result.allDay = 0;
+
+ if (propm.group(3) != null) { // has hh:mm-hh:mm entry
+ result.endTime = getTimeInMs(propm.group(1), propm.group(3)).getTime();
+ } else // event is one hour per default
+ result.endTime = result.beginTime + DateUtils.HOUR_IN_MILLIS;
+ }
+
+ return result;
+ } catch (ParseException e) {
+ Log.w("MobileOrg",
+ "Unable to parse schedule: " + date);
+ }
+ } else
+ Log.w("MobileOrg", "Unable to find time entry of entry");
+ return null;
+ }
+
+ private Date getTimeInMs(String date, String time) throws ParseException {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+ return formatter.parse(date + " " + time);
}
public String getScheduled() {
@@ -405,7 +405,7 @@ public void cloneNode(Long node_id, Long parent_id, Long target_file_id) {
public Cursor getFileSchedule(String filename) {
long file_id = this.getFilenameId(filename);
- String whereQuery = "file_id=? AND (payload LIKE '%SCHEDULED:%' OR payload LIKE '%DEADLINE:%')";
+ String whereQuery = "file_id=? AND (payload LIKE '%<%>%')";
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
"calendarHabits", true) == false)
Oops, something went wrong.

0 comments on commit a2f4e43

Please sign in to comment.