diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/api/CreateRequest.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/api/CreateRequest.java deleted file mode 100644 index c9768c070..000000000 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/api/CreateRequest.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.gtasks.api; - -import com.google.api.services.tasks.model.Task; - -import java.io.IOException; -/** - * Encapsulates a request to the api to create a task on the remote server - * @author Sam Bosley - * - */ -public class CreateRequest extends PushRequest { - - private String parent; - private String priorSiblingId; - - public CreateRequest(GtasksInvoker service, String listId, Task toUpdate, String parent, String priorSiblingId) { - super(service, listId, toUpdate); - this.parent = parent; - this.priorSiblingId = priorSiblingId; - } - - @Override - public Task executePush() throws IOException { - return service.createGtask(listId, toPush, parent, priorSiblingId); - } - - @Override - protected void recover() { - parent = null; - priorSiblingId = null; - } -} diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/api/MoveRequest.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/api/MoveRequest.java index 5b8afa8f5..045e02254 100644 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/api/MoveRequest.java +++ b/astrid/src/main/java/com/todoroo/astrid/gtasks/api/MoveRequest.java @@ -7,32 +7,48 @@ package com.todoroo.astrid.gtasks.api; import com.google.api.services.tasks.model.Task; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; /** * Encapsulates a request to the api to change the ordering on the given task * @author Sam Bosley * */ -public class MoveRequest extends PushRequest { +public class MoveRequest { + + private static final Logger log = LoggerFactory.getLogger(MoveRequest.class); + private final GtasksInvoker service; private String taskId; + private final String destinationList; private String parentId; private String priorSiblingId; public MoveRequest(GtasksInvoker service, String taskId, String destinationList, String parentId, String priorSiblingId) { - super(service, destinationList, null); + this.service = service; this.taskId = taskId; + this.destinationList = destinationList; this.parentId = parentId; this.priorSiblingId = priorSiblingId; } - @Override - public Task executePush() throws IOException { - return service.moveGtask(super.listId, taskId, parentId, priorSiblingId); + public Task push() throws IOException { + try { + return executePush(); + } catch (IOException e) { + log.error(e.getMessage(), e); + recover(); + return executePush(); + } + } + + private Task executePush() throws IOException { + return service.moveGtask(destinationList, taskId, parentId, priorSiblingId); } - @Override - protected void recover() { + private void recover() { parentId = null; priorSiblingId = null; } diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/api/PushRequest.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/api/PushRequest.java deleted file mode 100644 index 5be7b9b80..000000000 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/api/PushRequest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.gtasks.api; - -import com.google.api.services.tasks.model.Task; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -/** - * Abstract class that encapsulates some push request to the server - * @author Sam Bosley - * - */ -public abstract class PushRequest { - - private static final Logger log = LoggerFactory.getLogger(PushRequest.class); - - protected String listId; - protected Task toPush; - protected GtasksInvoker service; - - public PushRequest(GtasksInvoker service, String listId, Task toPush) { - this.service = service; - this.listId = listId; - this.toPush = toPush; - } - - public Task push() throws IOException { - try { - return executePush(); - } catch (IOException e) { - log.error(e.getMessage(), e); - recover(); - return executePush(); - } - } - - protected abstract Task executePush() throws IOException; - - protected abstract void recover(); -} diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java index 1ed7ef911..d953173b3 100644 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java +++ b/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java @@ -20,7 +20,6 @@ import com.todoroo.astrid.data.Task; import com.todoroo.astrid.gtasks.GtasksMetadata; import com.todoroo.astrid.gtasks.GtasksMetadataService; import com.todoroo.astrid.gtasks.GtasksPreferenceService; -import com.todoroo.astrid.gtasks.api.CreateRequest; import com.todoroo.astrid.gtasks.api.GtasksApiUtilities; import com.todoroo.astrid.gtasks.api.GtasksInvoker; import com.todoroo.astrid.gtasks.api.HttpNotFoundException; @@ -316,8 +315,7 @@ public class GtasksSyncService { String parent = gtasksMetadataService.getRemoteParentId(gtasksMetadata); String priorSibling = gtasksMetadataService.getRemoteSiblingId(listId, gtasksMetadata); - CreateRequest create = new CreateRequest(invoker, listId, remoteModel, parent, priorSibling); - com.google.api.services.tasks.model.Task created = create.executePush(); + com.google.api.services.tasks.model.Task created = invoker.createGtask(listId, remoteModel, parent, priorSibling); if (created != null) { //Update the metadata for the newly created task @@ -354,9 +352,6 @@ public class GtasksSyncService { } private boolean checkForToken() { - if (!gtasksPreferenceService.isLoggedIn()) { - return false; - } - return true; + return gtasksPreferenceService.isLoggedIn(); } }