From 48e42f910e4eb2506782899d81f25ca6c96f44d4 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Mon, 4 Oct 2010 18:09:03 -0700 Subject: [PATCH] Manual merge of improvements from split-out gtasks project and our current branch --- astrid/AndroidManifest.xml | 28 ---- .../gtasks/GtasksDecorationExposer.java | 64 -------- .../gtasks/sync/GtasksSyncProvider.java | 142 +++++++++--------- astrid/res/values/strings-gtasks.xml | 12 -- .../astrid/activity/TaskListActivity.java | 7 +- .../todoroo/astrid/adapter/TaskAdapter.java | 4 +- .../src/com/todoroo/astrid/utility/Flags.java | 5 - 7 files changed, 77 insertions(+), 185 deletions(-) delete mode 100644 astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDecorationExposer.java diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 7a17fb431..c5aaf6ffd 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -258,34 +258,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDecorationExposer.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDecorationExposer.java deleted file mode 100644 index 74d1ff608..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDecorationExposer.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.gtasks; - -import android.widget.RemoteViews; - -import com.timsu.astrid.R; -import com.todoroo.andlib.service.Autowired; -import com.todoroo.andlib.service.ContextManager; -import com.todoroo.andlib.service.DependencyInjectionService; -import com.todoroo.astrid.api.TaskDecoration; -import com.todoroo.astrid.api.TaskDecorationExposer; -import com.todoroo.astrid.data.Metadata; -import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.utility.Flags; - -/** - * Exposes {@link TaskDecoration} for GTasks indentation - * - * @author Tim Su - * - */ -public class GtasksDecorationExposer implements TaskDecorationExposer { - - @Autowired private GtasksMetadataService gtasksMetadataService; - @Autowired private GtasksPreferenceService gtasksPreferenceService; - - public GtasksDecorationExposer() { - DependencyInjectionService.getInstance().inject(this); - } - - @Override - public TaskDecoration expose(Task task) { - if(!gtasksPreferenceService.isLoggedIn()) - return null; - - if(!Flags.check(Flags.GTASKS)) - return null; - - return createDecoration(task); - } - - private TaskDecoration createDecoration(Task task) { - Metadata metadata = gtasksMetadataService.getTaskMetadata(task.getId()); - if(metadata == null) - return null; - - int indentation = metadata.getValue(GtasksMetadata.INDENT); - if(indentation <= 0) - return null; - - RemoteViews decoration = new RemoteViews(ContextManager.getContext().getPackageName(), - R.layout.gtasks_decoration); - decoration.setInt(R.id.indent, "setMinWidth", indentation * 20); //$NON-NLS-1$ - return new TaskDecoration(decoration, TaskDecoration.POSITION_LEFT, 0); - } - - @Override - public String getAddon() { - return GtasksPreferenceService.IDENTIFIER; - } - -} 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 83aa673e7..f38bd369b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java @@ -45,18 +45,18 @@ import com.todoroo.astrid.gtasks.GtasksPreferences; import com.todoroo.astrid.gtasks.GtasksTaskListUpdater; import com.todoroo.astrid.gtasks.auth.AuthManager; import com.todoroo.astrid.gtasks.auth.AuthManagerFactory; -import com.todoroo.astrid.producteev.api.ApiServiceException; import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.sync.SyncBackgroundService; import com.todoroo.astrid.sync.SyncContainer; import com.todoroo.astrid.sync.SyncProvider; import com.todoroo.astrid.utility.Constants; import com.todoroo.gtasks.GoogleConnectionManager; +import com.todoroo.gtasks.GoogleLoginException; import com.todoroo.gtasks.GoogleTaskService; +import com.todoroo.gtasks.GoogleTaskService.ConvenientTaskCreator; import com.todoroo.gtasks.GoogleTaskTask; import com.todoroo.gtasks.GoogleTaskView; import com.todoroo.gtasks.GoogleTasksException; -import com.todoroo.gtasks.GoogleTaskService.ConvenientTaskCreator; import com.todoroo.gtasks.actions.Actions; import com.todoroo.gtasks.actions.ListAction; import com.todoroo.gtasks.actions.ListActions; @@ -126,8 +126,8 @@ public class GtasksSyncProvider extends SyncProvider { exceptionService.reportError(tag + "-caught", e); //$NON-NLS-1$ // occurs when network error - } else if(!(e instanceof ApiServiceException) && e instanceof IOException) { - message = context.getString(R.string.producteev_ioerror); + } else if(!(e instanceof GoogleTasksException) && e instanceof IOException) { + message = context.getString(R.string.SyP_ioerror); } else { message = context.getString(R.string.DLG_error, e.toString()); exceptionService.reportError(tag + "-unhandled", e); //$NON-NLS-1$ @@ -181,7 +181,8 @@ public class GtasksSyncProvider extends SyncProvider { // check if we have a token & it works if(authToken == null) { try { - final AuthManager authManager = AuthManagerFactory.getAuthManager(activity, 0, new Bundle(), true, "goanna_mobile"); + final AuthManager authManager = AuthManagerFactory.getAuthManager( + activity, 0, new Bundle(), true, "goanna_mobile"); authManager.invalidateAndRefresh(new Runnable() { @Override public void run() { @@ -224,12 +225,7 @@ public class GtasksSyncProvider extends SyncProvider { gtasksTaskListUpdater.createParentSiblingMaps(); // batched read tasks for each list - ArrayList remoteTasks = new ArrayList(); - for(StoreObject dashboard : gtasksListService.getLists()) { - String listId = dashboard.getValue(GtasksList.REMOTE_ID); - List list = taskService.getTasks(listId); - readTasksIntoRemoteTasks(list, remoteTasks); - } + ArrayList remoteTasks = readAllRemoteTasks(); SyncData syncData = populateSyncData(remoteTasks); try { @@ -250,7 +246,66 @@ public class GtasksSyncProvider extends SyncProvider { } } - private void readTasksIntoRemoteTasks(List list, + @Override + protected void readRemotelyUpdated(SyncData data) + throws IOException { + // first, pull all tasks. then we can write them + try { + data.remoteUpdated = readAllRemoteTasks(); + } catch (JSONException e) { + throw new GoogleTasksException(e); + } + + super.readRemotelyUpdated(data); + } + + + // ---------------------------------------------------------------------- + // ------------------------------------------------------------ sync data + // ---------------------------------------------------------------------- + + // all synchronized properties + private static final Property[] PROPERTIES = new Property[] { + Task.ID, + Task.TITLE, + Task.DUE_DATE, + Task.CREATION_DATE, + Task.COMPLETION_DATE, + Task.DELETION_DATE, + Task.REMINDER_FLAGS, + Task.NOTES, + }; + + /** + * Populate SyncData data structure + * @throws JSONException + */ + private SyncData populateSyncData(ArrayList remoteTasks) throws JSONException { + // fetch locally created tasks + TodorooCursor localCreated = gtasksMetadataService.getLocallyCreated(PROPERTIES); + + // fetch locally updated tasks + TodorooCursor localUpdated = gtasksMetadataService.getLocallyUpdated(PROPERTIES); + + return new SyncData(remoteTasks, localCreated, localUpdated); + } + + // ---------------------------------------------------------------------- + // ------------------------------------------------- create / push / pull + // ---------------------------------------------------------------------- + + private ArrayList readAllRemoteTasks() + throws JSONException, IOException, GoogleLoginException { + ArrayList remoteTasks = new ArrayList(); + for(StoreObject dashboard : gtasksListService.getLists()) { + String listId = dashboard.getValue(GtasksList.REMOTE_ID); + List list = taskService.getTasks(listId); + addRemoteTasksToList(list, remoteTasks); + } + return remoteTasks; + } + + private void addRemoteTasksToList(List list, ArrayList remoteTasks) { int order = 0; @@ -296,40 +351,6 @@ public class GtasksSyncProvider extends SyncProvider { return findIndentation(parents, indentation, parents.get(task)) + 1; } - // ---------------------------------------------------------------------- - // ------------------------------------------------------------ sync data - // ---------------------------------------------------------------------- - - // all synchronized properties - private static final Property[] PROPERTIES = new Property[] { - Task.ID, - Task.TITLE, - Task.DUE_DATE, - Task.CREATION_DATE, - Task.COMPLETION_DATE, - Task.DELETION_DATE, - Task.REMINDER_FLAGS, - Task.NOTES, - }; - - /** - * Populate SyncData data structure - * @throws JSONException - */ - private SyncData populateSyncData(ArrayList remoteTasks) throws JSONException { - // fetch locally created tasks - TodorooCursor localCreated = gtasksMetadataService.getLocallyCreated(PROPERTIES); - - // fetch locally updated tasks - TodorooCursor localUpdated = gtasksMetadataService.getLocallyUpdated(PROPERTIES); - - return new SyncData(remoteTasks, localCreated, localUpdated); - } - - // ---------------------------------------------------------------------- - // ------------------------------------------------- create / push / pull - // ---------------------------------------------------------------------- - @Override protected GtasksTaskContainer create(GtasksTaskContainer local) throws IOException { String list = Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST); @@ -361,8 +382,10 @@ public class GtasksSyncProvider extends SyncProvider { try { // moving between lists - if(remote != null && !idList.equals(remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID))) { - taskService.executeActions(a.moveTask(idTask, idList, remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), null)); + if(remote != null && !idList.equals(remote.gtaskMetadata.getValue( + GtasksMetadata.LIST_ID))) { + taskService.executeActions(a.moveTask(idTask, idList, + remote.gtaskMetadata.getValue(GtasksMetadata.LIST_ID), null)); } // other properties @@ -377,7 +400,7 @@ public class GtasksSyncProvider extends SyncProvider { String id = idList; - // write task + // write task (and perform move action if requested) if(builder instanceof TaskModifier) { ListAction moveAction = l.move(idTask, local.parentId, local.priorSiblingId); ListAction action = ((TaskModifier) builder).done(); @@ -423,24 +446,9 @@ public class GtasksSyncProvider extends SyncProvider { @Override protected GtasksTaskContainer pull(GtasksTaskContainer task) throws IOException { - if(!task.gtaskMetadata.containsNonNullValue(GtasksMetadata.ID) || - !task.gtaskMetadata.containsNonNullValue(GtasksMetadata.LIST_ID)) - throw new ApiServiceException("Tried to read an invalid task"); //$NON-NLS-1$ - - String idToMatch = task.gtaskMetadata.getValue(GtasksMetadata.ID); - List tasks; - try { - tasks = taskService.getTasks(task.gtaskMetadata.getValue(GtasksMetadata.LIST_ID)); - } catch (JSONException e) { - throw new GoogleTasksException(e); - } - for(GoogleTaskTask remoteTask : tasks) { - if(remoteTask.getId().equals(idToMatch)) { - return parseRemoteTask(remoteTask); - } - } - - throw new GoogleTasksException("Could not find remote task to pull."); + // we pull all tasks at the end, so here we just + // return the task that was requested + return task; } /** diff --git a/astrid/res/values/strings-gtasks.xml b/astrid/res/values/strings-gtasks.xml index 912031eb3..61dc4f1ce 100644 --- a/astrid/res/values/strings-gtasks.xml +++ b/astrid/res/values/strings-gtasks.xml @@ -13,18 +13,6 @@ New Indentation: %d - - ▲ Move Up - - - ▶ Move Right - - - ◀ Move Left - - - ▼ Move Down - diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index c197650ed..8643573df 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -59,6 +59,7 @@ import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.utility.AndroidUtilities; +import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.widget.GestureService; import com.todoroo.andlib.widget.GestureService.GestureInterface; import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener; @@ -76,7 +77,6 @@ import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksMetadata; import com.todoroo.astrid.helper.TaskListContextMenuExtensionLoader; import com.todoroo.astrid.helper.TaskListContextMenuExtensionLoader.ContextMenuItem; import com.todoroo.astrid.reminders.Notifications; @@ -89,7 +89,6 @@ import com.todoroo.astrid.service.StartupService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Flags; -import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.widget.TasksWidget; /** @@ -630,10 +629,6 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, TodorooCursor currentCursor = taskService.fetchFiltered( sqlQueryTemplate.get(), null, TaskAdapter.PROPERTIES); startManagingCursor(currentCursor); - if(sqlQueryTemplate.get().contains(GtasksMetadata.METADATA_KEY)) - Flags.set(Flags.GTASKS); - else - Flags.checkAndClear(Flags.GTASKS); // set up list adapters taskAdapter = new TaskAdapter(this, R.layout.task_adapter_row, diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 52f64444f..78c986996 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -45,6 +45,7 @@ import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; +import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.activity.TaskEditActivity; import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.api.AstridApiConstants; @@ -52,13 +53,11 @@ import com.todoroo.astrid.api.TaskAction; import com.todoroo.astrid.api.TaskDecoration; import com.todoroo.astrid.api.TaskDecorationExposer; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksDecorationExposer; import com.todoroo.astrid.helper.TaskAdapterAddOnManager; import com.todoroo.astrid.service.AddOnService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.timers.TimerDecorationExposer; import com.todoroo.astrid.utility.Constants; -import com.todoroo.andlib.utility.Preferences; /** * Adapter for displaying a user's tasks as a list @@ -629,7 +628,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable { private final TaskDecorationExposer[] exposers = new TaskDecorationExposer[] { new TimerDecorationExposer(), - new GtasksDecorationExposer() }; /** diff --git a/astrid/src/com/todoroo/astrid/utility/Flags.java b/astrid/src/com/todoroo/astrid/utility/Flags.java index 2ac8a0da8..d7b2645e5 100644 --- a/astrid/src/com/todoroo/astrid/utility/Flags.java +++ b/astrid/src/com/todoroo/astrid/utility/Flags.java @@ -9,11 +9,6 @@ public class Flags { */ public static final int REFRESH = 1 << 0; - /** - * Whether active filter is GTasks - */ - public static final int GTASKS = 1 << 1; - public static boolean checkAndClear(int flag) { boolean set = (state & flag) > 0; state &= ~flag;