|
|
|
@ -16,8 +16,11 @@ import com.google.ical.values.DateValue;
|
|
|
|
|
import com.google.ical.values.DateValueImpl;
|
|
|
|
|
import com.google.ical.values.Frequency;
|
|
|
|
|
import com.google.ical.values.RRule;
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
import com.todoroo.andlib.service.ContextManager;
|
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
|
|
|
|
import com.todoroo.astrid.api.AstridApiConstants;
|
|
|
|
|
import com.todoroo.astrid.core.PluginServices;
|
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
@ -26,9 +29,12 @@ import com.todoroo.astrid.utility.Flags;
|
|
|
|
|
|
|
|
|
|
public class RepeatTaskCompleteListener extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
@Autowired ActFmPreferenceService actFmPreferenceService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
ContextManager.setContext(context);
|
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
|
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
|
|
|
|
|
if(taskId == -1)
|
|
|
|
|
return;
|
|
|
|
@ -38,10 +44,6 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
|
|
|
|
|
if(task == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// don't repeat when it repeats on the server
|
|
|
|
|
if(task.getValue(Task.REMOTE_ID) > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
String recurrence = task.getValue(Task.RECURRENCE);
|
|
|
|
|
if(recurrence != null && recurrence.length() > 0) {
|
|
|
|
|
long newDueDate;
|
|
|
|
@ -61,6 +63,15 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
|
|
|
|
|
hideUntil += newDueDate - task.getValue(Task.DUE_DATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update repeat time when it repeats on the server
|
|
|
|
|
if(actFmPreferenceService.isLoggedIn()) {
|
|
|
|
|
task.setValue(Task.COMPLETION_DATE, 0L);
|
|
|
|
|
task.setValue(Task.DUE_DATE, newDueDate);
|
|
|
|
|
task.setValue(Task.HIDE_UNTIL, hideUntil);
|
|
|
|
|
PluginServices.getTaskService().save(task);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clone to create new task
|
|
|
|
|
Task clone = PluginServices.getTaskService().clone(task);
|
|
|
|
|
clone.setValue(Task.DUE_DATE, newDueDate);
|
|
|
|
|