From e3634794eed7a511f12845be20e01d56c031ca3b Mon Sep 17 00:00:00 2001 From: Tim Su Date: Thu, 26 Aug 2010 21:02:51 -0700 Subject: [PATCH] Fix for AST-180 - updating title, notes, or due date of an Astrid task updates calendar event --- .../todoroo/astrid/gcal/GCalControlSet.java | 21 +++++++++++++++ astrid/res/values/strings-gcal.xml | 3 +++ .../astrid/activity/TaskEditActivity.java | 26 ++++++++++++------- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/gcal/GCalControlSet.java b/astrid/plugin-src/com/todoroo/astrid/gcal/GCalControlSet.java index e45b7f695..9933c25bf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gcal/GCalControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/gcal/GCalControlSet.java @@ -177,7 +177,28 @@ public class GCalControlSet implements TaskEditControlSet { exceptionService.displayAndReportError(activity, activity.getString(R.string.gcal_TEA_error), e); } + } else if(calendarUri != null) { + try { + ContentValues updateValues = new ContentValues(); + + // check if we need to update the item + ContentValues setValues = task.getSetValues(); + if(setValues.containsKey(Task.TITLE.name)) + updateValues.put("title", task.getValue(Task.TITLE)); + if(setValues.containsKey(Task.NOTES.name)) + updateValues.put("description", task.getValue(Task.NOTES)); + if(setValues.containsKey(Task.DUE_DATE.name)) + createStartAndEndDate(task, updateValues); + + ContentResolver cr = activity.getContentResolver(); + if(cr.update(calendarUri, updateValues, null, null) > 0) + return activity.getString(R.string.gcal_TEA_calendar_updated); + } catch (Exception e) { + exceptionService.reportError("unable-to-update-calendar: " + //$NON-NLS-1$ + task.getValue(Task.CALENDAR_URI), e); + } } + return null; } diff --git a/astrid/res/values/strings-gcal.xml b/astrid/res/values/strings-gcal.xml index 3f8418844..9e74479b3 100644 --- a/astrid/res/values/strings-gcal.xml +++ b/astrid/res/values/strings-gcal.xml @@ -21,6 +21,9 @@ Error opening event! + + Calendar event also updated! + diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java index 72eb850f4..965d17fad 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java @@ -377,14 +377,18 @@ public final class TaskEditActivity extends TabActivity { /** Save task model from values in UI components */ private void save() { - for(TaskEditControlSet controlSet : controls) - controlSet.writeToModel(model); + StringBuilder toast = new StringBuilder(); + for(TaskEditControlSet controlSet : controls) { + String toastText = controlSet.writeToModel(model); + if(toastText != null) + toast.append('\n').append(toastText); + } if(title.getText().length() > 0) model.setValue(Task.DELETION_DATE, 0L); if(taskService.save(model) && title.getText().length() > 0) - showSaveToast(); + showSaveToast(toast.toString()); } @Override @@ -445,22 +449,26 @@ public final class TaskEditActivity extends TabActivity { * Displays a Toast reporting that the selected task has been saved and, if * it has a due date, that is due in 'x' amount of time, to 1 time-unit of * precision + * @param additionalMessage */ - private void showSaveToast() { + private void showSaveToast(String additionalMessage) { int stringResource; long due = model.getValue(Task.DUE_DATE); + String toastMessage; if (due != 0) { stringResource = R.string.TEA_onTaskSave_due; CharSequence formattedDate = DateUtils.getRelativeTimeSpanString(due); - Toast.makeText(this, - getResources().getString(stringResource, formattedDate), - Toast.LENGTH_SHORT).show(); + toastMessage = getString(stringResource, formattedDate); } else { - Toast.makeText(this, R.string.TEA_onTaskSave_notDue, - Toast.LENGTH_SHORT).show(); + toastMessage = getString(R.string.TEA_onTaskSave_notDue); } + + int length = additionalMessage.length() == 0 ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG; + Toast.makeText(this, + toastMessage + additionalMessage, + length).show(); } protected void discardButtonClick() {