Repeat confirmation dialog when finishing a repeat task with an end date

pull/14/head
Sam Bosley 14 years ago
parent e76e3ce8ca
commit 348f7cca58

@ -68,29 +68,19 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
long oldDueDate = task.getValue(Task.DUE_DATE);
long repeatUntil = task.getValue(Task.REPEAT_UNTIL);
if (repeatUntil > 0 && newDueDate >= repeatUntil) {
Intent repeatFinished = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED);
repeatFinished.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
repeatFinished.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
repeatFinished.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
context.sendOrderedBroadcast(repeatFinished, null);
return;
}
long hideUntil = task.getValue(Task.HIDE_UNTIL);
if(hideUntil > 0 && task.getValue(Task.DUE_DATE) > 0) {
hideUntil += newDueDate - task.getValue(Task.DUE_DATE);
boolean repeatFinished = repeatUntil > 0 && newDueDate >= repeatUntil;
if (repeatFinished) {
Intent repeatFinishedIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED);
repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
context.sendOrderedBroadcast(repeatFinishedIntent, null);
System.err.println("SENDING BROADCAST");
return;
}
// update repeat time when it repeats on the server
task.setValue(Task.COMPLETION_DATE, 0L);
task.setValue(Task.DUE_DATE, newDueDate);
task.setValue(Task.HIDE_UNTIL, hideUntil);
task.putTransitory(TaskService.TRANS_REPEAT_COMPLETE, true);
ContentResolver cr = ContextManager.getContext().getContentResolver();
GCalHelper.rescheduleRepeatingTask(task, cr);
PluginServices.getTaskService().save(task);
rescheduleTask(task, newDueDate);
// send a broadcast
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
@ -103,6 +93,22 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
}
}
public static void rescheduleTask(Task task, long newDueDate) {
long hideUntil = task.getValue(Task.HIDE_UNTIL);
if(hideUntil > 0 && task.getValue(Task.DUE_DATE) > 0) {
hideUntil += newDueDate - 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(TaskService.TRANS_REPEAT_COMPLETE, true);
ContentResolver cr = ContextManager.getContext().getContentResolver();
GCalHelper.rescheduleRepeatingTask(task, cr);
PluginServices.getTaskService().save(task);
}
/** Compute next due date */
public static long computeNextDueDate(Task task, String recurrence) throws ParseException {
boolean repeatAfterCompletion = task.getFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION);

@ -58,6 +58,8 @@
<string name="repeat_until_title">Repeat until...</string>
<string name="repeat_keep_going">Keep going</string>
<string-array name="repeat_type">
<!-- slide 20c: repeat type (date to repeat from) -->
<item>from due date</item>
@ -85,13 +87,18 @@
<!-- text for confirmation dialog after repeating a task -->
<string name="repeat_rescheduling_dialog_title">Rescheduling task \"%s\"</string>
<!-- text for confirmation dialog after repeating a task for the last time -->
<string name="repeat_rescheduling_dialog_title_last_time">Completed repeating task \"%s\"</string>
<!-- text for when a repeating task was rescheduled -->
<string name="repeat_rescheduling_dialog_bubble">%1$s I\'ve rescheduled this repeating task from %2$s to %3$s</string>
<!-- text for when a repeating task was rescheduled but didn't have a due date yet -->
<string name="repeat_rescheduling_dialog_bubble_no_date">%1$s I\'ve rescheduled this repeating task to %2$s</string>
<!-- text for when a repeating task was rescheduled for the last time -->
<string name="repeat_rescheduling_dialog_bubble_last_time">You had this repeating until %1$s, and now you\'re all done. %2$s</string>
<string-array name="repeat_encouragement">
<!-- Encouragement in rescheduling dialog bubble -->
@ -100,5 +107,12 @@
<item>I love when you\'re productive!</item>
<item>Doesn\'t it feel good to check something off?</item>
</string-array>
<string-array name="repeat_encouragement_last_time">
<!-- Encouragement in rescheduling dialog bubble -->
<item>Good job!</item>
<item>I\'m so proud of you!</item>
<item>I love when you\'re productive!</item>
</string-array>
</resources>

@ -109,9 +109,11 @@ public class AstridActivity extends FragmentActivity
Notifications.BROADCAST_IN_APP_NOTIFY);
reminderIntentFilter.setPriority(1);
registerReceiver(reminderReceiver, reminderIntentFilter);
registerReceiver(repeatConfirmationReceiver,
new android.content.IntentFilter(
AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED));
android.content.IntentFilter repeatFilter = new android.content.IntentFilter(
AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
repeatFilter.addAction(AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED);
registerReceiver(repeatConfirmationReceiver, repeatFilter);
}
@Override
@ -383,8 +385,10 @@ public class AstridActivity extends FragmentActivity
DateChangedAlerts.REPEAT_RESCHEDULED_PROPERTIES);
try {
boolean lastTime = AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED.equals(intent.getAction());
DateChangedAlerts.showRepeatTaskRescheduledDialog(
AstridActivity.this, task, oldDueDate, newDueDate);
AstridActivity.this, task, oldDueDate, newDueDate, lastTime);
} catch (BadTokenException e) { // Activity not running when tried to show dialog--rebroadcast
new Thread() {
@Override

@ -29,6 +29,8 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.repeats.RepeatTaskCompleteListener;
import com.todoroo.astrid.ui.DateAndTimeDialog.DateAndTimeDialogListener;
import com.todoroo.astrid.utility.Flags;
/**
@ -114,10 +116,12 @@ public class DateChangedAlerts {
Task.ID,
Task.TITLE,
Task.DUE_DATE,
Task.HIDE_UNTIL
Task.HIDE_UNTIL,
Task.REPEAT_UNTIL
};
public static void showRepeatTaskRescheduledDialog(final AstridActivity activity, final Task task, final long oldDueDate, final long newDueDate) {
public static void showRepeatTaskRescheduledDialog(final AstridActivity activity, final Task task,
final long oldDueDate, final long newDueDate, final boolean lastTime) {
if (!Preferences.getBoolean(PREF_SHOW_HELPERS, true))
return;
@ -128,18 +132,54 @@ public class DateChangedAlerts {
Button okButton = (Button) d.findViewById(R.id.reminder_complete);
Button undoButton = (Button) d.findViewById(R.id.reminder_edit);
d.findViewById(R.id.reminder_snooze).setVisibility(View.GONE);
Button keepGoing = (Button) d.findViewById(R.id.reminder_snooze);
if (!lastTime) {
keepGoing.setVisibility(View.GONE);
} else {
keepGoing.setText(R.string.repeat_keep_going);
keepGoing.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
long startDate = 0;
DateAndTimeDialog picker = new DateAndTimeDialog(activity, startDate, R.layout.repeat_until_dialog, R.string.repeat_until_title);
picker.setDateAndTimeDialogListener(new DateAndTimeDialogListener() {
@Override
public void onDateAndTimeSelected(long date) {
d.dismiss();
task.setValue(Task.REPEAT_UNTIL, date);
RepeatTaskCompleteListener.rescheduleTask(task, newDueDate);
Flags.set(Flags.REFRESH);
}
@Override
public void onDateAndTimeCancelled() {
//
}
});
picker.show();
}
});
}
okButton.setText(R.string.DLG_ok);
undoButton.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)));
int titleResource = lastTime ? R.string.repeat_rescheduling_dialog_title_last_time : R.string.repeat_rescheduling_dialog_title;
((TextView) d.findViewById(R.id.reminder_title)).setText(
activity.getString(titleResource, task.getValue(Task.TITLE)));
String oldDueDateString = getRelativeDateAndTimeString(activity, oldDueDate);
String newDueDateString = getRelativeDateAndTimeString(activity, newDueDate);
String[] encouragements = activity.getResources().getStringArray(R.array.repeat_encouragement);
String repeatUntilDateString = getRelativeDateAndTimeString(activity, task.getValue(Task.REPEAT_UNTIL));
int encouragementResource = lastTime ? R.array.repeat_encouragement_last_time : R.array.repeat_encouragement;
String[] encouragements = activity.getResources().getStringArray(encouragementResource);
String encouragement = encouragements[(int) (Math.random()*encouragements.length)];
String speechBubbleText;
if (!TextUtils.isEmpty(oldDueDateString))
if (lastTime)
speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble_last_time, repeatUntilDateString, encouragement);
else if (!TextUtils.isEmpty(oldDueDateString))
speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble, encouragement, oldDueDateString, newDueDateString);
else
speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble_no_date, encouragement, newDueDateString);
@ -154,6 +194,7 @@ public class DateChangedAlerts {
public void onClick(View v) {
d.dismiss();
task.setValue(Task.DUE_DATE, oldDueDate);
task.setValue(Task.COMPLETION_DATE, 0L);
long hideUntil = task.getValue(Task.HIDE_UNTIL);
if (hideUntil > 0)
task.setValue(Task.HIDE_UNTIL, hideUntil - (newDueDate - oldDueDate));

Loading…
Cancel
Save