diff --git a/astrid/.classpath b/astrid/.classpath index c7efb1be2..db233317d 100644 --- a/astrid/.classpath +++ b/astrid/.classpath @@ -15,14 +15,19 @@ - - - - - + + + + + + + + + + diff --git a/astrid/libs/google-api-client-1.4.1-beta.jar b/astrid/libs/google-api-client-1.4.1-beta.jar deleted file mode 100644 index c22af9721..000000000 Binary files a/astrid/libs/google-api-client-1.4.1-beta.jar and /dev/null differ diff --git a/astrid/libs/google-api-client-1.5.0-beta.jar b/astrid/libs/google-api-client-1.5.0-beta.jar new file mode 100644 index 000000000..41f2e578e Binary files /dev/null and b/astrid/libs/google-api-client-1.5.0-beta.jar differ diff --git a/astrid/libs/google-api-client-extensions-1.5.0-beta.jar b/astrid/libs/google-api-client-extensions-1.5.0-beta.jar new file mode 100644 index 000000000..b893cf2d1 Binary files /dev/null and b/astrid/libs/google-api-client-extensions-1.5.0-beta.jar differ diff --git a/astrid/libs/google-api-client-extensions-android2-1.4.1-beta.jar b/astrid/libs/google-api-client-extensions-android2-1.4.1-beta.jar deleted file mode 100644 index e486bb08a..000000000 Binary files a/astrid/libs/google-api-client-extensions-android2-1.4.1-beta.jar and /dev/null differ diff --git a/astrid/libs/google-api-client-extensions-android2-1.5.0-beta.jar b/astrid/libs/google-api-client-extensions-android2-1.5.0-beta.jar new file mode 100644 index 000000000..856f201eb Binary files /dev/null and b/astrid/libs/google-api-client-extensions-android2-1.5.0-beta.jar differ diff --git a/astrid/libs/google-api-client-googleapis-1.4.1-beta.jar b/astrid/libs/google-api-client-googleapis-1.4.1-beta.jar deleted file mode 100644 index 002689f63..000000000 Binary files a/astrid/libs/google-api-client-googleapis-1.4.1-beta.jar and /dev/null differ diff --git a/astrid/libs/google-api-client-googleapis-extensions-android2-1.4.1-beta.jar b/astrid/libs/google-api-client-googleapis-extensions-android2-1.4.1-beta.jar deleted file mode 100644 index efffa088d..000000000 Binary files a/astrid/libs/google-api-client-googleapis-extensions-android2-1.4.1-beta.jar and /dev/null differ diff --git a/astrid/libs/google-api-services-tasks-v1-1.0.0-beta.jar b/astrid/libs/google-api-services-tasks-v1-1.0.0-beta.jar deleted file mode 100644 index 2ce3ccbeb..000000000 Binary files a/astrid/libs/google-api-services-tasks-v1-1.0.0-beta.jar and /dev/null differ diff --git a/astrid/libs/google-api-services-tasks-v1-1.2.2-beta-sources.jar b/astrid/libs/google-api-services-tasks-v1-1.2.2-beta-sources.jar new file mode 100644 index 000000000..afe7b02aa Binary files /dev/null and b/astrid/libs/google-api-services-tasks-v1-1.2.2-beta-sources.jar differ diff --git a/astrid/libs/google-api-services-tasks-v1-1.2.2-beta.jar b/astrid/libs/google-api-services-tasks-v1-1.2.2-beta.jar new file mode 100644 index 000000000..ed071e8f1 Binary files /dev/null and b/astrid/libs/google-api-services-tasks-v1-1.2.2-beta.jar differ diff --git a/astrid/libs/google-http-client-1.5.0-beta-sources.jar b/astrid/libs/google-http-client-1.5.0-beta-sources.jar new file mode 100644 index 000000000..9dc3a551c Binary files /dev/null and b/astrid/libs/google-http-client-1.5.0-beta-sources.jar differ diff --git a/astrid/libs/google-http-client-1.5.0-beta.jar b/astrid/libs/google-http-client-1.5.0-beta.jar new file mode 100644 index 000000000..b5e610ddf Binary files /dev/null and b/astrid/libs/google-http-client-1.5.0-beta.jar differ diff --git a/astrid/libs/google-http-client-extensions-1.5.0-beta.jar b/astrid/libs/google-http-client-extensions-1.5.0-beta.jar new file mode 100644 index 000000000..c9b6ef72b Binary files /dev/null and b/astrid/libs/google-http-client-extensions-1.5.0-beta.jar differ diff --git a/astrid/libs/google-http-client-extensions-android2-1.5.0-beta.jar b/astrid/libs/google-http-client-extensions-android2-1.5.0-beta.jar new file mode 100644 index 000000000..e5fd826af Binary files /dev/null and b/astrid/libs/google-http-client-extensions-android2-1.5.0-beta.jar differ diff --git a/astrid/libs/google-oauth-client-1.5.0-beta.jar b/astrid/libs/google-oauth-client-1.5.0-beta.jar new file mode 100644 index 000000000..af73e9aa4 Binary files /dev/null and b/astrid/libs/google-oauth-client-1.5.0-beta.jar differ diff --git a/astrid/libs/google-oauth-client-extensions-1.5.0-beta.jar b/astrid/libs/google-oauth-client-extensions-1.5.0-beta.jar new file mode 100644 index 000000000..f253f0132 Binary files /dev/null and b/astrid/libs/google-oauth-client-extensions-1.5.0-beta.jar differ diff --git a/astrid/libs/gson-1.6.jar b/astrid/libs/gson-1.6.jar new file mode 100644 index 000000000..40648939f Binary files /dev/null and b/astrid/libs/gson-1.6.jar differ diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListService.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListService.java index 7b982bc12..8bd2100a4 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListService.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListService.java @@ -1,6 +1,9 @@ package com.todoroo.astrid.gtasks; -import com.google.api.services.tasks.v1.model.TaskLists; +import java.util.List; + +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; @@ -61,12 +64,11 @@ public class GtasksListService { public void migrateListIds (TaskLists remoteLists) { readLists(); - for (int i = 0; i < remoteLists.items.size(); i++) { - com.google.api.services.tasks.v1.model.TaskList remote = remoteLists.items.get(i); - + List items = remoteLists.getItems(); + for (TaskList remote : items) { for (StoreObject list : lists) { - if (list.getValue(GtasksList.NAME).equals(remote.title)) { - list.setValue(GtasksList.REMOTE_ID, remote.id); + if (list.getValue(GtasksList.NAME).equals(remote.getTitle())) { + list.setValue(GtasksList.REMOTE_ID, remote.getId()); storeObjectDao.persist(list); break; } @@ -81,10 +83,11 @@ public class GtasksListService { for(StoreObject list : lists) list.setValue(StoreObject.TYPE, ""); - for(int i = 0; i < remoteLists.items.size(); i++) { - com.google.api.services.tasks.v1.model.TaskList remote = remoteLists.items.get(i); + List items = remoteLists.getItems(); + for(int i = 0; i < items.size(); i++) { + com.google.api.services.tasks.model.TaskList remote = items.get(i); - String id = remote.id; + String id = remote.getId(); StoreObject local = null; for(StoreObject list : lists) { if(list.getValue(GtasksList.REMOTE_ID).equals(id)) { @@ -98,7 +101,7 @@ public class GtasksListService { local.setValue(StoreObject.TYPE, GtasksList.TYPE); local.setValue(GtasksList.REMOTE_ID, id); - local.setValue(GtasksList.NAME, remote.title); + local.setValue(GtasksList.NAME, remote.getTitle()); local.setValue(GtasksList.ORDER, i); storeObjectDao.persist(local); } @@ -111,20 +114,20 @@ public class GtasksListService { clearListCache(); } - public StoreObject addNewList(com.google.api.services.tasks.v1.model.TaskList newList) { + public StoreObject addNewList(com.google.api.services.tasks.model.TaskList newList) { readLists(); if (lists != null) { for (StoreObject list : lists) { - if (list.getValue(GtasksList.REMOTE_ID).equals(newList.id)) //Sanity check--make sure it's actually a new list + if (list.getValue(GtasksList.REMOTE_ID).equals(newList.getId())) //Sanity check--make sure it's actually a new list return null; } } StoreObject local = new StoreObject(); local.setValue(StoreObject.TYPE, GtasksList.TYPE); - local.setValue(GtasksList.REMOTE_ID, newList.id); - local.setValue(GtasksList.NAME, newList.title); + local.setValue(GtasksList.REMOTE_ID, newList.getId()); + local.setValue(GtasksList.NAME, newList.getTitle()); int order = lists == null ? 0 : lists.length; local.setValue(GtasksList.ORDER, order); diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/CreateRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/CreateRequest.java index 27e0cbc0f..2d922d24f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/CreateRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/CreateRequest.java @@ -2,7 +2,7 @@ package com.todoroo.astrid.gtasks.api; import java.io.IOException; -import com.google.api.services.tasks.v1.model.Task; +import com.google.api.services.tasks.model.Task; /** * Encapsulates a request to the api to create a task on the remote server * @author Sam Bosley diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksApiUtilities.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksApiUtilities.java index 6307ba92f..a1e75a839 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksApiUtilities.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksApiUtilities.java @@ -4,28 +4,38 @@ import java.util.Date; import java.util.TimeZone; import com.google.api.client.util.DateTime; -import com.google.api.services.tasks.v1.model.Task; +import com.google.api.services.tasks.model.Task; @SuppressWarnings("nls") public class GtasksApiUtilities { - public static String unixTimeToGtasksCompletionTime(long time) { + public static DateTime unixTimeToGtasksCompletionTime(long time) { if (time == 0) return null; - return new DateTime(new Date(time), TimeZone.getDefault()).toStringRfc3339(); + return new DateTime(new Date(time), TimeZone.getDefault()); } +// public static String unixTimeToGtasksCompletionTime(long time) { +// if (time == 0) return null; +// return new DateTime(new Date(time), TimeZone.getDefault()).toStringRfc3339(); +// } - public static long gtasksCompletedTimeToUnixTime(String gtasksCompletedTime, long defaultValue) { + + public static long gtasksCompletedTimeToUnixTime(DateTime gtasksCompletedTime, long defaultValue) { if (gtasksCompletedTime == null) return defaultValue; - try { - long utcTime = DateTime.parseRfc3339(gtasksCompletedTime).value; - Date date = new Date(utcTime); - return date.getTime(); - } catch (NumberFormatException e) { - return defaultValue; - } + return gtasksCompletedTime.getValue(); } +// public static long gtasksCompletedTimeToUnixTime(String gtasksCompletedTime, long defaultValue) { +// if (gtasksCompletedTime == null) return defaultValue; +// try { +// long utcTime = DateTime.parseRfc3339(gtasksCompletedTime).value; +// Date date = new Date(utcTime); +// return date.getTime(); +// } catch (NumberFormatException e) { +// return defaultValue; +// } +// } + /** * Google deals only in dates for due times, so on the server side they normalize to utc time * and then truncate h:m:s to 0. This can lead to a loss of date information for @@ -34,7 +44,7 @@ public class GtasksApiUtilities { * @param time * @return */ - public static String unixTimeToGtasksDueDate(long time) { + public static DateTime unixTimeToGtasksDueDate(long time) { if (time == 0) return null; Date date = new Date(time); date.setHours(0); @@ -42,14 +52,19 @@ public class GtasksApiUtilities { date.setSeconds(0); date.setTime(date.getTime() - date.getTimezoneOffset() * 60000); DateTime dateTime = new DateTime(date, TimeZone.getTimeZone("UTC")); - return dateTime.toStringRfc3339(); + return dateTime; } +// public static DateTime unixTimeToGtasksDueDate(long time) { +// if (time == 0) return null; +// return new DateTime(time, 0); +// } + //Adjust for google's rounding - public static long gtasksDueTimeToUnixTime(String gtasksDueTime, long defaultValue) { + public static long gtasksDueTimeToUnixTime(DateTime gtasksDueTime, long defaultValue) { if (gtasksDueTime == null) return defaultValue; try { - long utcTime = DateTime.parseRfc3339(gtasksDueTime).value; + long utcTime = gtasksDueTime.getValue(); //DateTime.parseRfc3339(gtasksDueTime).value; Date date = new Date(utcTime); Date returnDate = new Date(date.getTime() + date.getTimezoneOffset() * 60000); return returnDate.getTime(); @@ -58,8 +73,13 @@ public class GtasksApiUtilities { } } +// public static long gtasksDueTimeToUnixTime(DateTime gtasksDueTime, long defaultValue) { +// if (gtasksDueTime == null) return defaultValue; +// return gtasksDueTime.getValue(); +// } + public static String extractListIdFromSelfLink(Task task) { - String selfLink = task.selfLink; + String selfLink = task.getSelfLink(); String [] urlComponents = selfLink.split("/"); int listIdIndex = urlComponents.length - 3; return urlComponents[listIdIndex]; diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java index 91baa3a65..d79802f81 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java @@ -7,14 +7,16 @@ import android.content.Context; import com.google.api.client.extensions.android2.AndroidHttp; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; import com.google.api.client.http.HttpResponseException; -import com.google.api.client.json.jackson.JacksonFactory; -import com.google.api.services.tasks.v1.Tasks; -import com.google.api.services.tasks.v1.Tasks.TasksOperations.Insert; -import com.google.api.services.tasks.v1.Tasks.TasksOperations.List; -import com.google.api.services.tasks.v1.Tasks.TasksOperations.Move; -import com.google.api.services.tasks.v1.model.Task; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.gson.GsonFactory; +import com.google.api.client.util.DateTime; +import com.google.api.services.tasks.Tasks; +import com.google.api.services.tasks.Tasks.TasksOperations.Insert; +import com.google.api.services.tasks.Tasks.TasksOperations.List; +import com.google.api.services.tasks.Tasks.TasksOperations.Move; +import com.google.api.services.tasks.model.Task; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.timsu.astrid.R; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; @@ -33,6 +35,7 @@ public class GtasksService { private Tasks service; private GoogleAccessProtectedResource accessProtectedResource; private String token; + private JsonFactory jsonFactory; @Autowired ExceptionService exceptionService; @@ -49,8 +52,9 @@ public class GtasksService { this.token = authToken; accessProtectedResource = new GoogleAccessProtectedResource(authToken); - service = new Tasks(AndroidHttp.newCompatibleTransport(), accessProtectedResource, new JacksonFactory()); - service.accessKey = API_KEY; + jsonFactory = new GsonFactory(); + service = new Tasks(AndroidHttp.newCompatibleTransport(), accessProtectedResource, jsonFactory); + service.setKey(API_KEY); service.setApplicationName("Astrid"); } @@ -58,13 +62,14 @@ public class GtasksService { private synchronized void handleException(IOException e) throws IOException { if (e instanceof HttpResponseException) { HttpResponseException h = (HttpResponseException)e; - if (h.response.statusCode == 401 || h.response.statusCode == 403) { - System.err.println("Encountered " + h.response.statusCode + " error"); + int statusCode = h.getResponse().getStatusCode(); + if (statusCode == 401 || statusCode == 403) { + System.err.println("Encountered " + statusCode + " error"); token = GtasksTokenValidator.validateAuthToken(token); if (token != null) { accessProtectedResource.setAccessToken(token); } - } else if (h.response.statusCode == 503) { // 503 errors are generally either 1) quota limit reached or 2) problems on Google's end + } else if (statusCode == 503) { // 503 errors are generally either 1) quota limit reached or 2) problems on Google's end System.err.println("Encountered 503 error"); final Context context = ContextManager.getContext(); String message = context.getString(R.string.gtasks_error_backend); @@ -116,7 +121,7 @@ public class GtasksService { public TaskList createGtaskList(String title) throws IOException { TaskList newList = new TaskList(); - newList.title = title; + newList.setTitle(title); TaskList toReturn = null; try { toReturn = service.tasklists.insert(newList).execute(); @@ -132,12 +137,12 @@ public class GtasksService { public TaskList updateGtaskList(TaskList list) throws IOException { TaskList toReturn = null; try { - toReturn = service.tasklists.update(list.id, list).execute(); + toReturn = service.tasklists.update(list.getId(), list).execute(); } catch (IOException e) { handleException(e); - toReturn = service.tasklists.update(list.id, list).execute(); + toReturn = service.tasklists.update(list.getId(), list).execute(); } finally { - log("Update list, id: " + list.id, toReturn); + log("Update list, id: " + list.getId(), toReturn); } return toReturn; } @@ -153,15 +158,15 @@ public class GtasksService { } } - public com.google.api.services.tasks.v1.model.Tasks getAllGtasksFromTaskList(TaskList list, boolean includeDeleted, boolean includeHidden) throws IOException { - return getAllGtasksFromListId(list.id, includeDeleted, includeHidden); + public com.google.api.services.tasks.model.Tasks getAllGtasksFromTaskList(TaskList list, boolean includeDeleted, boolean includeHidden) throws IOException { + return getAllGtasksFromListId(list.getId(), includeDeleted, includeHidden); } - public com.google.api.services.tasks.v1.model.Tasks getAllGtasksFromListId(String listId, boolean includeDeleted, boolean includeHidden) throws IOException { - com.google.api.services.tasks.v1.model.Tasks toReturn = null; + public com.google.api.services.tasks.model.Tasks getAllGtasksFromListId(String listId, boolean includeDeleted, boolean includeHidden) throws IOException { + com.google.api.services.tasks.model.Tasks toReturn = null; List request = service.tasks.list(listId); - request.showDeleted = includeDeleted; - request.showHidden = includeHidden; + request.setShowDeleted(includeDeleted); + request.setShowHidden(includeHidden); try { toReturn = request.execute(); } catch (IOException e) { @@ -186,11 +191,11 @@ public class GtasksService { return toReturn; } - public Task createGtask(String listId, String title, String notes, String due) throws IOException { + public Task createGtask(String listId, String title, String notes, DateTime due) throws IOException { Task newGtask = new Task(); - newGtask.title = title; - newGtask.notes = notes; - newGtask.due = due; + newGtask.setTitle(title); + newGtask.setNotes(notes); + newGtask.setDue(due); return createGtask(listId, newGtask); } @@ -201,8 +206,8 @@ public class GtasksService { public Task createGtask(String listId, Task task, String parent, String priorSiblingId) throws IOException { Insert insertOp = service.tasks.insert(listId, task); - insertOp.parent = parent; - insertOp.previous = priorSiblingId; + insertOp.setParent(parent); + insertOp.setPrevious(priorSiblingId); Task toReturn = null; try { @@ -211,7 +216,7 @@ public class GtasksService { handleException(e); toReturn = insertOp.execute(); } finally { - log("Creating gtask, title: " + task.title, toReturn); + log("Creating gtask, title: " + task.getTitle(), toReturn); } return toReturn; } @@ -219,20 +224,20 @@ public class GtasksService { public Task updateGtask(String listId, Task task) throws IOException { Task toReturn = null; try { - toReturn = service.tasks.update(listId, task.id, task).execute(); + toReturn = service.tasks.update(listId, task.getId(), task).execute(); } catch (IOException e) { handleException(e); - toReturn = service.tasks.update(listId, task.id, task).execute(); + toReturn = service.tasks.update(listId, task.getId(), task).execute(); } finally { - log("Update gtask, title: " + task.title, toReturn); + log("Update gtask, title: " + task.getTitle(), toReturn); } return toReturn; } public Task moveGtask(String listId, String taskId, String parentId, String previousId) throws IOException { Move move = service.tasks.move(listId, taskId); - move.parent = parentId; - move.previous = previousId; + move.setParent(parentId); + move.setPrevious(previousId); Task toReturn = null; try { @@ -267,4 +272,8 @@ public class GtasksService { log("Clear completed tasks, list id: " + listId, null); } } + + public JsonFactory getJsonFactory() { + return jsonFactory; + } } diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java index be59cefe3..70016fe4b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java @@ -2,7 +2,7 @@ package com.todoroo.astrid.gtasks.api; import java.io.IOException; -import com.google.api.services.tasks.v1.model.Task; +import com.google.api.services.tasks.model.Task; /** * Encapsulates a request to the api to move a task from one list to another * @author Sam Bosley @@ -30,15 +30,15 @@ public class MoveListRequest extends PushRequest { } private void transferProperties(Task local) { - toPush.completed = local.completed; - toPush.deleted = local.deleted; - toPush.due = local.due; - toPush.hidden = local.hidden; - toPush.notes = local.notes; - toPush.status = local.status; - toPush.title = local.title; - - toPush.parent = newParent; + toPush.setCompleted(local.getCompleted()); + toPush.setDeleted(local.getDeleted()); + toPush.setDue(local.getDue()); + toPush.setHidden(local.getHidden()); + toPush.setNotes(local.getNotes()); + toPush.setStatus(local.getStatus()); + toPush.setTitle(local.getTitle()); + + toPush.setParent(newParent); } public String getIdTaskToMove() { diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveRequest.java index e6eb77fa3..6e3580902 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveRequest.java @@ -2,7 +2,7 @@ package com.todoroo.astrid.gtasks.api; import java.io.IOException; -import com.google.api.services.tasks.v1.model.Task; +import com.google.api.services.tasks.model.Task; /** * Encapsulates a request to the api to change the ordering on the given task * @author Sam Bosley diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/PushRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/PushRequest.java index 24dc68f7d..0d46e5a80 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/PushRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/PushRequest.java @@ -2,7 +2,7 @@ package com.todoroo.astrid.gtasks.api; import java.io.IOException; -import com.google.api.services.tasks.v1.model.Task; +import com.google.api.services.tasks.model.Task; /** * Abstract class that encapsulates some push request to the server diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java index 1f367cc5f..c25cc1cdf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java @@ -2,7 +2,7 @@ package com.todoroo.astrid.gtasks.api; import java.io.IOException; -import com.google.api.services.tasks.v1.model.Task; +import com.google.api.services.tasks.model.Task; /** * Encapsulates a request to the api to update a task on the remote server diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java index 3eced32f1..dbf3a0f59 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java @@ -2,9 +2,11 @@ package com.todoroo.astrid.gtasks.sync; import java.io.IOException; import java.util.HashMap; +import java.util.List; -import com.google.api.services.tasks.v1.model.TaskLists; -import com.google.api.services.tasks.v1.model.Tasks; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; +import com.google.api.services.tasks.model.Tasks; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; @@ -68,25 +70,27 @@ public class GtasksLegacyMigrator { //and map their titles to their real remote ids HashMap taskAndListTitlesToRemoteTaskIds = new HashMap(); - for (com.google.api.services.tasks.v1.model.TaskList list : allLists.items) { - if (list.title.equals(defaultListTitle)) { - defaultListId = list.id; + List items = allLists.getItems(); + for (TaskList list : items) { + if (list.getTitle().equals(defaultListTitle)) { + defaultListId = list.getId(); } - Tasks allTasks = gtasksService.getAllGtasksFromListId(list.id, false, false); + Tasks allTasks = gtasksService.getAllGtasksFromListId(list.getId(), false, false); - if (allTasks.items != null) { - for (com.google.api.services.tasks.v1.model.Task t : allTasks.items) { - System.err.println("Constructing key with title: " + t.title); - String key = constructKeyFromTitles(t.title, list.title); - taskAndListTitlesToRemoteTaskIds.put(key, t.id); + List tasksItems = allTasks.getItems(); + if (tasksItems != null) { + for (com.google.api.services.tasks.model.Task t : tasksItems) { + System.err.println("Constructing key with title: " + t.getTitle()); + String key = constructKeyFromTitles(t.getTitle(), list.getTitle()); + taskAndListTitlesToRemoteTaskIds.put(key, t.getId()); } } } if (defaultListId == null) { - com.google.api.services.tasks.v1.model.TaskList defaultList = gtasksService.getGtaskList("@default"); //$NON-NLS-1$ - defaultListId = defaultList.id; + com.google.api.services.tasks.model.TaskList defaultList = gtasksService.getGtaskList("@default"); //$NON-NLS-1$ + defaultListId = defaultList.getId(); } Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId); @@ -103,19 +107,20 @@ public class GtasksLegacyMigrator { //Search through lists to see if one of them has match String taskTitle = container.task.getValue(Task.TITLE); boolean foundMatch = false; - for (com.google.api.services.tasks.v1.model.TaskList list : allLists.items) { - String expectedKey = constructKeyFromTitles(taskTitle, list.title); + items = allLists.getItems(); + for (TaskList list : items) { + String expectedKey = constructKeyFromTitles(taskTitle, list.getTitle()); // save the new id of the current list // if it matches the listname of the current task - if (list.title != null && list.title.equals(originalListName)) - originalListId = list.id; + if (list.getTitle() != null && list.getTitle().equals(originalListName)) + originalListId = list.getId(); if (taskAndListTitlesToRemoteTaskIds.containsKey(expectedKey)) { System.err.println("Found match"); foundMatch = true; String newRemoteTaskId = taskAndListTitlesToRemoteTaskIds.get(expectedKey); - String newRemoteListId = list.id; + String newRemoteListId = list.getId(); container.gtaskMetadata.setValue(GtasksMetadata.ID, newRemoteTaskId); container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, newRemoteListId); diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncOnSaveService.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncOnSaveService.java index c572959b9..722be1d81 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncOnSaveService.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncOnSaveService.java @@ -153,7 +153,7 @@ public final class GtasksSyncOnSaveService { AndroidUtilities.sleepDeep(1000L); //Wait for metadata to be saved Metadata gtasksMetadata = gtasksMetadataService.getTaskMetadata(task.getId()); - com.google.api.services.tasks.v1.model.Task remoteModel = null; + com.google.api.services.tasks.model.Task remoteModel = null; boolean newlyCreated = false; //Initialize the gtasks api service @@ -168,7 +168,7 @@ public final class GtasksSyncOnSaveService { String remoteId = null; String listId = Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST); if (listId == null) { - listId = gtasksService.getGtaskList("@default").id; //$NON-NLS-1$ + listId = gtasksService.getGtaskList("@default").getId(); //$NON-NLS-1$ Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, listId); } @@ -181,7 +181,7 @@ public final class GtasksSyncOnSaveService { listId = gtasksMetadata.getValue(GtasksMetadata.LIST_ID); } - remoteModel = new com.google.api.services.tasks.v1.model.Task(); + remoteModel = new com.google.api.services.tasks.model.Task(); newlyCreated = true; } else { //update case remoteId = gtasksMetadata.getValue(GtasksMetadata.ID); @@ -198,25 +198,25 @@ public final class GtasksSyncOnSaveService { //Update the remote model's changed properties if (values.containsKey(Task.DELETION_DATE.name) && task.isDeleted()) { - remoteModel.deleted = true; + remoteModel.setDeleted(true); } if (values.containsKey(Task.TITLE.name)) { - remoteModel.title = task.getValue(Task.TITLE); + remoteModel.setTitle(task.getValue(Task.TITLE)); } if (values.containsKey(Task.NOTES.name)) { - remoteModel.notes = task.getValue(Task.NOTES); + remoteModel.setNotes(task.getValue(Task.NOTES)); } if (values.containsKey(Task.DUE_DATE.name)) { - remoteModel.due = GtasksApiUtilities.unixTimeToGtasksDueDate(task.getValue(Task.DUE_DATE)); + remoteModel.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(task.getValue(Task.DUE_DATE))); } if (values.containsKey(Task.COMPLETION_DATE.name)) { if (task.isCompleted()) { - remoteModel.completed = GtasksApiUtilities.unixTimeToGtasksCompletionTime(task.getValue(Task.COMPLETION_DATE)); - remoteModel.status = "completed"; //$NON-NLS-1$ + remoteModel.setCompleted(GtasksApiUtilities.unixTimeToGtasksCompletionTime(task.getValue(Task.COMPLETION_DATE))); + remoteModel.setStatus("completed"); //$NON-NLS-1$ } else { - remoteModel.completed = null; - remoteModel.status = "needsAction"; //$NON-NLS-1$ + remoteModel.setCompleted(null); + remoteModel.setStatus("needsAction"); //$NON-NLS-1$ } } @@ -228,8 +228,8 @@ public final class GtasksSyncOnSaveService { try { //Make sure the parent task exists on the target list if (parent != null) { - com.google.api.services.tasks.v1.model.Task remoteParent = gtasksService.getGtask(listId, parent); - if (remoteParent == null || (remoteParent.deleted != null && remoteParent.deleted)) + com.google.api.services.tasks.model.Task remoteParent = gtasksService.getGtask(listId, parent); + if (remoteParent == null || (remoteParent.getDeleted() != null && remoteParent.getDeleted().booleanValue())) parent = null; } } catch (IOException e) { @@ -238,8 +238,8 @@ public final class GtasksSyncOnSaveService { try { if (priorSibling != null) { - com.google.api.services.tasks.v1.model.Task remoteSibling = gtasksService.getGtask(listId, priorSibling); - if (remoteSibling == null || (remoteSibling.deleted != null && remoteSibling.deleted)) + com.google.api.services.tasks.model.Task remoteSibling = gtasksService.getGtask(listId, priorSibling); + if (remoteSibling == null || (remoteSibling.getDeleted() != null && remoteSibling.getDeleted().booleanValue())) priorSibling = null; } } catch (IOException e) { @@ -247,10 +247,10 @@ public final class GtasksSyncOnSaveService { } - com.google.api.services.tasks.v1.model.Task created = gtasksService.createGtask(listId, remoteModel, parent, priorSibling); + com.google.api.services.tasks.model.Task created = gtasksService.createGtask(listId, remoteModel, parent, priorSibling); //Update the metadata for the newly created task - gtasksMetadata.setValue(GtasksMetadata.ID, created.id); + gtasksMetadata.setValue(GtasksMetadata.ID, created.getId()); gtasksMetadata.setValue(GtasksMetadata.LIST_ID, listId); metadataService.save(gtasksMetadata); } @@ -279,8 +279,8 @@ public final class GtasksSyncOnSaveService { try { //Make sure the parent task exists on the target list if (parent != null) { - com.google.api.services.tasks.v1.model.Task remoteParent = gtasksService.getGtask(listId, parent); - if (remoteParent == null || (remoteParent.deleted != null && remoteParent.deleted)) + com.google.api.services.tasks.model.Task remoteParent = gtasksService.getGtask(listId, parent); + if (remoteParent == null || (remoteParent.getDeleted() != null && remoteParent.getDeleted().booleanValue())) parent = null; } } catch (IOException e) { @@ -289,8 +289,8 @@ public final class GtasksSyncOnSaveService { try { if (priorSibling != null) { - com.google.api.services.tasks.v1.model.Task remoteSibling = gtasksService.getGtask(listId, priorSibling); - if (remoteSibling == null || (remoteSibling.deleted != null && remoteSibling.deleted)) + com.google.api.services.tasks.model.Task remoteSibling = gtasksService.getGtask(listId, priorSibling); + if (remoteSibling == null || (remoteSibling.getDeleted() != null && remoteSibling.getDeleted().booleanValue())) priorSibling = null; } } catch (IOException e) { diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java index 6fc70f3c4..dc46d011d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java @@ -23,8 +23,8 @@ import android.content.Intent; import android.text.TextUtils; import android.util.Log; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.timsu.astrid.R; import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.Property; @@ -225,15 +225,15 @@ public class GtasksSyncProvider extends SyncProvider { private void getActiveList(TaskLists taskView) throws IOException { String listId; - if(taskView.items.size() == 0) { + if(taskView.getItems().size() == 0) { if(Constants.DEBUG) Log.e("gtasks-debug", "ACTION: createList(4)"); TaskList newList = taskService.createGtaskList(ContextManager.getString(R.string.app_name)); - listId = newList.id; + listId = newList.getId(); } else if (Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST) != null) { listId = Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST); } else { - listId = taskService.getGtaskList("@default").id; + listId = taskService.getGtaskList("@default").getId(); } Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, listId); @@ -345,7 +345,7 @@ public class GtasksSyncProvider extends SyncProvider { String listId = dashboard.getValue(GtasksList.REMOTE_ID); if(Constants.DEBUG) Log.e("gtasks-debug", "ACTION: getTasks, " + listId); - List remoteTasks = taskService.getAllGtasksFromListId(listId, includeDeleted, includeHidden).items; + List remoteTasks = taskService.getAllGtasksFromListId(listId, includeDeleted, includeHidden).getItems(); addRemoteTasksToList(remoteTasks, list); } catch (Exception e) { handleException("read-remotes", e, false); @@ -364,31 +364,31 @@ public class GtasksSyncProvider extends SyncProvider { return list; } - private void addRemoteTasksToList(List remoteTasks, + private void addRemoteTasksToList(List remoteTasks, ArrayList list) { if (remoteTasks != null) { long order = 0; - HashMap idsToTasks = new HashMap(); + HashMap idsToTasks = new HashMap(); HashMap indentation = new HashMap(); HashMap parentToPriorSiblingMap = new HashMap(); //Build map of String ids to task objects - for (com.google.api.services.tasks.v1.model.Task task : remoteTasks) { - String id = task.id; + for (com.google.api.services.tasks.model.Task task : remoteTasks) { + String id = task.getId(); idsToTasks.put(id, task); } - for(com.google.api.services.tasks.v1.model.Task remoteTask : remoteTasks) { - if(TextUtils.isEmpty(remoteTask.title)) + for(com.google.api.services.tasks.model.Task remoteTask : remoteTasks) { + if(TextUtils.isEmpty(remoteTask.getTitle())) continue; GtasksTaskContainer container = parseRemoteTask(remoteTask); - String id = remoteTask.id; + String id = remoteTask.getId(); // update parents, prior sibling - String parent = remoteTask.parent; // can be null, which means top level task + String parent = remoteTask.getParent(); // can be null, which means top level task container.parentId = parent; if(parentToPriorSiblingMap.containsKey(parent)) container.priorSiblingId = parentToPriorSiblingMap.get(parent); @@ -412,16 +412,16 @@ public class GtasksSyncProvider extends SyncProvider { } } - private int findIndentation(HashMap idsToTasks, - HashMap indentation, com.google.api.services.tasks.v1.model.Task task) { + private int findIndentation(HashMap idsToTasks, + HashMap indentation, com.google.api.services.tasks.model.Task task) { if (task == null) return 0; //TODO: Not sure why this is happening... - if(indentation.containsKey(task.id)) - return indentation.get(task.id); + if(indentation.containsKey(task.getId())) + return indentation.get(task.getId()); - if(TextUtils.isEmpty(task.parent)) + if(TextUtils.isEmpty(task.getParent())) return 0; - return findIndentation(idsToTasks, indentation, idsToTasks.get(task.parent)) + 1; + return findIndentation(idsToTasks, indentation, idsToTasks.get(task.getParent())) + 1; } @Override @@ -435,34 +435,33 @@ public class GtasksSyncProvider extends SyncProvider { createdWithoutId.add(local); createdWithoutOrder.add(local); - - com.google.api.services.tasks.v1.model.Task createdTask = new com.google.api.services.tasks.v1.model.Task(); + com.google.api.services.tasks.model.Task createdTask = new com.google.api.services.tasks.model.Task(); CreateRequest createRequest = new CreateRequest(taskService, listId, createdTask, local.parentId, local.priorSiblingId); //updateTaskHelper(local, null, createRequest); localPropertiesToModel(local, null, createRequest.getToPush()); - com.google.api.services.tasks.v1.model.Task createResult = createRequest.executePush(); - String newIdTask = createResult.id; + com.google.api.services.tasks.model.Task createResult = createRequest.executePush(); + String newIdTask = createResult.getId(); local.gtaskMetadata.setValue(GtasksMetadata.ID, newIdTask); return local; }//*/ private void localPropertiesToModel(GtasksTaskContainer local, GtasksTaskContainer remote, - com.google.api.services.tasks.v1.model.Task model) { + com.google.api.services.tasks.model.Task model) { if(shouldTransmit(local, Task.TITLE, remote)) - model.title = local.task.getValue(Task.TITLE); + model.setTitle(local.task.getValue(Task.TITLE)); if(shouldTransmit(local, Task.DUE_DATE, remote)) { - model.due = GtasksApiUtilities.unixTimeToGtasksDueDate(local.task.getValue(Task.DUE_DATE)); + model.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(local.task.getValue(Task.DUE_DATE))); } if(shouldTransmit(local, Task.COMPLETION_DATE, remote)) { - model.completed = GtasksApiUtilities.unixTimeToGtasksCompletionTime(local.task.getValue(Task.COMPLETION_DATE)); - model.status = (local.task.isCompleted() ? "completed" : "needsAction"); + model.setCompleted(GtasksApiUtilities.unixTimeToGtasksCompletionTime(local.task.getValue(Task.COMPLETION_DATE))); + model.setStatus((local.task.isCompleted() ? "completed" : "needsAction")); } if(shouldTransmit(local, Task.DELETION_DATE, remote)) - model.deleted = local.task.isDeleted(); + model.setDeleted(local.task.isDeleted()); if(shouldTransmit(local, Task.NOTES, remote)) - model.notes = local.task.getValue(Task.NOTES); + model.setNotes(local.task.getValue(Task.NOTES)); } private void updateTaskHelper(final GtasksTaskContainer local, @@ -517,9 +516,9 @@ public class GtasksSyncProvider extends SyncProvider { Log.e("gtasks-debug", "ACTION: moveTask(5), " + newIdTask + ", " + idList + " to " + remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID)); MoveListRequest moveList = new MoveListRequest(taskService, newIdTask, remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), idList, null); - com.google.api.services.tasks.v1.model.Task result = moveList.executePush(); - local.gtaskMetadata.setValue(GtasksMetadata.ID, result.id); - remote.gtaskMetadata.setValue(GtasksMetadata.ID, result.id); + com.google.api.services.tasks.model.Task result = moveList.executePush(); + local.gtaskMetadata.setValue(GtasksMetadata.ID, result.getId()); + remote.gtaskMetadata.setValue(GtasksMetadata.ID, result.getId()); } } catch (IOException e) { handleException("update-task", e, false); @@ -536,28 +535,28 @@ public class GtasksSyncProvider extends SyncProvider { /** Create a task container for the given remote task * @throws JSONException */ - private GtasksTaskContainer parseRemoteTask(com.google.api.services.tasks.v1.model.Task remoteTask) { + private GtasksTaskContainer parseRemoteTask(com.google.api.services.tasks.model.Task remoteTask) { Task task = new Task(); ArrayList metadata = new ArrayList(); - task.setValue(Task.TITLE, remoteTask.title); + task.setValue(Task.TITLE, remoteTask.getTitle()); task.setValue(Task.CREATION_DATE, DateUtilities.now()); - task.setValue(Task.COMPLETION_DATE, GtasksApiUtilities.gtasksCompletedTimeToUnixTime(remoteTask.completed, 0)); - if (remoteTask.deleted == null || !remoteTask.deleted.booleanValue()) + task.setValue(Task.COMPLETION_DATE, GtasksApiUtilities.gtasksCompletedTimeToUnixTime(remoteTask.getCompleted(), 0)); + if (remoteTask.getDeleted() == null || !remoteTask.getDeleted().booleanValue()) task.setValue(Task.DELETION_DATE, 0L); - else if (remoteTask.deleted.booleanValue()) + else if (remoteTask.getDeleted().booleanValue()) task.setValue(Task.DELETION_DATE, DateUtilities.now()); - if (remoteTask.hidden != null && remoteTask.hidden.booleanValue()) + if (remoteTask.getHidden() != null && remoteTask.getHidden().booleanValue()) task.setValue(Task.DELETION_DATE, DateUtilities.now()); - long dueDate = GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0); + long dueDate = GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0); long createdDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate); task.setValue(Task.DUE_DATE, createdDate); - task.setValue(Task.NOTES, remoteTask.notes); + task.setValue(Task.NOTES, remoteTask.getNotes()); Metadata gtasksMetadata = GtasksMetadata.createEmptyMetadata(AbstractModel.NO_ID); - gtasksMetadata.setValue(GtasksMetadata.ID, remoteTask.id); + gtasksMetadata.setValue(GtasksMetadata.ID, remoteTask.getId()); gtasksMetadata.setValue(GtasksMetadata.LIST_ID, GtasksApiUtilities.extractListIdFromSelfLink(remoteTask)); GtasksTaskContainer container = new GtasksTaskContainer(task, metadata, @@ -585,7 +584,7 @@ public class GtasksSyncProvider extends SyncProvider { if(Constants.DEBUG) Log.e("gtasks-debug", "ACTION: modifyTask(3) - " + id); - com.google.api.services.tasks.v1.model.Task toUpdate = taskService.getGtask(local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), id); + com.google.api.services.tasks.model.Task toUpdate = taskService.getGtask(local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), id); UpdateRequest modifyTask = new UpdateRequest(taskService, local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), toUpdate); updateTaskHelper(local, remote, modifyTask); diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksApiTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksApiTest.java index 15d4cef5c..3c3708e34 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksApiTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksApiTest.java @@ -1,6 +1,7 @@ package com.todoroo.astrid.gtasks; import java.util.Date; +import java.util.List; import android.accounts.Account; import android.accounts.AccountManager; @@ -9,10 +10,11 @@ import android.content.Intent; import android.os.Bundle; import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager; -import com.google.api.services.tasks.v1.model.Task; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; -import com.google.api.services.tasks.v1.model.Tasks; +import com.google.api.client.util.DateTime; +import com.google.api.services.tasks.model.Task; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; +import com.google.api.services.tasks.model.Tasks; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; @@ -34,8 +36,9 @@ public class GtasksApiTest extends DatabaseTestCase { public void testCreateTask() throws Exception { if(bypassTests) return; Task newTask = new Task(); - String title = newTask.title = "New task"; - + String title = "New task"; + newTask.setTitle(title); + service.createGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title)); } @@ -43,12 +46,14 @@ public class GtasksApiTest extends DatabaseTestCase { public void testUpdateTaskProperties() throws Exception { if(bypassTests) return; Task newTask = new Task(); - String title = newTask.title = "This title will change"; + String title = "This title will change"; + newTask.setTitle(title); newTask = service.createGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title)); - String title2 = newTask.title = "Changed Title"; + String title2 = "Changed Title"; + newTask.setTitle(title2); service.updateGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title2)); assertFalse(taskWithTitleExists(title)); @@ -56,69 +61,75 @@ public class GtasksApiTest extends DatabaseTestCase { public void testTaskDateFormatting2() throws Exception { Task newTask = new Task(); - String title = newTask.title = "Due date will change"; + String title = "Due date will change"; + newTask.setTitle(title); newTask = service.createGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title)); - newTask = service.getGtask(DEFAULT_LIST, newTask.id); - System.err.println("Newtask A: " + newTask.due); + newTask = service.getGtask(DEFAULT_LIST, newTask.getId()); + System.err.println("Newtask A: " + newTask.getDue()); long now = DateUtilities.now(); - newTask.due = GtasksApiUtilities.unixTimeToGtasksDueDate(now); - System.err.println("Newtask B: " + newTask.due); + newTask.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(now)); + System.err.println("Newtask B: " + newTask.getDue()); newTask = service.updateGtask(DEFAULT_LIST, newTask); - System.err.println("Newtask C: " + newTask.due); + System.err.println("Newtask C: " + newTask.getDue()); long complete = now + DateUtilities.ONE_DAY; - newTask.completed = GtasksApiUtilities.unixTimeToGtasksCompletionTime(complete); - System.err.println("Newtask D: " + newTask.completed); - newTask.status = "completed"; + newTask.setCompleted(GtasksApiUtilities.unixTimeToGtasksCompletionTime(complete)); + System.err.println("Newtask D: " + newTask.getCompleted()); + newTask.setStatus("completed"); newTask = service.updateGtask(DEFAULT_LIST, newTask); - System.err.println("Newtask E: " + newTask.completed); + System.err.println("Newtask E: " + newTask.getCompleted()); } public void testTaskDateFormatting() throws Exception { if(bypassTests) return; Task newTask = new Task(); - String title = newTask.title = "Due date will change"; + String title = "Due date will change"; + newTask.setTitle(title); newTask = service.createGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title)); long dueTime = new Date(114, 1, 13).getTime(); - String dueTimeString = GtasksApiUtilities.unixTimeToGtasksDueDate(dueTime); - newTask.due = dueTimeString; + DateTime dueTimeString = GtasksApiUtilities.unixTimeToGtasksDueDate(dueTime); + newTask.setDue(dueTimeString); newTask = service.updateGtask(DEFAULT_LIST, newTask); //assertEquals(dueTimeString, GtasksApiUtilities.gtasksDueTimeStringToLocalTimeString(newTask.due)); - assertEquals(dueTime, GtasksApiUtilities.gtasksDueTimeToUnixTime(newTask.due, 0)); + assertEquals(dueTime, GtasksApiUtilities.gtasksDueTimeToUnixTime(newTask.getDue(), 0)); long compTime = new Date(115, 2, 14).getTime(); - String compTimeString = GtasksApiUtilities.unixTimeToGtasksCompletionTime(compTime); - newTask.completed = compTimeString; - newTask.status = "completed"; + DateTime compTimeString = GtasksApiUtilities.unixTimeToGtasksCompletionTime(compTime); + newTask.setCompleted(compTimeString); + newTask.setStatus("completed"); newTask = service.updateGtask(DEFAULT_LIST, newTask); //assertEquals(compTimeString, GtasksApiUtilities.gtasksCompletedTimeStringToLocalTimeString(newTask.completed)); - assertEquals(compTime, GtasksApiUtilities.gtasksCompletedTimeToUnixTime(newTask.completed, 0)); + assertEquals(compTime, GtasksApiUtilities.gtasksCompletedTimeToUnixTime(newTask.getCompleted(), 0)); } public void testTaskDeleted() throws Exception { if(bypassTests) return; Task newTask = new Task(); - String title = newTask.title = "This task will be deleted"; + String title = "This task will be deleted"; + newTask.setTitle(title); newTask = service.createGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title)); - service.deleteGtask(DEFAULT_LIST, newTask.id); + service.deleteGtask(DEFAULT_LIST, newTask.getId()); assertFalse(taskWithTitleExists(title)); } public void testTaskMoved() throws Exception { if(bypassTests) return; Task newTask1 = new Task(); - String title1 = newTask1.title = "Task 1"; + String title1 = "Task 1"; + newTask1.setTitle(title1); + Task newTask2 = new Task(); - String title2 = newTask2.title = "Task 2"; + String title2 = "Task 2"; + newTask2.setTitle(title2); newTask1 = service.createGtask(DEFAULT_LIST, newTask1); newTask2 = service.createGtask(DEFAULT_LIST, newTask2); @@ -126,27 +137,28 @@ public class GtasksApiTest extends DatabaseTestCase { assertTrue(taskWithTitleExists(title1)); assertTrue(taskWithTitleExists(title2)); - System.err.println("Task 1 id: " + newTask1.id); - System.err.println("Task 2 id: " + newTask2.id); + System.err.println("Task 1 id: " + newTask1.getId()); + System.err.println("Task 2 id: " + newTask2.getId()); - service.moveGtask(DEFAULT_LIST, newTask1.id, newTask2.id, null); - newTask1 = service.getGtask(DEFAULT_LIST, newTask1.id); - newTask2 = service.getGtask(DEFAULT_LIST, newTask2.id); + service.moveGtask(DEFAULT_LIST, newTask1.getId(), newTask2.getId(), null); + newTask1 = service.getGtask(DEFAULT_LIST, newTask1.getId()); + newTask2 = service.getGtask(DEFAULT_LIST, newTask2.getId()); - assertEquals(newTask1.parent, newTask2.id); + assertEquals(newTask1.getParent(), newTask2.getId()); - service.moveGtask(DEFAULT_LIST, newTask1.id, null, newTask2.id); - newTask1 = service.getGtask(DEFAULT_LIST, newTask1.id); - newTask2 = service.getGtask(DEFAULT_LIST, newTask2.id); + service.moveGtask(DEFAULT_LIST, newTask1.getId(), null, newTask2.getId()); + newTask1 = service.getGtask(DEFAULT_LIST, newTask1.getId()); + newTask2 = service.getGtask(DEFAULT_LIST, newTask2.getId()); - assertNull(newTask1.parent); - assertTrue(newTask2.position.compareTo(newTask1.position) < 0); + assertNull(newTask1.getParent()); + assertTrue(newTask2.getPosition().compareTo(newTask1.getPosition()) < 0); } public void testMoveBetweenLists() throws Exception { if(bypassTests) return; Task newTask = new Task(); - String title = newTask.title = "This task will move lists"; + String title = "This task will move lists"; + newTask.setTitle(title); newTask = service.createGtask(DEFAULT_LIST, newTask); assertTrue(taskWithTitleExists(title)); @@ -157,18 +169,19 @@ public class GtasksApiTest extends DatabaseTestCase { assertNotNull(newList = listWithTitle(listTitle)); - MoveListRequest moveTask = new MoveListRequest(service, newTask.id, DEFAULT_LIST, newList.id, null); + MoveListRequest moveTask = new MoveListRequest(service, newTask.getId(), DEFAULT_LIST, newList.getId(), null); moveTask.executePush(); assertFalse(taskWithTitleExists(title)); - assertTrue(listHasTaskWithTitle(newList.id, title)); + assertTrue(listHasTaskWithTitle(newList.getId(), title)); } private boolean listHasTaskWithTitle(String listId, String title) throws Exception { - com.google.api.services.tasks.v1.model.Tasks newListTasks = service.getAllGtasksFromListId(listId, false, false); - if (newListTasks.items != null) { - for (Task t : newListTasks.items) { - if (t.title.equals(title)) { + com.google.api.services.tasks.model.Tasks newListTasks = service.getAllGtasksFromListId(listId, false, false); + List items = newListTasks.getItems(); + if (items != null) { + for (Task t : items) { + if (t.getTitle().equals(title)) { return true; } } @@ -178,9 +191,10 @@ public class GtasksApiTest extends DatabaseTestCase { private boolean taskWithTitleExists(String title) throws Exception { Tasks defaultList = service.getAllGtasksFromListId(DEFAULT_LIST, false, false); - if (defaultList.items != null) { - for (Task t : defaultList.items) { - if (t.title.equals(title)) + List items = defaultList.getItems(); + if (items != null) { + for (Task t : items) { + if (t.getTitle().equals(title)) return true; } } @@ -205,7 +219,7 @@ public class GtasksApiTest extends DatabaseTestCase { TaskList t = service.createGtaskList(title); assertNotNull(listWithTitle(title)); - service.deleteGtaskList(t.id); + service.deleteGtaskList(t.getId()); assertNull(listWithTitle(title)); } @@ -215,7 +229,8 @@ public class GtasksApiTest extends DatabaseTestCase { TaskList t = service.createGtaskList(title1); assertNotNull(listWithTitle(title1)); - String title2 = t.title = "New title"; + String title2 = "New title"; + t.setTitle(title2); service.updateGtaskList(t); assertNotNull(listWithTitle(title2)); assertNull(listWithTitle(title1)); @@ -223,8 +238,9 @@ public class GtasksApiTest extends DatabaseTestCase { private TaskList listWithTitle(String title) throws Exception { TaskLists allLists = service.allGtaskLists(); - for (TaskList t : allLists.items) { - if (t.title.equals(title)) + List items = allLists.getItems(); + for (TaskList t : items) { + if (t.getTitle().equals(title)) return t; } return null; @@ -276,9 +292,10 @@ public class GtasksApiTest extends DatabaseTestCase { private void deleteAllLists() { try { TaskLists allLists = service.allGtaskLists(); - for (TaskList t : allLists.items) { - if (!t.title.equals("Default List")) - service.deleteGtaskList(t.id); + List items = allLists.getItems(); + for (TaskList t : items) { + if (!t.getTitle().equals("Default List")) + service.deleteGtaskList(t.getId()); } } catch (Exception e) { e.printStackTrace(); @@ -289,9 +306,10 @@ public class GtasksApiTest extends DatabaseTestCase { private void clearDefaultList() { try { Tasks tasks = service.getAllGtasksFromListId(DEFAULT_LIST, false, false); - if (tasks.items != null) { - for (Task t : tasks.items) { - service.deleteGtask(DEFAULT_LIST, t.id); + List items = tasks.getItems(); + if (items != null) { + for (Task t : items) { + service.deleteGtask(DEFAULT_LIST, t.getId()); } } } catch (Exception e) { diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java index e6e4d05f9..2526be1fb 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java @@ -8,8 +8,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.api.AstridApiConstants; @@ -93,14 +93,14 @@ public class GtasksDetailExposerTest extends DatabaseTestCase { TaskLists lists = new TaskLists(); List newLists = new ArrayList(); TaskList list = new TaskList(); - list.id = "listone-id"; - list.title = "List One"; //new GoogleTaskListInfo("listone-id", "List One"); + list.setId("listone-id"); + list.setTitle("List One"); //new GoogleTaskListInfo("listone-id", "List One"); newLists.add(list); list = new TaskList(); - list.id = "listtwo-id"; - list.title = "List Two"; //("listtwo-id", "List Two"); + list.setId("listtwo-id"); + list.setTitle("List Two"); //("listtwo-id", "List Two"); newLists.add(list); - lists.items = newLists; + lists.setItems(newLists); gtasksListService.updateLists(lists); } diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java index bd345d5bc..293b40af2 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java @@ -3,8 +3,8 @@ package com.todoroo.astrid.gtasks; import java.util.ArrayList; import java.util.List; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.todoroo.andlib.service.Autowired; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; @@ -132,10 +132,10 @@ public class GtasksIndentActionTest extends DatabaseTestCase { TaskLists lists = new TaskLists(); List items = new ArrayList(); TaskList list = new TaskList(); - list.id = "list"; - list.title = "Test Tasks"; + list.setId("list"); + list.setTitle("Test Tasks"); items.add(list); - lists.items = items; + lists.setItems(items); gtasksListService.updateLists(lists); } diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksNewSyncTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksNewSyncTest.java index 8ecd30757..dfa4d02ff 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksNewSyncTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksNewSyncTest.java @@ -1,6 +1,7 @@ package com.todoroo.astrid.gtasks; import java.util.Date; +import java.util.List; import android.accounts.Account; import android.accounts.AccountManager; @@ -9,7 +10,7 @@ import android.content.Intent; import android.os.Bundle; import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager; -import com.google.api.services.tasks.v1.model.Tasks; +import com.google.api.services.tasks.model.Tasks; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; @@ -61,8 +62,8 @@ public class GtasksNewSyncTest extends DatabaseTestCase { public void testTaskCreatedRemotely() throws Exception { if(bypassTests) return; String title = "Gtasks task 1"; - com.google.api.services.tasks.v1.model.Task remoteTask = new com.google.api.services.tasks.v1.model.Task(); - remoteTask.title = title; + com.google.api.services.tasks.model.Task remoteTask = new com.google.api.services.tasks.model.Task(); + remoteTask.setTitle(title); remoteTask = gtasksService.createGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -80,7 +81,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); //Set new title on local task @@ -94,7 +95,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newTitle, localTask.getValue(Task.TITLE)); - assertEquals(newTitle, remoteTask.title); + assertEquals(newTitle, remoteTask.getTitle()); } public void testTitleChangedRemotely() throws Exception { @@ -104,12 +105,12 @@ public class GtasksNewSyncTest extends DatabaseTestCase { whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); //Set new title on remote task String newRemoteTitle = "Task 3 edited on gtasks"; - remoteTask.title = newRemoteTitle; + remoteTask.setTitle(newRemoteTitle); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -117,7 +118,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { //Refetch local/remote tasks, assert that both titles match expected remoteTask = refetchRemoteTask(remoteTask); localTask = refetchLocalTask(localTask); - assertEquals(newRemoteTitle, remoteTask.title); + assertEquals(newRemoteTitle, remoteTask.getTitle()); assertEquals(newRemoteTitle, localTask.getValue(Task.TITLE)); } @@ -128,11 +129,11 @@ public class GtasksNewSyncTest extends DatabaseTestCase { long startDate = localTask.getValue(Task.DUE_DATE); whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); localTask = refetchLocalTask(localTask); assertTrue(String.format("Expected %s, was %s", new Date(startDate), new Date(localTask.getValue(Task.DUE_DATE))), Math.abs(startDate - localTask.getValue(Task.DUE_DATE)) < 5000); - assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); //Set new due date on local task @@ -146,7 +147,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newDueDate, localTask.getValue(Task.DUE_DATE).longValue()); - assertEquals(newDueDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(newDueDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); } public void testDateChangedRemotely() throws Exception { @@ -156,16 +157,16 @@ public class GtasksNewSyncTest extends DatabaseTestCase { long startDate = localTask.getValue(Task.DUE_DATE); whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); localTask = refetchLocalTask(localTask); assertTrue(String.format("Expected %s, was %s", new Date(startDate), new Date(localTask.getValue(Task.DUE_DATE))), Math.abs(startDate - localTask.getValue(Task.DUE_DATE)) < 5000); - assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); //Set new due date on remote task long newDueDate = new Date(116, 1, 8).getTime(); - remoteTask.due = GtasksApiUtilities.unixTimeToGtasksDueDate(newDueDate); + remoteTask.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(newDueDate)); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -174,7 +175,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newDueDate, localTask.getValue(Task.DUE_DATE).longValue()); - assertEquals(newDueDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(newDueDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); } @@ -185,18 +186,18 @@ public class GtasksNewSyncTest extends DatabaseTestCase { long startDate = localTask.getValue(Task.DUE_DATE); whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); localTask = refetchLocalTask(localTask); assertTrue(String.format("Expected %s, was %s", new Date(startDate), new Date(localTask.getValue(Task.DUE_DATE))), Math.abs(startDate - localTask.getValue(Task.DUE_DATE)) < 5000); - assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); //Set new due date on remote task first long newLocalDate = new Date(128, 5, 11).getTime(); long newRemoteDate = new Date(121, 5, 25).getTime(); - remoteTask.due = GtasksApiUtilities.unixTimeToGtasksDueDate(newRemoteDate); + remoteTask.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(newRemoteDate)); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); @@ -210,7 +211,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newLocalDate, localTask.getValue(Task.DUE_DATE).longValue()); - assertEquals(newLocalDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(newLocalDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); } public void DISABLED_testDateChangedBoth_ChooseRemote() throws Exception { @@ -220,11 +221,11 @@ public class GtasksNewSyncTest extends DatabaseTestCase { long startDate = localTask.getValue(Task.DUE_DATE); whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); localTask = refetchLocalTask(localTask); assertTrue(String.format("Expected %s, was %s", new Date(startDate), new Date(localTask.getValue(Task.DUE_DATE))), Math.abs(startDate - localTask.getValue(Task.DUE_DATE)) < 5000); - assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(startDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); @@ -237,7 +238,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); - remoteTask.due = GtasksApiUtilities.unixTimeToGtasksDueDate(newRemoteDate); + remoteTask.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(newRemoteDate)); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -246,7 +247,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newLocalDate, localTask.getValue(Task.DUE_DATE).longValue()); - assertEquals(newLocalDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + assertEquals(newLocalDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); } /* @@ -269,9 +270,9 @@ public class GtasksNewSyncTest extends DatabaseTestCase { whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); assertEquals(originalNote, localTask.getValue(Task.NOTES)); - assertEquals(originalNote, remoteTask.notes); + assertEquals(originalNote, remoteTask.getNotes()); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); @@ -284,7 +285,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newNote, localTask.getValue(Task.NOTES)); - assertEquals(newNote, remoteTask.notes); + assertEquals(newNote, remoteTask.getNotes()); } public void testNoteEditedRemotely() throws Exception { @@ -295,14 +296,14 @@ public class GtasksNewSyncTest extends DatabaseTestCase { whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); assertEquals(originalNote, localTask.getValue(Task.NOTES)); - assertEquals(originalNote, remoteTask.notes); + assertEquals(originalNote, remoteTask.getNotes()); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); String newNote = "New remote note"; - remoteTask.notes = newNote; + remoteTask.setNotes(newNote); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -310,7 +311,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); assertEquals(newNote, localTask.getValue(Task.NOTES)); - assertEquals(newNote, remoteTask.notes); + assertEquals(newNote, remoteTask.getNotes()); } public void DISABLED_testNoteEditedBoth() throws Exception { @@ -321,9 +322,9 @@ public class GtasksNewSyncTest extends DatabaseTestCase { whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); assertEquals(originalNote, localTask.getValue(Task.NOTES)); - assertEquals(originalNote, remoteTask.notes); + assertEquals(originalNote, remoteTask.getNotes()); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); @@ -335,7 +336,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); - remoteTask.notes = newRemoteNote; + remoteTask.setNotes(newRemoteNote); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -343,7 +344,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { localTask = refetchLocalTask(localTask); remoteTask = refetchRemoteTask(remoteTask); System.err.println("Local note: " + localTask.getValue(Task.NOTES)); - System.err.println("Remote note: " + remoteTask.notes); + System.err.println("Remote note: " + remoteTask.getNotes()); } private Task createLocalTaskForNoteTests(String addToTitle) { @@ -365,7 +366,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { Task localTask = createNewLocalTask(title); whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); @@ -379,7 +380,7 @@ public class GtasksNewSyncTest extends DatabaseTestCase { remoteTask = refetchRemoteTask(remoteTask); assertTrue(String.format("Expected %s, was %s", new Date(completion), new Date(localTask.getValue(Task.COMPLETION_DATE))), Math.abs(completion - localTask.getValue(Task.COMPLETION_DATE)) < 5000); - assertEquals("completed", remoteTask.status); + assertEquals("completed", remoteTask.getStatus()); } public void testTaskCompletedRemotely() throws Exception { @@ -388,13 +389,13 @@ public class GtasksNewSyncTest extends DatabaseTestCase { Task localTask = createNewLocalTask(title); whenInvokeSync(); - com.google.api.services.tasks.v1.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); + com.google.api.services.tasks.model.Task remoteTask = assertTaskExistsRemotely(localTask, title); AndroidUtilities.sleepDeep(TIME_BETWEEN_SYNCS); long completion = DateUtilities.now(); - remoteTask.status = "completed"; - remoteTask.completed = GtasksApiUtilities.unixTimeToGtasksCompletionTime(completion); + remoteTask.setStatus("completed"); + remoteTask.setCompleted(GtasksApiUtilities.unixTimeToGtasksCompletionTime(completion)); gtasksService.updateGtask(DEFAULT_LIST, remoteTask); whenInvokeSync(); @@ -403,17 +404,17 @@ public class GtasksNewSyncTest extends DatabaseTestCase { remoteTask = refetchRemoteTask(remoteTask); assertTrue(String.format("Expected %s, was %s", new Date(completion), new Date(localTask.getValue(Task.COMPLETION_DATE))), Math.abs(completion - localTask.getValue(Task.COMPLETION_DATE)) < 5000); - assertEquals("completed", remoteTask.status); + assertEquals("completed", remoteTask.getStatus()); } - private com.google.api.services.tasks.v1.model.Task assertTaskExistsRemotely(Task localTask, String title) { + private com.google.api.services.tasks.model.Task assertTaskExistsRemotely(Task localTask, String title) { //Get the corresponding remote id for a local task Metadata metadata = gtasksMetadataService.getTaskMetadata(localTask.getId()); String taskId = metadata.getValue(GtasksMetadata.ID); String listId = metadata.getValue(GtasksMetadata.LIST_ID); //Fetch the remote task belonging to that id - com.google.api.services.tasks.v1.model.Task remoteTask = null; + com.google.api.services.tasks.model.Task remoteTask = null; try { remoteTask = gtasksService.getGtask(listId, taskId); } catch (Exception e) { @@ -424,18 +425,18 @@ public class GtasksNewSyncTest extends DatabaseTestCase { //Do a basic title match assertNotNull(remoteTask); assertEquals(title, localTask.getValue(Task.TITLE)); - assertEquals(title, remoteTask.title); + assertEquals(title, remoteTask.getTitle()); return remoteTask; } - private Task assertTaskExistsLocally(com.google.api.services.tasks.v1.model.Task remoteTask, String title) { + private Task assertTaskExistsLocally(com.google.api.services.tasks.model.Task remoteTask, String title) { long localId = localIdForTask(remoteTask); //Fetch the local task from the database Task localTask = taskService.fetchById(localId, Task.PROPERTIES); assertNotNull(localTask); - assertEquals(title, remoteTask.title); + assertEquals(title, remoteTask.getTitle()); assertEquals(title, localTask.getValue(Task.TITLE)); return localTask; } @@ -444,13 +445,13 @@ public class GtasksNewSyncTest extends DatabaseTestCase { return taskService.fetchById(localTask.getValue(Task.ID), Task.PROPERTIES); } - private com.google.api.services.tasks.v1.model.Task refetchRemoteTask(com.google.api.services.tasks.v1.model.Task remoteTask) throws Exception { - return gtasksService.getGtask(GtasksApiUtilities.extractListIdFromSelfLink(remoteTask), remoteTask.id); + private com.google.api.services.tasks.model.Task refetchRemoteTask(com.google.api.services.tasks.model.Task remoteTask) throws Exception { + return gtasksService.getGtask(GtasksApiUtilities.extractListIdFromSelfLink(remoteTask), remoteTask.getId()); } - private long localIdForTask(com.google.api.services.tasks.v1.model.Task remoteTask) { + private long localIdForTask(com.google.api.services.tasks.model.Task remoteTask) { TodorooCursor cursor = metadataService.query(Query.select(Metadata.TASK). - where(Criterion.and(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY), GtasksMetadata.ID.eq(remoteTask.id)))); + where(Criterion.and(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY), GtasksMetadata.ID.eq(remoteTask.getId())))); try { assertEquals(1, cursor.getCount()); @@ -528,9 +529,10 @@ public class GtasksNewSyncTest extends DatabaseTestCase { private void setupTestList() throws Exception { Tasks defaultListTasks = gtasksService.getAllGtasksFromListId(DEFAULT_LIST, false, false); - if (defaultListTasks.items != null) { - for (com.google.api.services.tasks.v1.model.Task t : defaultListTasks.items) { - gtasksService.deleteGtask(DEFAULT_LIST, t.id); + List items = defaultListTasks.getItems(); + if (items != null) { + for (com.google.api.services.tasks.model.Task t : items) { + gtasksService.deleteGtask(DEFAULT_LIST, t.getId()); } } } diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksSyncOnSaveTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksSyncOnSaveTest.java index 8e8efd0fa..a315b7f16 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksSyncOnSaveTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksSyncOnSaveTest.java @@ -2,6 +2,7 @@ package com.todoroo.astrid.gtasks; import java.io.IOException; import java.util.Date; +import java.util.List; import android.accounts.Account; import android.accounts.AccountManager; @@ -10,7 +11,7 @@ import android.content.Intent; import android.os.Bundle; import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager; -import com.google.api.services.tasks.v1.model.Tasks; +import com.google.api.services.tasks.model.Tasks; import com.timsu.astrid.R; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; @@ -55,8 +56,8 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_TO_WAIT); - com.google.api.services.tasks.v1.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); - assertEquals(title, remoteTask.title); + com.google.api.services.tasks.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); + assertEquals(title, remoteTask.getTitle()); return localTask; } @@ -66,10 +67,10 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { return localTask; } - private com.google.api.services.tasks.v1.model.Task getRemoteTaskForLocalId(long localId) throws IOException { + private com.google.api.services.tasks.model.Task getRemoteTaskForLocalId(long localId) throws IOException { Metadata gtasksMetadata = gtasksMetadataService.getTaskMetadata(localId); assertNotNull(gtasksMetadata); - com.google.api.services.tasks.v1.model.Task remoteTask = gtasksService.getGtask(DEFAULT_LIST, gtasksMetadata.getValue(GtasksMetadata.ID)); + com.google.api.services.tasks.model.Task remoteTask = gtasksService.getGtask(DEFAULT_LIST, gtasksMetadata.getValue(GtasksMetadata.ID)); assertNotNull(remoteTask); return remoteTask; } @@ -84,8 +85,8 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_TO_WAIT); - com.google.api.services.tasks.v1.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); - assertEquals(newTitle, remoteTask.title); + com.google.api.services.tasks.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); + assertEquals(newTitle, remoteTask.getTitle()); } public void testSyncOnDueDateUpdate() throws IOException { @@ -98,8 +99,8 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_TO_WAIT); - com.google.api.services.tasks.v1.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); - assertEquals(dueDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.due, 0)); + com.google.api.services.tasks.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); + assertEquals(dueDate, GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0)); } public void testSyncOnNotesUpdate() throws IOException { @@ -112,23 +113,23 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_TO_WAIT); - com.google.api.services.tasks.v1.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); - assertEquals(notes, remoteTask.notes); + com.google.api.services.tasks.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); + assertEquals(notes, remoteTask.getNotes()); } public void testSyncOnCompleted() throws IOException { if(bypassTests) return; Task localTask = performBasicCreation("-will be completed"); - long completionDate = DateUtilities.now(); + long completionDate = (DateUtilities.now() / 1000L) * 1000L; localTask.setValue(Task.COMPLETION_DATE, completionDate); taskService.save(localTask); AndroidUtilities.sleepDeep(TIME_TO_WAIT); - com.google.api.services.tasks.v1.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); - assertEquals("completed", remoteTask.status); - assertEquals(completionDate, GtasksApiUtilities.gtasksCompletedTimeToUnixTime(remoteTask.completed, 0)); + com.google.api.services.tasks.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); + assertEquals("completed", remoteTask.getStatus()); + assertEquals(completionDate, GtasksApiUtilities.gtasksCompletedTimeToUnixTime(remoteTask.getCompleted(), 0)); } public void testSyncOnDeleted() throws IOException { @@ -141,16 +142,17 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { AndroidUtilities.sleepDeep(TIME_TO_WAIT); - com.google.api.services.tasks.v1.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); - assertTrue(remoteTask.deleted); + com.google.api.services.tasks.model.Task remoteTask = getRemoteTaskForLocalId(localTask.getId()); + assertTrue(remoteTask.getDeleted()); assertFalse(taskWithTitleExists(localTask.getValue(Task.TITLE))); } private boolean taskWithTitleExists(String title) throws IOException { Tasks allTasks = gtasksService.getAllGtasksFromListId(DEFAULT_LIST, false, false); - if (allTasks.items != null) { - for (com.google.api.services.tasks.v1.model.Task t : allTasks.items) { - if (t.title.equals(title)) + List items = allTasks.getItems(); + if (items != null) { + for (com.google.api.services.tasks.model.Task t : items) { + if (t.getTitle().equals(title)) return true; } } @@ -210,9 +212,10 @@ public class GtasksSyncOnSaveTest extends DatabaseTestCase { private void setupTestList() throws Exception { Tasks defaultListTasks = gtasksService.getAllGtasksFromListId(DEFAULT_LIST, false, false); - if (defaultListTasks.items != null) { - for (com.google.api.services.tasks.v1.model.Task t : defaultListTasks.items) { - gtasksService.deleteGtask(DEFAULT_LIST, t.id); + List items = defaultListTasks.getItems(); + if (items != null) { + for (com.google.api.services.tasks.model.Task t : items) { + gtasksService.deleteGtask(DEFAULT_LIST, t.getId()); } } } diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java index 9f10e60fa..17ab443ae 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java @@ -3,8 +3,8 @@ package com.todoroo.astrid.gtasks; import java.util.ArrayList; import java.util.List; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.todoroo.andlib.service.Autowired; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; @@ -121,10 +121,10 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase { TaskLists lists = new TaskLists(); List items = new ArrayList(); TaskList list = new TaskList(); - list.id = "1"; - list.title = "Tim's Tasks"; + list.setId("1"); + list.setTitle("Tim's Tasks"); items.add(list); - lists.items = items; + lists.setItems(items); gtasksListService.updateLists(lists); } diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java index d66fe8d9d..9bf6521d6 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java @@ -3,8 +3,8 @@ package com.todoroo.astrid.gtasks; import java.util.ArrayList; import java.util.List; -import com.google.api.services.tasks.v1.model.TaskList; -import com.google.api.services.tasks.v1.model.TaskLists; +import com.google.api.services.tasks.model.TaskList; +import com.google.api.services.tasks.model.TaskLists; import com.todoroo.andlib.service.Autowired; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; @@ -237,10 +237,10 @@ public class GtasksTaskMovingTest extends DatabaseTestCase { TaskLists lists = new TaskLists(); List items = new ArrayList(); TaskList list = new TaskList(); - list.id = "1"; - list.title = "Tim's Tasks"; + list.setId("1"); + list.setTitle("Tim's Tasks"); items.add(list); - lists.items = items; + lists.setItems(items); gtasksListService.updateLists(lists); } diff --git a/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSync.java b/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSync.java index 1a02733dd..ea6c79ea5 100644 --- a/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSync.java +++ b/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSync.java @@ -2,6 +2,7 @@ package com.todoroo.astrid.sync.repeats; import java.io.IOException; import java.util.Date; +import java.util.List; import android.accounts.Account; import android.accounts.AccountManager; @@ -10,7 +11,7 @@ import android.content.Intent; import android.os.Bundle; import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager; -import com.google.api.services.tasks.v1.model.Tasks; +import com.google.api.services.tasks.model.Tasks; import com.timsu.astrid.R; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; @@ -29,7 +30,7 @@ import com.todoroo.astrid.repeats.NewRepeatTests; import com.todoroo.astrid.repeats.RepeatTaskCompleteListener; import com.todoroo.astrid.service.MetadataService; -public class RepeatTestsGtasksSync extends NewRepeatTests { +public class RepeatTestsGtasksSync extends NewRepeatTests { @Autowired MetadataService metadataService; @Autowired GtasksMetadataService gtasksMetadataService; @@ -62,12 +63,12 @@ public class RepeatTestsGtasksSync extends NewRepeatTests items = defaultListTasks.getItems(); + if (items != null) { + for (com.google.api.services.tasks.model.Task t : items) { + gtasksService.deleteGtask(DEFAULT_LIST, t.getId()); } } } diff --git a/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSyncRemote.java b/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSyncRemote.java index b74074b5c..87889e5ce 100644 --- a/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSyncRemote.java +++ b/tests/src/com/todoroo/astrid/sync/repeats/RepeatTestsGtasksSyncRemote.java @@ -15,14 +15,14 @@ public class RepeatTestsGtasksSyncRemote extends RepeatTestsGtasksSync { @Override protected long setCompletionDate(boolean completeBefore, Task t, - com.google.api.services.tasks.v1.model.Task remoteModel, long dueDate) { + com.google.api.services.tasks.model.Task remoteModel, long dueDate) { long completionDate; if (completeBefore) completionDate = dueDate - DateUtilities.ONE_DAY; else completionDate = dueDate + DateUtilities.ONE_DAY; - remoteModel.completed = GtasksApiUtilities.unixTimeToGtasksCompletionTime(completionDate); - remoteModel.status = "completed"; + remoteModel.setCompleted(GtasksApiUtilities.unixTimeToGtasksCompletionTime(completionDate)); + remoteModel.setStatus("completed"); try { gtasksService.updateGtask(GtasksApiUtilities.extractListIdFromSelfLink(remoteModel), remoteModel); } catch (IOException e) {