Alert when rescheduling a repeating task

pull/14/head
Sam Bosley 13 years ago
parent 5658f820de
commit 818487e693

@ -71,45 +71,45 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
}
// update repeat time when it repeats on the server
if(actFmPreferenceService.isLoggedIn() && !skipActFmCheck) {
task.setValue(Task.COMPLETION_DATE, 0L);
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;
}
// clone to create new task
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
Flags.set(Flags.GTASKS_SUPPRESS_SYNC);
Task clone = PluginServices.getTaskService().clone(task);
clone.setValue(Task.DUE_DATE, newDueDate);
clone.setValue(Task.HIDE_UNTIL, hideUntil);
clone.setValue(Task.COMPLETION_DATE, 0L);
clone.setValue(Task.TIMER_START, 0L);
clone.setValue(Task.ELAPSED_SECONDS, 0);
clone.setValue(Task.REMINDER_SNOOZE, 0L);
clone.setValue(Task.REMINDER_LAST, 0L);
clone.setValue(Task.CALENDAR_URI, ""); //$NON-NLS-1$
GCalHelper.createTaskEventIfEnabled(clone, false);
PluginServices.getTaskService().save(clone);
// clear recurrence from completed task so it can be re-completed
task.setValue(Task.RECURRENCE, ""); //$NON-NLS-1$
task.setValue(Task.DETAILS_DATE, 0L);
long oldDueDate = task.getValue(Task.DUE_DATE);
task.setValue(Task.COMPLETION_DATE, 0L);
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);
// send a broadcast
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, clone.getId());
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, task.getValue(Task.DUE_DATE));
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
context.sendOrderedBroadcast(broadcastIntent, null);
Flags.set(Flags.REFRESH);
return;
// // clone to create new task
// Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
// Flags.set(Flags.GTASKS_SUPPRESS_SYNC);
// Task clone = PluginServices.getTaskService().clone(task);
// clone.setValue(Task.DUE_DATE, newDueDate);
// clone.setValue(Task.HIDE_UNTIL, hideUntil);
// clone.setValue(Task.COMPLETION_DATE, 0L);
// clone.setValue(Task.TIMER_START, 0L);
// clone.setValue(Task.ELAPSED_SECONDS, 0);
// clone.setValue(Task.REMINDER_SNOOZE, 0L);
// clone.setValue(Task.REMINDER_LAST, 0L);
// clone.setValue(Task.CALENDAR_URI, ""); //$NON-NLS-1$
//
// GCalHelper.createTaskEventIfEnabled(clone, false);
// PluginServices.getTaskService().save(clone);
//
// // clear recurrence from completed task so it can be re-completed
// task.setValue(Task.RECURRENCE, ""); //$NON-NLS-1$
// task.setValue(Task.DETAILS_DATE, 0L);
//
// PluginServices.getTaskService().save(task);
}
}

@ -63,6 +63,8 @@
<string name="DLG_cancel">Cancel</string>
<string name="DLG_undo">Undo</string>
<!-- =============================================================== UI == -->
<!-- Label for DateButtons with no value -->

@ -59,4 +59,9 @@
<!-- task detail for repeat from completion date (%s -> interval) -->
<string name="repeat_detail_completion">%s after completion</string>
<!-- text for confirmation dialog after repeating a task -->
<string name="repeat_rescheduling_dialog_title">Rescheduling task \"%s\"</string>
<string name="repeat_rescheduling_dialog_bubble">I\'ve rescheduled this repeating task from %1$s to %2$s</string>
</resources>

