From 3e8ffc390f1391c7d74f67f8a62cbcf436f67128 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Tue, 5 Oct 2010 17:36:21 -0700 Subject: [PATCH] Handle case where user didn't really have a default list --- .../gtasks/sync/GtasksSyncProvider.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 f9905470b..21b3ca3a0 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java @@ -67,6 +67,7 @@ import com.todoroo.gtasks.actions.ListAction; import com.todoroo.gtasks.actions.ListActions; import com.todoroo.gtasks.actions.ListActions.TaskBuilder; import com.todoroo.gtasks.actions.ListActions.TaskModifier; +import com.todoroo.gtasks.actions.ListCreationAction; @SuppressWarnings("nls") public class GtasksSyncProvider extends SyncProvider { @@ -252,11 +253,7 @@ public class GtasksSyncProvider extends SyncProvider { try { GoogleTaskView taskView = taskService.getTaskView(); - if(taskView.getActiveTaskList() != null) - Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, - taskView.getActiveTaskList().getInfo().getId()); - else - Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, null); + getActiveList(taskView); gtasksListService.updateLists(taskView.getAllLists()); @@ -284,6 +281,22 @@ public class GtasksSyncProvider extends SyncProvider { } } + private void getActiveList(GoogleTaskView taskView) throws JSONException, + IOException, GoogleLoginException { + String listId; + if(taskView.getActiveTaskList() != null && taskView.getActiveTaskList().getInfo() != null) + listId = taskView.getActiveTaskList().getInfo().getId(); + else if(taskView.getAllLists().length == 0) { + ListCreationAction createList = a.createList(0, ContextManager.getString(R.string.app_name)); + taskService.executeActions(createList); + listId = createList.getNewId(); + } else { + listId = taskView.getAllLists()[0].getId(); + } + + Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, listId); + } + @Override protected void readRemotelyUpdated(SyncData data) throws IOException {