Handle repeat-on-complete for those who sync with astrid.com

pull/14/head
Tim Su 13 years ago
parent e7cabcbdca
commit 21e905442d

@ -261,7 +261,8 @@ public final class ActFmSyncService {
if(!newlyCreated) { if(!newlyCreated) {
params.add("id"); params.add(remoteId); params.add("id"); params.add(remoteId);
} } else if(!values.containsKey(Task.TITLE.name))
return;
try { try {
params.add("token"); params.add(token); params.add("token"); params.add(token);

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

@ -106,7 +106,6 @@ public class TaskService {
return new Task(); return new Task();
newTask.clearValue(Task.ID); newTask.clearValue(Task.ID);
newTask.clearValue(Task.REMOTE_ID); newTask.clearValue(Task.REMOTE_ID);
taskDao.createNew(newTask);
TodorooCursor<Metadata> cursor = metadataDao.query( TodorooCursor<Metadata> cursor = metadataDao.query(
Query.select(Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId()))); Query.select(Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId())));
try { try {

Loading…
Cancel
Save