diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 53900b207..6fb0366cc 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -440,7 +440,7 @@ - + @@ -454,7 +454,7 @@ - + diff --git a/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java b/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java index c56e184a5..68cde8d4a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java +++ b/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java @@ -35,20 +35,28 @@ public class GCalHelper { } public static void createTaskEventIfEnabled(Task t) { + createTaskEventIfEnabled(t, true); + } + + public static void createTaskEventIfEnabled(Task t, boolean deleteEventIfExists) { boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null && !Preferences.getStringValue(R.string.gcal_p_default).equals("-1"); //$NON-NLS-1$ if (gcalCreateEventEnabled) { ContentResolver cr = ContextManager.getContext().getContentResolver(); - Uri calendarUri = GCalHelper.createTaskEvent(t, cr, new ContentValues()); + Uri calendarUri = GCalHelper.createTaskEvent(t, cr, new ContentValues(), deleteEventIfExists); if (calendarUri != null) t.setValue(Task.CALENDAR_URI, calendarUri.toString()); } } public static Uri createTaskEvent(Task task, ContentResolver cr, ContentValues values) { + return createTaskEvent(task, cr, values, true); + } + + public static Uri createTaskEvent(Task task, ContentResolver cr, ContentValues values, boolean deleteEventIfExists) { String eventuri = getTaskEventUri(task); - if(!TextUtils.isEmpty(eventuri)) { + if(!TextUtils.isEmpty(eventuri) && deleteEventIfExists) { deleteTaskEvent(task); } diff --git a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java index d70696733..4e8926de9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java +++ b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java @@ -76,6 +76,7 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver { task.setValue(Task.DUE_DATE, newDueDate); task.setValue(Task.HIDE_UNTIL, hideUntil); task.putTransitory("repeat-complete", true); //$NON-NLS-1$ + GCalHelper.createTaskEventIfEnabled(task, false); PluginServices.getTaskService().save(task); return; } @@ -93,7 +94,7 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver { clone.setValue(Task.REMINDER_LAST, 0L); clone.setValue(Task.CALENDAR_URI, ""); //$NON-NLS-1$ - GCalHelper.createTaskEventIfEnabled(clone); + GCalHelper.createTaskEventIfEnabled(clone, false); PluginServices.getTaskService().save(clone); // clear recurrence from completed task so it can be re-completed diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java index 5a58200d3..bb2f55afd 100755 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java @@ -287,13 +287,16 @@ public final class TaskEditActivity extends Activity { GCalControlSet gcalControl = new GCalControlSet(TaskEditActivity.this, R.layout.control_set_gcal, R.layout.control_set_gcal_display, R.string.gcal_TEA_addToCalendar_label); - controls.add(gcalControl); + //The deadline control set contains the repeat controls and the calendar controls. + //NOTE: we add the gcalControl to the list AFTER the deadline control, because + //otherwise the correct date may not be written to the calendar event. Order matters! DeadlineControlSet deadlineControl = new DeadlineControlSet( TaskEditActivity.this, R.layout.control_set_deadline, R.layout.control_set_deadline_display, repeatControls.getDisplayView(), gcalControl.getDisplayView()); controls.add(deadlineControl); controlSetMap.put(getString(R.string.TEA_ctrl_when_pref), deadlineControl); + controls.add(gcalControl); ImportanceControlSet importanceControl = new ImportanceControlSet( TaskEditActivity.this, R.layout.control_set_importance);