Fix for task edit actions not working when synchronized to RTM.

pull/14/head
Tim Su 14 years ago
parent 486d675384
commit b2f26641f6

@ -14,10 +14,8 @@ import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
/** /**
* Exposes Task Details for Remember the Milk: * Exposes Task Details for Google TAsks:
* - RTM list * - list
* - RTM repeat information
* - RTM notes
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *

@ -3,8 +3,6 @@
*/ */
package com.todoroo.astrid.gtasks; package com.todoroo.astrid.gtasks;
import org.weloveastrid.rmilk.MilkUtilities;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
@ -32,7 +30,7 @@ import com.todoroo.astrid.data.MetadataApiDao.MetadataCriteria;
import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.data.TaskApiDao.TaskCriteria;
/** /**
* Exposes filters based on RTM lists * Exposes filters based on lists
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
@ -90,7 +88,7 @@ public class GtasksFilterExposer extends BroadcastReceiver {
list[0] = header; list[0] = header;
list[1] = listsCategory; list[1] = listsCategory;
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, MilkUtilities.IDENTIFIER); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, GtasksPreferenceService.IDENTIFIER);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, list); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, list);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
} }

@ -7,7 +7,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import org.json.JSONException; import org.json.JSONException;
@ -55,7 +54,6 @@ import com.todoroo.gtasks.GoogleTaskTask;
import com.todoroo.gtasks.GoogleTaskView; import com.todoroo.gtasks.GoogleTaskView;
import com.todoroo.gtasks.GoogleTasksException; import com.todoroo.gtasks.GoogleTasksException;
import com.todoroo.gtasks.GoogleTaskService.ConvenientTaskCreator; import com.todoroo.gtasks.GoogleTaskService.ConvenientTaskCreator;
import com.todoroo.gtasks.actions.Action;
import com.todoroo.gtasks.actions.Actions; import com.todoroo.gtasks.actions.Actions;
import com.todoroo.gtasks.actions.ListAction; import com.todoroo.gtasks.actions.ListAction;
import com.todoroo.gtasks.actions.ListActions; import com.todoroo.gtasks.actions.ListActions;
@ -75,11 +73,6 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
private static final Actions a = new Actions(); private static final Actions a = new Actions();
private static final ListActions l = new ListActions(); private static final ListActions l = new ListActions();
/** batched actions to execute */
private final ArrayList<Action> actions = new ArrayList<Action>();
private final HashMap<String, ArrayList<ListAction>> listActions =
new HashMap<String, ArrayList<ListAction>>();
static { static {
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
@ -230,7 +223,6 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
for(StoreObject dashboard : gtasksListService.getLists()) { for(StoreObject dashboard : gtasksListService.getLists()) {
String listId = dashboard.getValue(GtasksList.REMOTE_ID); String listId = dashboard.getValue(GtasksList.REMOTE_ID);
List<GoogleTaskTask> list = taskService.getTasks(listId); List<GoogleTaskTask> list = taskService.getTasks(listId);
System.err.println("list " + listId + " read " + list.size() + " tasks");
readTasksIntoRemoteTasks(list, remoteTasks); readTasksIntoRemoteTasks(list, remoteTasks);
} }
@ -242,7 +234,6 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
syncData.localUpdated.close(); syncData.localUpdated.close();
} }
executeBatchedActions();
gtasksTaskListUpdater.updateAllMetadata(); gtasksTaskListUpdater.updateAllMetadata();
gtasksPreferenceService.recordSuccessfulSync(); gtasksPreferenceService.recordSuccessfulSync();
@ -307,7 +298,6 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
private static final Property<?>[] PROPERTIES = new Property<?>[] { private static final Property<?>[] PROPERTIES = new Property<?>[] {
Task.ID, Task.ID,
Task.TITLE, Task.TITLE,
Task.IMPORTANCE,
Task.DUE_DATE, Task.DUE_DATE,
Task.CREATION_DATE, Task.CREATION_DATE,
Task.COMPLETION_DATE, Task.COMPLETION_DATE,
@ -348,20 +338,14 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
updateTaskHelper(local, null, createdTask); String remoteId = updateTaskHelper(local, null, createdTask);
String remoteId; gtasksTaskListUpdater.addRemoteTaskMapping(local.task.getId(), remoteId);
try {
remoteId = createdTask.go();
gtasksTaskListUpdater.addRemoteTaskMapping(local.task.getId(), remoteId);
} catch (JSONException e) {
throw new GoogleTasksException(e);
}
local.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, remoteId); local.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, remoteId);
return local; return local;
} }
private void updateTaskHelper(GtasksTaskContainer local, private String updateTaskHelper(GtasksTaskContainer local,
GtasksTaskContainer remote, TaskBuilder<?> builder) throws IOException { GtasksTaskContainer remote, TaskBuilder<?> builder) throws IOException {
String idTask = local.gtaskMetadata.getValue(GtasksMetadata.ID); String idTask = local.gtaskMetadata.getValue(GtasksMetadata.ID);
@ -375,7 +359,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
// moving between lists // moving between lists
if(remote != null && !idList.equals(remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID))) { if(remote != null && !idList.equals(remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID))) {
batch(a.moveTask(idTask, idList, remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), null)); taskService.executeActions(a.moveTask(idTask, idList, remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), null));
} }
// other properties // other properties
@ -388,12 +372,22 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
if(shouldTransmit(local, Task.NOTES, remote)) if(shouldTransmit(local, Task.NOTES, remote))
builder.notes(local.task.getValue(Task.NOTES)); builder.notes(local.task.getValue(Task.NOTES));
// moving within a list String id = idList;
if(remote == null || local.parentId != remote.parentId || local.priorSiblingId != remote.priorSiblingId) { ListAction moveAction = l.move(idTask, local.parentId, local.priorSiblingId);
batch(local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID),
l.move(idTask, local.parentId, local.priorSiblingId)); // write task
if(builder instanceof TaskModifier) {
ListAction action = ((TaskModifier) builder).done();
if(remote == null || local.parentId != remote.parentId || local.priorSiblingId != remote.priorSiblingId)
taskService.executeListActions(idList, action, moveAction);
else
taskService.executeListActions(idList, action);
} else {
id = ((ConvenientTaskCreator)builder).go();
taskService.executeListActions(idList, moveAction);
} }
return id;
} catch (JSONException e) { } catch (JSONException e) {
throw new GoogleTasksException(e); throw new GoogleTasksException(e);
} }
@ -457,45 +451,15 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
String id = local.gtaskMetadata.getValue(GtasksMetadata.ID); String id = local.gtaskMetadata.getValue(GtasksMetadata.ID);
TaskModifier modifyTask = l.modifyTask(id); TaskModifier modifyTask = l.modifyTask(id);
updateTaskHelper(local, remote, modifyTask);
if(shouldTransmit(local, Task.TITLE, remote)) if(shouldTransmit(local, Task.TITLE, remote))
modifyTask.name(local.task.getValue(Task.TITLE)); modifyTask.name(local.task.getValue(Task.TITLE));
ListAction action = modifyTask.done(); updateTaskHelper(local, remote, modifyTask);
batch(local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), action);
} catch (JSONException e) { } catch (JSONException e) {
throw new GoogleTasksException(e); throw new GoogleTasksException(e);
} }
} }
/** add action to batch */
private void batch(String list, ListAction action) {
if(!listActions.containsKey(list))
listActions.put(list, new ArrayList<ListAction>());
listActions.get(list).add(action);
}
/** add action to batch */
private void batch(Action action) {
actions.add(action);
}
/** execute all batched actions */
private void executeBatchedActions() throws IOException, JSONException {
if(!actions.isEmpty()) {
taskService.executeActions(actions.toArray(new Action[actions.size()]));
System.err.println("executed " + actions);
}
if(!listActions.isEmpty()) {
for(Entry<String, ArrayList<ListAction>> entry : listActions.entrySet()) {
taskService.executeListActions(entry.getKey(),
entry.getValue().toArray(new ListAction[entry.getValue().size()]));
System.err.println("executed " + entry.getValue() + " on " + entry.getKey());
}
}
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// --------------------------------------------------------- read / write // --------------------------------------------------------- read / write
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -519,7 +483,8 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
int length = tasks.size(); int length = tasks.size();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
GtasksTaskContainer task = tasks.get(i); GtasksTaskContainer task = tasks.get(i);
if(AndroidUtilities.equals(task.gtaskMetadata, target.gtaskMetadata)) if(AndroidUtilities.equals(task.gtaskMetadata.getValue(GtasksMetadata.ID),
target.gtaskMetadata.getValue(GtasksMetadata.ID)))
return i; return i;
} }
return -1; return -1;

@ -6,7 +6,6 @@ import java.util.Iterator;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksMetadata; import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.producteev.sync.ProducteevTask;
import com.todoroo.astrid.sync.SyncContainer; import com.todoroo.astrid.sync.SyncContainer;
/** /**
@ -38,7 +37,7 @@ public class GtasksTaskContainer extends SyncContainer {
for(Iterator<Metadata> iterator = metadata.iterator(); iterator.hasNext(); ) { for(Iterator<Metadata> iterator = metadata.iterator(); iterator.hasNext(); ) {
Metadata item = iterator.next(); Metadata item = iterator.next();
if(ProducteevTask.METADATA_KEY.equals(item.getValue(Metadata.KEY))) { if(GtasksMetadata.METADATA_KEY.equals(item.getValue(Metadata.KEY))) {
gtaskMetadata = item; gtaskMetadata = item;
iterator.remove(); iterator.remove();
// don't break, could be multiple // don't break, could be multiple

Loading…
Cancel
Save