Handle case where user didn't really have a default list

pull/14/head
Tim Su 14 years ago
parent 9a977e0129
commit 3e8ffc390f

@ -67,6 +67,7 @@ import com.todoroo.gtasks.actions.ListAction;
import com.todoroo.gtasks.actions.ListActions; import com.todoroo.gtasks.actions.ListActions;
import com.todoroo.gtasks.actions.ListActions.TaskBuilder; import com.todoroo.gtasks.actions.ListActions.TaskBuilder;
import com.todoroo.gtasks.actions.ListActions.TaskModifier; import com.todoroo.gtasks.actions.ListActions.TaskModifier;
import com.todoroo.gtasks.actions.ListCreationAction;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> { public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
@ -252,11 +253,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
try { try {
GoogleTaskView taskView = taskService.getTaskView(); GoogleTaskView taskView = taskService.getTaskView();
if(taskView.getActiveTaskList() != null) getActiveList(taskView);
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST,
taskView.getActiveTaskList().getInfo().getId());
else
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, null);
gtasksListService.updateLists(taskView.getAllLists()); gtasksListService.updateLists(taskView.getAllLists());
@ -284,6 +281,22 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
} }
} }
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 @Override
protected void readRemotelyUpdated(SyncData<GtasksTaskContainer> data) protected void readRemotelyUpdated(SyncData<GtasksTaskContainer> data)
throws IOException { throws IOException {

Loading…
Cancel
Save