@ -14,17 +14,21 @@ import android.view.View;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.IntentFilter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.core.SearchFilter;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.reminders.ReminderDialog;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.ui.DateChangedAlerts;
/**
* This wrapper activity contains all the glue-code to handle the callbacks between the different
@ -49,6 +53,7 @@ public class AstridActivity extends FragmentActivity
protected int fragmentLayout = LAYOUT_SINGLE;
private final ReminderReceiver reminderReceiver = new ReminderReceiver();
private final RepeatConfirmationReceiver repeatConfirmationReceiver = new RepeatConfirmationReceiver();
public FilterListFragment getFilterListFragment() {
FilterListFragment frag = (FilterListFragment) getSupportFragmentManager()
@ -91,15 +96,17 @@ public class AstridActivity extends FragmentActivity
@Override
protected void onResume() {
super.onResume();
android.content.IntentFilter intentFilter = new android.content.IntentFilter(Notifications.BROADCAST_IN_APP_NOTIFY);
intentFilter.setPriority(1);
registerReceiver(reminderReceiver, intentFilter);
android.content.IntentFilter reminderIntentFilter = new android.content.IntentFilter(Notifications.BROADCAST_IN_APP_NOTIFY);
reminderIntentFilter.setPriority(1);
registerReceiver(reminderReceiver, reminderIntentFilter);
registerReceiver(repeatConfirmationReceiver, new android.content.IntentFilter(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED));
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(reminderReceiver);
unregisterReceiver(repeatConfirmationReceiver);
}
/**
@ -279,6 +286,7 @@ public class AstridActivity extends FragmentActivity
if (taskId > 0) {
String text = intent.getStringExtra(Notifications.EXTRAS_TEXT);
Dialog d = ReminderDialog.createReminderDialog(AstridActivity.this, taskId, text);
d.setOwnerActivity(AstridActivity.this);
d.show();
}
@ -288,4 +296,21 @@ public class AstridActivity extends FragmentActivity
}
private class RepeatConfirmationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, 0);
if (taskId > 0) {
long oldDueDate = intent.getLongExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, 0);
long newDueDate = intent.getLongExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, 0);
Task task = PluginServices.getTaskService().fetchById(taskId, DateChangedAlerts.REPEAT_RESCHEDULED_PROPERTIES);
Dialog d = DateChangedAlerts.createRepeatTaskRescheduledDialog(AstridActivity.this, task, oldDueDate, newDueDate);
d.setOwnerActivity(AstridActivity.this);
d.show();
// Do some stuff
}
}
}
}

@ -114,7 +114,7 @@ import com.todoroo.astrid.service.SyncV2Service.SyncV2Provider;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.ui.QuickAddMarkupDialog;
import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Flags;
@ -1190,7 +1190,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
}
private static void showAlertForMarkupTask(AstridActivity activity, Task task, String originalText) {
Dialog d = QuickAddMarkupDialog.createQuickAddMarkupDialog(activity, task, originalText);
Dialog d = DateChangedAlerts.createQuickAddMarkupDialog(activity, task, originalText);
d.show();
}

@ -16,16 +16,19 @@ import android.widget.TextView;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.utility.Flags;
/**
* Helper class that creates a dialog to confirm the results of a quick add markup
* @author Sam
*
*/
public class QuickAddMarkupDialog {
public class DateChangedAlerts {
public static Dialog createQuickAddMarkupDialog(final AstridActivity activity, Task task, String originalText) {
final Dialog d = new Dialog(activity, R.style.ReminderDialog);
@ -36,7 +39,7 @@ public class QuickAddMarkupDialog {
((Button) d.findViewById(R.id.reminder_complete)).setText(R.string.DLG_ok);
((TextView) d.findViewById(R.id.reminder_title)).setText(activity.getString(R.string.TLA_quickadd_confirm_title, originalText));
Spanned speechBubbleText = constructSpeechBubbleText(activity, task);
Spanned speechBubbleText = constructSpeechBubbleTextForQuickAdd(activity, task);
((TextView) d.findViewById(R.id.reminder_message)).setText(speechBubbleText, TextView.BufferType.SPANNABLE);
@ -63,8 +66,63 @@ public class QuickAddMarkupDialog {
return d;
}
public static final Property<?>[] REPEAT_RESCHEDULED_PROPERTIES =
new Property<?>[] {
Task.ID,
Task.TITLE,
Task.DUE_DATE,
Task.HIDE_UNTIL
};
public static Dialog createRepeatTaskRescheduledDialog(final AstridActivity activity, final Task task, final long oldDueDate, final long newDueDate) {
final Dialog d = new Dialog(activity, R.style.ReminderDialog);
d.setContentView(R.layout.astrid_reminder_view);
d.findViewById(R.id.reminder_snooze).setVisibility(View.GONE);
((Button) d.findViewById(R.id.reminder_complete)).setText(R.string.DLG_ok);
((Button) d.findViewById(R.id.reminder_edit)).setText(R.string.DLG_undo);
((TextView) d.findViewById(R.id.reminder_title)).setText(activity.getString(R.string.repeat_rescheduling_dialog_title, task.getValue(Task.TITLE)));
String oldDueDateString = getRelativeDateAndTimeString(activity, oldDueDate);
String newDueDateString = getRelativeDateAndTimeString(activity, newDueDate);
String speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble, oldDueDateString, newDueDateString);
((TextView) d.findViewById(R.id.reminder_message)).setText(speechBubbleText);
d.findViewById(R.id.reminder_complete).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
}
});
d.findViewById(R.id.dismiss).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
}
});
d.findViewById(R.id.reminder_edit).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
task.setValue(Task.DUE_DATE, oldDueDate);
long hideUntil = task.getValue(Task.HIDE_UNTIL);
if (hideUntil > 0)
task.setValue(Task.HIDE_UNTIL, hideUntil - (newDueDate - oldDueDate));
PluginServices.getTaskService().save(task);
Flags.set(Flags.REFRESH);
}
});
return d;
}
@SuppressWarnings("nls")
private static Spanned constructSpeechBubbleText(Context context, Task task) {
private static Spanned constructSpeechBubbleTextForQuickAdd(Context context, Task task) {
String[] priorityStrings = context.getResources().getStringArray(R.array.TLA_priority_strings);
int[] colorsArray = new int[] { R.color.importance_1, R.color.importance_2, R.color.importance_3, R.color.importance_4 };
@ -77,10 +135,7 @@ public class QuickAddMarkupDialog {
}
if (TextUtils.isEmpty(dueDate)) {
dueDate = task.getValue(Task.DUE_DATE) > 0 ? DateUtilities.getRelativeDay(context, date, false) : "";
if(Task.hasDueTime(date))
dueDate = String.format("%s at %s", dueDate, //$NON-NLS-1$
DateUtilities.getTimeString(context, new Date(date)));
dueDate = getRelativeDateAndTimeString(context, date);
}
if (!TextUtils.isEmpty(dueDate))
@ -97,6 +152,14 @@ public class QuickAddMarkupDialog {
return Html.fromHtml(fullString);
}
private static String getRelativeDateAndTimeString(Context context, long date) {
String dueDate = date > 0 ? DateUtilities.getRelativeDay(context, date, false) : "";
if(Task.hasDueTime(date))
dueDate = String.format("%s at %s", dueDate, //$NON-NLS-1$
DateUtilities.getTimeString(context, new Date(date)));
return dueDate;
}
private static String getRecurrenceString(Context context, Task task) {
try {
RRule rrule = new RRule(task.getValue(Task.RECURRENCE));
Loading…
Cancel
Save