();
-
- public GtasksTaskListUpdater() {
- DependencyInjectionService.getInstance().inject(this);
- }
-
- // --- used during normal ui operations
-
- public void debugPrint(String listId) {
- StoreObject list = gtasksListService.getList(listId);
- if(list == GtasksListService.LIST_NOT_FOUND_OBJECT)
- return;
-
- iterateThroughList(list, new ListIterator() {
- public void processTask(long taskId, Metadata metadata) {
- System.err.format("%d: %d, indent:%d, parent:%d\n", taskId, //$NON-NLS-1$
- metadata.getValue(GtasksMetadata.ORDER),
- metadata.getValue(GtasksMetadata.INDENT),
- metadata.getValue(GtasksMetadata.PARENT_TASK));
- }
- });
- }
-
- /**
- * Indent a task and all its children
- */
- public void indent(String listId, final long targetTaskId, final int delta) {
- StoreObject list = gtasksListService.getList(listId);
- if(list == GtasksListService.LIST_NOT_FOUND_OBJECT)
- return;
-
- updateParentSiblingMapsFor(list);
-
- final AtomicInteger targetTaskIndent = new AtomicInteger(-1);
- final AtomicInteger previousIndent = new AtomicInteger(-1);
- final AtomicLong previousTask = new AtomicLong(-1);
- final Task taskContainer = new Task();
-
- iterateThroughList(list, new ListIterator() {
- @Override
- public void processTask(long taskId, Metadata metadata) {
- int indent = metadata.getValue(GtasksMetadata.INDENT);
-
- if(targetTaskId == taskId) {
- // if indenting is warranted, indent me and my children
- if(indent + delta <= previousIndent.get() + 1 && indent + delta >= 0) {
- targetTaskIndent.set(indent);
- metadata.setValue(GtasksMetadata.INDENT, indent + delta);
- if(delta > 0)
- metadata.setValue(GtasksMetadata.PARENT_TASK, previousTask.get());
- else if(parents.containsKey(taskId))
- metadata.setValue(GtasksMetadata.PARENT_TASK,
- parents.get(parents.get(taskId)));
- else
- metadata.setValue(GtasksMetadata.PARENT_TASK, Task.NO_ID);
- if(PluginServices.getMetadataService().save(metadata))
- updateModifiedDate(taskContainer, taskId);
- }
- } else if(targetTaskIndent.get() > -1) {
- // found first task that is not beneath target
- if(indent <= targetTaskIndent.get())
- targetTaskIndent.set(-1);
- else {
- metadata.setValue(GtasksMetadata.INDENT, indent + delta);
- PluginServices.getMetadataService().save(metadata);
- updateModifiedDate(taskContainer, taskId);
- }
- } else {
- previousIndent.set(indent);
- previousTask.set(taskId);
- }
- }
-
- });
- }
-
- /**
- * Move a task and all its children.
- *
- * if moving up and first task in list or moving down and last,
- * indents to same as task that we swapped with.
- *
- * @param delta -1 or 1
- *
- */
- public void move(String listId, final long targetTaskId, final int delta) {
- StoreObject list = gtasksListService.getList(listId);
- if(list == GtasksListService.LIST_NOT_FOUND_OBJECT)
- return;
-
- long taskToSwap = -1;
- if(delta == -1) {
- // use sibling / parent map to figure out prior task
- updateParentSiblingMapsFor(list);
- if(siblings.containsKey(targetTaskId) && siblings.get(targetTaskId) != -1L)
- taskToSwap = siblings.get(targetTaskId);
- else if(parents.containsKey(targetTaskId) && parents.get(targetTaskId) != -1L)
- taskToSwap = parents.get(targetTaskId);
- } else {
- // walk through to find the next task
- Filter filter = GtasksFilterExposer.filterFromList(list);
- TodorooCursor cursor = PluginServices.getTaskService().fetchFiltered(filter.sqlQuery, null, Task.ID);
- try {
- int targetIndent = -1;
- for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
- long taskId = cursor.getLong(0);
-
- if(targetIndent != -1) {
- Metadata metadata = gtasksMetadataService.getTaskMetadata(taskId);
- if(metadata.getValue(GtasksMetadata.INDENT) <= targetIndent) {
- taskToSwap = taskId;
- break;
- }
- } else if(taskId == targetTaskId) {
- Metadata metadata = gtasksMetadataService.getTaskMetadata(taskId);
- targetIndent = metadata.getValue(GtasksMetadata.INDENT);
- }
- }
- } finally {
- cursor.close();
- }
- }
-
- if(taskToSwap == -1L)
- return;
-
- if(delta == -1) {
- moveUp(list, targetTaskId, taskToSwap);
- } else {
- // adjust indent of target task to task to swap
- Metadata targetTask = gtasksMetadataService.getTaskMetadata(targetTaskId);
- Metadata nextTask = gtasksMetadataService.getTaskMetadata(taskToSwap);
- int targetIndent = targetTask.getValue(GtasksMetadata.INDENT);
- int nextIndent = nextTask.getValue(GtasksMetadata.INDENT);
- if(targetIndent != nextIndent)
- indent(listId, targetTaskId, nextIndent - targetIndent);
- moveUp(list, taskToSwap, targetTaskId);
- }
- }
-
- private void moveUp(StoreObject list, final long targetTaskId, final long priorTaskId) {
- final AtomicInteger priorTaskOrder = new AtomicInteger(-1);
- final AtomicInteger priorTaskIndent = new AtomicInteger(-1);
- final AtomicInteger targetTaskOrder = new AtomicInteger(0);
- final AtomicInteger targetTaskIndent = new AtomicInteger(-1);
- final AtomicInteger tasksToMove = new AtomicInteger(1);
- final AtomicBoolean finished = new AtomicBoolean(false);
-
- // step 1. calculate tasks to move
- iterateThroughList(list, new ListIterator() {
- @Override
- public void processTask(long taskId, Metadata metadata) {
- if(finished.get() && priorTaskOrder.get() != -1)
- return;
-
- if(taskId == priorTaskId) {
- priorTaskIndent.set(metadata.getValue(GtasksMetadata.INDENT));
- priorTaskOrder.set(metadata.getValue(GtasksMetadata.ORDER));
- } else if(targetTaskId == taskId) {
- targetTaskIndent.set(metadata.getValue(GtasksMetadata.INDENT));
- targetTaskOrder.set(metadata.getValue(GtasksMetadata.ORDER));
- } else if(targetTaskIndent.get() > -1) {
- // found first task that is not beneath target
- if(metadata.getValue(GtasksMetadata.INDENT) <= targetTaskIndent.get())
- finished.set(true);
- else
- tasksToMove.incrementAndGet();
- }
- }
- });
-
- final AtomicBoolean priorFound = new AtomicBoolean(false);
- final AtomicBoolean targetFound = new AtomicBoolean(false);
- final Task taskContainer = new Task();
- finished.set(false);
-
- // step 2. swap the order of prior and our tasks
- iterateThroughList(list, new ListIterator() {
- @Override
- public void processTask(long taskId, Metadata metadata) {
- if(finished.get())
- return;
-
- if(targetTaskId == taskId)
- targetFound.set(true);
- else if(taskId == priorTaskId)
- priorFound.set(true);
-
- if(targetFound.get()) {
- if(targetTaskId != taskId && metadata.getValue(GtasksMetadata.INDENT) <= targetTaskIndent.get())
- finished.set(true);
- else {
- int newOrder = metadata.getValue(GtasksMetadata.ORDER) -
- targetTaskOrder.get() + priorTaskOrder.get();
- int newIndent = metadata.getValue(GtasksMetadata.INDENT) -
- targetTaskIndent.get() + priorTaskIndent.get();
-
- metadata.setValue(GtasksMetadata.ORDER, newOrder);
- metadata.setValue(GtasksMetadata.INDENT, newIndent);
- PluginServices.getMetadataService().save(metadata);
- updateModifiedDate(taskContainer, taskId);
- }
- } else if(priorFound.get()) {
- int newOrder = metadata.getValue(GtasksMetadata.ORDER) +
- tasksToMove.get();
- metadata.setValue(GtasksMetadata.ORDER, newOrder);
- PluginServices.getMetadataService().save(metadata);
- updateModifiedDate(taskContainer, taskId);
- }
- }
- });
-
- }
-
- private void updateModifiedDate(Task taskContainer, long taskId) {
- taskContainer.setId(taskId);
- taskContainer.setValue(Task.DETAILS_DATE, DateUtilities.now());
- PluginServices.getTaskService().save(taskContainer);
- }
-
- // --- used during synchronization
-
- /**
- * Update order, parent, and indentation fields for all tasks in all lists
- */
- public void updateAllMetadata() {
- for(StoreObject list : gtasksListService.getLists()) {
- correctMetadataForList(list.getValue(GtasksList.REMOTE_ID));
- }
- }
-
- /**
- * Update order, parent, and indentation fields for all tasks in the given list
- * @param listId
- */
- public void correctMetadataForList(String listId) {
- StoreObject list = gtasksListService.getList(listId);
- if(list == GtasksListService.LIST_NOT_FOUND_OBJECT)
- return;
-
- updateParentSiblingMapsFor(list);
-
- final AtomicInteger order = new AtomicInteger(0);
- final AtomicInteger previousIndent = new AtomicInteger(-1);
-
- iterateThroughList(list, new ListIterator() {
- @Override
- public void processTask(long taskId, Metadata metadata) {
- metadata.setValue(GtasksMetadata.ORDER, order.getAndAdd(1));
- int indent = metadata.getValue(GtasksMetadata.INDENT);
- if(indent > previousIndent.get() + 1)
- indent = previousIndent.get() + 1;
- metadata.setValue(GtasksMetadata.INDENT, indent);
-
- long parent = parents.get(taskId);
- if(parent < 0)
- parent = Task.NO_ID;
- metadata.setValue(GtasksMetadata.PARENT_TASK, parent);
-
- PluginServices.getMetadataService().save(metadata);
- previousIndent.set(indent);
- }
- });
- }
-
- /**
- * Create a local tree of tasks to expedite sibling and parent lookups
- */
- public void createParentSiblingMaps() {
- for(StoreObject list : gtasksListService.getLists()) {
- updateParentSiblingMapsFor(list);
- }
- }
-
- private void updateParentSiblingMapsFor(StoreObject list) {
- final AtomicLong previousTask = new AtomicLong(-1L);
- final AtomicInteger previousIndent = new AtomicInteger(-1);
-
- iterateThroughList(list, new ListIterator() {
- @Override
- public void processTask(long taskId, Metadata metadata) {
- int indent = metadata.getValue(GtasksMetadata.INDENT);
-
- long parent, sibling;
- if(indent > previousIndent.get()) {
- parent = previousTask.get();
- sibling = -1L;
- } else if(indent == previousIndent.get()) {
- sibling = previousTask.get();
- parent = parents.get(sibling);
- } else {
- // move up once for each indent
- sibling = previousTask.get();
- for(int i = indent; i < previousIndent.get(); i++)
- sibling = parents.get(sibling);
- parent = parents.get(sibling);
- }
- parents.put(taskId, parent);
- siblings.put(taskId, sibling);
-
- previousTask.set(taskId);
- previousIndent.set(indent);
- if(!TextUtils.isEmpty(metadata.getValue(GtasksMetadata.ID)))
- localToRemoteIdMap.put(taskId, metadata.getValue(GtasksMetadata.ID));
- }
- });
- }
-
- /**
- * Must be called after creating parent and sibling maps. Updates a
- * task container's parent and sibling fields.
- *
- * @param container
- */
- public void updateParentAndSibling(GtasksTaskContainer container) {
- long taskId = container.task.getId();
- if(parents.containsKey(taskId)) {
- long parentId = parents.get(taskId);
- if(localToRemoteIdMap.containsKey(parentId))
- container.parentId = localToRemoteIdMap.get(parentId);
- }
- if(siblings.containsKey(taskId)) {
- long siblingId = siblings.get(taskId);
- if(localToRemoteIdMap.containsKey(siblingId))
- container.priorSiblingId = localToRemoteIdMap.get(siblingId);
- }
- }
-
- public void addRemoteTaskMapping(long id, String remoteId) {
- localToRemoteIdMap.put(id, remoteId);
- }
-
- // --- private helpers
-
- private interface ListIterator {
- public void processTask(long taskId, Metadata metadata);
- }
-
- private void iterateThroughList(StoreObject list, ListIterator iterator) {
- Filter filter = GtasksFilterExposer.filterFromList(list);
- TodorooCursor cursor = PluginServices.getTaskService().fetchFiltered(filter.sqlQuery, null, Task.ID);
- try {
- for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
- long taskId = cursor.getLong(0);
- Metadata metadata = gtasksMetadataService.getTaskMetadata(taskId);
- if(metadata == null)
- continue;
- iterator.processTask(taskId, metadata);
- }
-
- } finally {
- cursor.close();
- }
- }
-
-}
-
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AccountChooser.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AccountChooser.java
deleted file mode 100644
index aaa86d3b1..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AccountChooser.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.todoroo.astrid.gtasks.auth;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-
-import com.timsu.astrid.R;
-
-/**
- * Choose which account to upload track information to.
- * @author Sandor Dornbush
- */
-public class AccountChooser {
-
- /**
- * The last selected account.
- */
- private int selectedAccountIndex = -1;
- private Account selectedAccount = null;
-
- /**
- * An interface for receiving updates once the user has selected the account.
- */
- public interface AccountHandler {
- /**
- * Handle the account being selected.
- * @param account The selected account or null if none could be found
- */
- public void handleAccountSelected(Account account);
- }
-
- /**
- * Chooses the best account to upload to.
- * If no account is found the user will be alerted.
- * If only one account is found that will be used.
- * If multiple accounts are found the user will be allowed to choose.
- *
- * @param activity The parent activity
- * @param handler The handler to be notified when an account has been selected
- */
- public void chooseAccount(final Activity activity,
- final AccountHandler handler) {
- final Account[] accounts = AccountManager.get(activity)
- .getAccountsByType("com.google"); //$NON-NLS-1$
- if (accounts.length < 1) {
- alertNoAccounts(activity, handler);
- return;
- }
- if (accounts.length == 1) {
- handler.handleAccountSelected(accounts[0]);
- return;
- }
-
- // TODO This should be read out of a preference.
- if (selectedAccount != null) {
- handler.handleAccountSelected(selectedAccount);
- return;
- }
-
- // Let the user choose.
- final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
- builder.setTitle(R.string.choose_account_title);
- builder.setCancelable(false);
- builder.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- selectedAccount = accounts[selectedAccountIndex];
- handler.handleAccountSelected(selectedAccount);
- }
- });
- builder.setNegativeButton(android.R.string.cancel,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- handler.handleAccountSelected(null);
- }
- });
- String[] choices = new String[accounts.length];
- for (int i = 0; i < accounts.length; i++) {
- choices[i] = accounts[i].name;
- }
- builder.setSingleChoiceItems(choices, selectedAccountIndex,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- selectedAccountIndex = which;
- }
- });
- builder.show();
- }
-
- /**
- * Puts up a dialog alerting the user that no suitable account was found.
- */
- private void alertNoAccounts(final Activity activity,
- final AccountHandler handler) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
- builder.setTitle(R.string.no_account_found_title);
- builder.setMessage(R.string.no_account_found);
- builder.setCancelable(true);
- builder.setNegativeButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- handler.handleAccountSelected(null);
- }
- });
- builder.show();
- }
-}
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManager.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManager.java
deleted file mode 100644
index f410aca31..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManager.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.todoroo.astrid.gtasks.auth;
-
-import android.content.Intent;
-
-/**
- * This interface describes a class that will fetch and maintain a Google
- * authentication token.
- *
- * @author Sandor Dornbush
- */
-public interface AuthManager {
-
- /**
- * Initializes the login process. The user should be asked to login if they
- * haven't already. The {@link Runnable} provided will be executed when the
- * auth token is successfully fetched.
- *
- * @param whenFinished A {@link Runnable} to execute when the auth token
- * has been successfully fetched and is available via
- * {@link #getAuthToken()}
- */
- public abstract void doLogin(Runnable whenFinished, Object o);
-
- /**
- * The {@link android.app.Activity} owner of this class should call this
- * function when it gets {@link android.app.Activity#onActivityResult} with
- * the request code passed into the constructor. The resultCode and results
- * should come directly from the {@link android.app.Activity#onActivityResult}
- * function. This function will return true if an auth token was successfully
- * fetched or the process is not finished.
- *
- * @param resultCode The result code passed in to the
- * {@link android.app.Activity}'s
- * {@link android.app.Activity#onActivityResult} function
- * @param results The data passed in to the {@link android.app.Activity}'s
- * {@link android.app.Activity#onActivityResult} function
- * @return True if the auth token was fetched or we aren't done fetching
- * the auth token, or False if there was an error or the request was
- * canceled
- */
- public abstract boolean authResult(int resultCode, Intent results);
-
- /**
- * Returns the current auth token. Response may be null if no valid auth
- * token has been fetched.
- *
- * @return The current auth token or null if no auth token has been
- * fetched
- */
- public abstract String getAuthToken();
-
- /**
- * Invalidates the existing auth token and request a new one. The
- * {@link Runnable} provided will be executed when the new auth token is
- * successfully fetched.
- *
- * @param whenFinished A {@link Runnable} to execute when a new auth token
- * is successfully fetched
- */
- public abstract void invalidateAndRefresh(Runnable whenFinished);
-
-}
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManagerFactory.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManagerFactory.java
deleted file mode 100644
index 8ffbd0342..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManagerFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.todoroo.astrid.gtasks.auth;
-
-import android.app.Activity;
-import android.os.Build;
-import android.os.Bundle;
-
-/**
- * A factory for getting the platform specific AuthManager.
- *
- * @author Sandor Dornbush
- */
-public class AuthManagerFactory {
-
- private AuthManagerFactory() {
- // don't construct me
- }
-
- /**
- * Returns whether the modern AuthManager should be used
- */
- public static boolean useModernAuthManager() {
- return Integer.parseInt(Build.VERSION.SDK) >= 7;
- }
-
- /**
- * Get a right {@link AuthManager} for the platform.
- * @return A new AuthManager
- */
- public static AuthManager getAuthManager(Activity activity, int code,
- Bundle extras, boolean requireGoogle, String service) {
- if (useModernAuthManager()) {
- return new ModernAuthManager(activity, code, extras, requireGoogle, service);
- } else {
- return new AuthManagerOld(activity, code, extras, requireGoogle, service);
- }
- }
-
-}
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManagerOld.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManagerOld.java
deleted file mode 100644
index eda7413e2..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/AuthManagerOld.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.todoroo.astrid.gtasks.auth;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-
-import com.google.android.googlelogindist.GoogleLoginServiceConstants;
-import com.google.android.googlelogindist.GoogleLoginServiceHelper;
-
-/**
- * AuthManager keeps track of the current auth token for a user. The advantage
- * over just passing around a String is that this class can renew the auth
- * token if necessary, and it will change for all classes using this
- * AuthManager.
- */
-public class AuthManagerOld implements AuthManager {
- /** The activity that will handle auth result callbacks. */
- private final Activity activity;
-
- /** The code used to tell the activity that it is an auth result. */
- private final int code;
-
- /** Extras to pass into the getCredentials function. */
- private final Bundle extras;
-
- /** True if the account must be a Google account (not a domain account). */
- private final boolean requireGoogle;
-
- /** The name of the service to authorize for. */
- private final String service;
-
- /** A list of handlers to call when a new auth token is fetched. */
- private final Vector newTokenListeners = new Vector();
-
- /** The most recently fetched auth token or null if none is available. */
- private String authToken;
-
- /**
- * The number of handlers at the beginning of the above list that shouldn't
- * be removed after they are called.
- */
- private int stickyNewTokenListenerCount;
-
- /**
- * AuthManager requires many of the same parameters as
- * {@link GoogleLoginServiceHelper#getCredentials(Activity, int, Bundle,
- * boolean, String, boolean)}. The activity must have
- * a handler in {@link Activity#onActivityResult} that calls
- * {@link #authResult(int, Intent)} if the request code is the code given
- * here.
- *
- * @param activity An activity with a handler in
- * {@link Activity#onActivityResult} that calls
- * {@link #authResult(int, Intent)} when {@literal code} is the request
- * code
- * @param code The request code to pass to
- * {@link Activity#onActivityResult} when
- * {@link #authResult(int, Intent)} should be called
- * @param extras A {@link Bundle} of extras for
- * {@link GoogleLoginServiceHelper}
- * @param requireGoogle True if the account must be a Google account
- * @param service The name of the service to authenticate as
- */
- public AuthManagerOld(Activity activity, int code, Bundle extras,
- boolean requireGoogle, String service) {
- this.activity = activity;
- this.code = code;
- this.extras = extras;
- this.requireGoogle = requireGoogle;
- this.service = service;
- }
-
- /* (non-Javadoc)
- * @see com.google.android.apps.mytracks.io.AuthManager#doLogin(java.lang.Runnable)
- */
- public void doLogin(Runnable whenFinished, Object o) {
- synchronized (newTokenListeners) {
- if (whenFinished != null) {
- newTokenListeners.add(whenFinished);
- }
- }
- activity.runOnUiThread(new LoginRunnable());
- }
-
- /**
- * Runnable which actually gets login credentials.
- */
- private class LoginRunnable implements Runnable {
- @Override
- public void run() {
- GoogleLoginServiceHelper.getCredentials(
- activity, code, extras, requireGoogle, service, true);
- }
- }
-
- /* (non-Javadoc)
- * @see com.google.android.apps.mytracks.io.AuthManager#authResult(int, android.content.Intent)
- */
- public boolean authResult(int resultCode, Intent results) {
- if (resultCode == Activity.RESULT_OK) {
- authToken = results.getStringExtra(
- GoogleLoginServiceConstants.AUTHTOKEN_KEY);
- if (authToken == null) {
- GoogleLoginServiceHelper.getCredentials(
- activity, code, extras, requireGoogle, service, false);
- return true;
- } else {
- // Notify all active listeners that we have a new auth token.
- synchronized (newTokenListeners) {
- Iterator iter = newTokenListeners.iterator();
- while (iter.hasNext()) {
- iter.next().run();
- }
- iter = null;
- // Remove anything not in the sticky part of the list.
- newTokenListeners.setSize(stickyNewTokenListenerCount);
- }
- return true;
- }
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see com.google.android.apps.mytracks.io.AuthManager#getAuthToken()
- */
- public String getAuthToken() {
- return authToken;
- }
-
- /* (non-Javadoc)
- * @see com.google.android.apps.mytracks.io.AuthManager#invalidateAndRefresh(java.lang.Runnable)
- */
- public void invalidateAndRefresh(Runnable whenFinished) {
- synchronized (newTokenListeners) {
- if (whenFinished != null) {
- newTokenListeners.add(whenFinished);
- }
- }
- activity.runOnUiThread(new Runnable() {
- public void run() {
- GoogleLoginServiceHelper.invalidateAuthToken(activity, code, authToken);
- }
- });
- }
-
- /**
- * Adds a {@link Runnable} to be executed every time the auth token is
- * updated. The {@link Runnable} will not be removed until manually removed
- * with {@link #removeStickyNewTokenListener(Runnable)}.
- *
- * @param listener The {@link Runnable} to execute every time a new auth
- * token is fetched
- */
- public void addStickyNewTokenListener(Runnable listener) {
- synchronized (newTokenListeners) {
- newTokenListeners.add(0, listener);
- stickyNewTokenListenerCount++;
- }
- }
-
- /**
- * Stops executing the given {@link Runnable} every time the auth token is
- * updated. This {@link Runnable} must have been added with
- * {@link #addStickyNewTokenListener(Runnable)} above. If the
- * {@link Runnable} was added more than once, only the first occurrence
- * will be removed.
- *
- * @param listener The {@link Runnable} to stop executing every time a new
- * auth token is fetched
- */
- public void removeStickyNewTokenListener(Runnable listener) {
- synchronized (newTokenListeners) {
- if (stickyNewTokenListenerCount > 0
- && newTokenListeners.remove(listener)) {
- stickyNewTokenListenerCount--;
- }
- }
- }
-}
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/ModernAuthManager.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/ModernAuthManager.java
deleted file mode 100644
index 0df1b4812..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/ModernAuthManager.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.todoroo.astrid.gtasks.auth;
-
-import java.io.IOException;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AccountManagerCallback;
-import android.accounts.AccountManagerFuture;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-
-/**
- * AuthManager keeps track of the current auth token for a user. The advantage
- * over just passing around a String is that this class can renew the auth
- * token if necessary, and it will change for all classes using this
- * AuthManager.
- */
-public class ModernAuthManager implements AuthManager {
- protected static final int GET_LOGIN_REQUEST = 1;
-
-/** The activity that will handle auth result callbacks. */
- private final Activity activity;
-
- /** The name of the service to authorize for. */
- private final String service;
-
- /** The most recently fetched auth token or null if none is available. */
- private String authToken;
-
- private final AccountManager accountManager;
-
- private Runnable whenFinished;
-
- /**
- * AuthManager requires many of the same parameters as
- * {@link com.google.android.googlelogindist.GoogleLoginServiceHelper
- * #getCredentials(Activity, int, Bundle, boolean, String, boolean)}.
- * The activity must have a handler in {@link Activity#onActivityResult} that
- * calls {@link #authResult(int, Intent)} if the request code is the code
- * given here.
- *
- * @param activity An activity with a handler in
- * {@link Activity#onActivityResult} that calls
- * {@link #authResult(int, Intent)} when {@literal code} is the request
- * code
- * @param code The request code to pass to
- * {@link Activity#onActivityResult} when
- * {@link #authResult(int, Intent)} should be called
- * @param extras A {@link Bundle} of extras for
- * {@link com.google.android.googlelogindist.GoogleLoginServiceHelper}
- * @param requireGoogle True if the account must be a Google account
- * @param service The name of the service to authenticate as
- */
- public ModernAuthManager(Activity activity, int code, Bundle extras,
- boolean requireGoogle, String service) {
- this.activity = activity;
- this.service = service;
- this.accountManager = AccountManager.get(activity);
- }
-
- /**
- * Call this to do the initial login. The user will be asked to login if
- * they haven't already. The {@link Runnable} provided will be executed
- * when the auth token is successfully fetched.
- *
- * @param runnable A {@link Runnable} to execute when the auth token
- * has been successfully fetched and is available via
- * {@link #getAuthToken()}
- */
- @SuppressWarnings("nls")
- public void doLogin(final Runnable runnable, Object o) {
- this.whenFinished = runnable;
- if (!(o instanceof Account)) {
- throw new IllegalArgumentException("FroyoAuthManager requires an account.");
- }
- Account account = (Account) o;
- accountManager.getAuthToken(account, service, true,
- new AccountManagerCallback() {
- public void run(AccountManagerFuture future) {
- try {
- Bundle result = future.getResult();
-
- // AccountManager needs user to grant permission
- if (result.containsKey(AccountManager.KEY_INTENT)) {
- Intent intent = (Intent) result.get(AccountManager.KEY_INTENT);
- clearNewTaskFlag(intent);
- activity.startActivityForResult(intent, GET_LOGIN_REQUEST);
- return;
- }
-
- authToken = result.getString(
- AccountManager.KEY_AUTHTOKEN);
- Log.e("gtasks-auth", "Got auth token.");
- runWhenFinished();
- } catch (OperationCanceledException e) {
- Log.e("gtasks-auth", "Operation Canceled", e);
- } catch (IOException e) {
- Log.e("gtasks-auth", "IOException", e);
- } catch (AuthenticatorException e) {
- Log.e("gtasks-auth", "Authentication Failed", e);
- }
- }
- }, null /* handler */);
- }
-
- private static void clearNewTaskFlag(Intent intent) {
- int flags = intent.getFlags();
- flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
- intent.setFlags(flags);
- }
-
- /**
- * The {@link Activity} passed into the constructor should call this
- * function when it gets {@link Activity#onActivityResult} with the request
- * code passed into the constructor. The resultCode and results should
- * come directly from the {@link Activity#onActivityResult} function. This
- * function will return true if an auth token was successfully fetched or
- * the process is not finished.
- *
- * @param resultCode The result code passed in to the {@link Activity}'s
- * {@link Activity#onActivityResult} function
- * @param results The data passed in to the {@link Activity}'s
- * {@link Activity#onActivityResult} function
- * @return True if the auth token was fetched or we aren't done fetching
- * the auth token, or False if there was an error or the request was
- * canceled
- */
- @SuppressWarnings("nls")
- public boolean authResult(int resultCode, Intent results) {
- if (results != null) {
- authToken = results.getStringExtra(
- AccountManager.KEY_AUTHTOKEN);
- Log.w("google-auth", "authResult: " + authToken);
- } else {
- Log.e("google-auth", "No auth result results!!");
- }
- runWhenFinished();
- return authToken != null;
- }
-
- /**
- * Returns the current auth token. Response may be null if no valid auth
- * token has been fetched.
- *
- * @return The current auth token or null if no auth token has been
- * fetched
- */
- public String getAuthToken() {
- return authToken;
- }
-
- /**
- * Invalidates the existing auth token and request a new one. The
- * {@link Runnable} provided will be executed when the new auth token is
- * successfully fetched.
- *
- * @param runnable A {@link Runnable} to execute when a new auth token
- * is successfully fetched
- */
- public void invalidateAndRefresh(final Runnable runnable) {
- this.whenFinished = runnable;
-
- activity.runOnUiThread(new Runnable() {
- public void run() {
- accountManager.invalidateAuthToken("com.google", authToken); //$NON-NLS-1$
- new AccountChooser().chooseAccount(activity,
- new AccountChooser.AccountHandler() {
- @Override
- public void handleAccountSelected(Account account) {
- if (account != null) {
- doLogin(whenFinished, account);
- } else {
- runWhenFinished();
- }
- }
- });
- }
- });
- }
-
- private void runWhenFinished() {
- if (whenFinished != null) {
- (new Thread() {
- @Override
- public void run() {
- whenFinished.run();
- }
- }).start();
- }
- }
-}
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java
deleted file mode 100644
index 83aa673e7..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java
+++ /dev/null
@@ -1,540 +0,0 @@
-/**
- * See the file "LICENSE" for the full license governing this code.
- */
-package com.todoroo.astrid.gtasks.sync;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.json.JSONException;
-
-import android.app.Activity;
-import android.app.Notification;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-
-import com.flurry.android.FlurryAgent;
-import com.timsu.astrid.R;
-import com.todoroo.andlib.data.AbstractModel;
-import com.todoroo.andlib.data.Property;
-import com.todoroo.andlib.data.TodorooCursor;
-import com.todoroo.andlib.service.Autowired;
-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.DateUtilities;
-import com.todoroo.andlib.utility.DialogUtilities;
-import com.todoroo.andlib.utility.Preferences;
-import com.todoroo.astrid.data.Metadata;
-import com.todoroo.astrid.data.StoreObject;
-import com.todoroo.astrid.data.Task;
-import com.todoroo.astrid.gtasks.GtasksBackgroundService;
-import com.todoroo.astrid.gtasks.GtasksList;
-import com.todoroo.astrid.gtasks.GtasksListService;
-import com.todoroo.astrid.gtasks.GtasksMetadata;
-import com.todoroo.astrid.gtasks.GtasksMetadataService;
-import com.todoroo.astrid.gtasks.GtasksPreferenceService;
-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.GoogleTaskService;
-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;
-import com.todoroo.gtasks.actions.ListActions.TaskBuilder;
-import com.todoroo.gtasks.actions.ListActions.TaskModifier;
-
-@SuppressWarnings("nls")
-public class GtasksSyncProvider extends SyncProvider {
-
- @Autowired private GtasksListService gtasksListService;
- @Autowired private GtasksMetadataService gtasksMetadataService;
- @Autowired private GtasksPreferenceService gtasksPreferenceService;
- @Autowired private GtasksTaskListUpdater gtasksTaskListUpdater;
-
- /** google task service fields */
- private GoogleTaskService taskService = null;
- private static final Actions a = new Actions();
- private static final ListActions l = new ListActions();
-
- static {
- AstridDependencyInjector.initialize();
- }
-
- @Autowired
- protected ExceptionService exceptionService;
-
- public GtasksSyncProvider() {
- super();
- DependencyInjectionService.getInstance().inject(this);
- }
-
- // ----------------------------------------------------------------------
- // ------------------------------------------------------ utility methods
- // ----------------------------------------------------------------------
-
- /**
- * Sign out of service, deleting all synchronization metadata
- */
- public void signOut() {
- gtasksPreferenceService.clearLastSyncDate();
- gtasksPreferenceService.setToken(null);
-
- gtasksMetadataService.clearMetadata();
- }
-
- /**
- * Deal with a synchronization exception. If requested, will show an error
- * to the user (unless synchronization is happening in background)
- *
- * @param context
- * @param tag
- * error tag
- * @param e
- * exception
- * @param showError
- * whether to display a dialog
- */
- @Override
- protected void handleException(String tag, Exception e, boolean displayError) {
- final Context context = ContextManager.getContext();
- gtasksPreferenceService.setLastError(e.toString());
-
- String message = null;
-
- // occurs when application was closed
- if(e instanceof IllegalStateException) {
- 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 {
- message = context.getString(R.string.DLG_error, e.toString());
- exceptionService.reportError(tag + "-unhandled", e); //$NON-NLS-1$
- }
-
- if(displayError && context instanceof Activity && message != null) {
- DialogUtilities.okDialog((Activity)context,
- message, null);
- }
- }
-
- // ----------------------------------------------------------------------
- // ------------------------------------------------------ initiating sync
- // ----------------------------------------------------------------------
-
- /**
- * initiate sync in background
- */
- @Override
- protected void initiateBackground(Service service) {
- try {
- String authToken = gtasksPreferenceService.getToken();
-
- final GoogleConnectionManager connectionManager;
- if(authToken == null) {
- Log.e("astrid-sync", "No token, unable to sync");
- return;
- } else {
- connectionManager = new GoogleConnectionManager(authToken);
- }
-
- taskService = new GoogleTaskService(connectionManager);
- performSync();
- } catch (IllegalStateException e) {
- // occurs when application was closed
- } catch (Exception e) {
- handleException("gtasks-authenticate", e, true);
- } finally {
- gtasksPreferenceService.stopOngoing();
- }
- }
-
- /**
- * If user isn't already signed in, show sign in dialog. Else perform sync.
- */
- @Override
- protected void initiateManual(final Activity activity) {
- String authToken = gtasksPreferenceService.getToken();
- gtasksPreferenceService.stopOngoing();
-
- // check if we have a token & it works
- if(authToken == null) {
- try {
- final AuthManager authManager = AuthManagerFactory.getAuthManager(activity, 0, new Bundle(), true, "goanna_mobile");
- authManager.invalidateAndRefresh(new Runnable() {
- @Override
- public void run() {
- String token = authManager.getAuthToken();
- if(token != null) {
- gtasksPreferenceService.setToken(token);
- //activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
- // activity, GtasksBackgroundService.class));
- System.err.println("yay! " + token);
- activity.finish();
- }
- }
- });
- } catch (Exception e) {
- handleException("auth", e, true);
- }
- } else {
- activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
- activity, GtasksBackgroundService.class));
- activity.finish();
- }
- }
-
-
- // ----------------------------------------------------------------------
- // ----------------------------------------------------- synchronization!
- // ----------------------------------------------------------------------
-
- protected void performSync() {
- FlurryAgent.onEvent("gtasks-started");
- gtasksPreferenceService.recordSyncStart();
-
- try {
- GoogleTaskView taskView = taskService.getTaskView();
- Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST,
- taskView.getActiveTaskList().getInfo().getId());
-
- gtasksListService.updateLists(taskView.getAllLists());
-
- 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);
- }
-
- SyncData syncData = populateSyncData(remoteTasks);
- try {
- synchronizeTasks(syncData);
- } finally {
- syncData.localCreated.close();
- syncData.localUpdated.close();
- }
-
- gtasksTaskListUpdater.updateAllMetadata();
-
- gtasksPreferenceService.recordSuccessfulSync();
- FlurryAgent.onEvent("gtasks-sync-finished"); //$NON-NLS-1$
- } catch (IllegalStateException e) {
- // occurs when application was closed
- } catch (Exception e) {
- handleException("gtasks-sync", e, true); //$NON-NLS-1$
- }
- }
-
- private void readTasksIntoRemoteTasks(List list,
- ArrayList remoteTasks) {
-
- int order = 0;
- HashMap parents = new HashMap();
- HashMap indentation = new HashMap();
- HashMap parentToPriorSiblingMap = new HashMap();
-
- for(GoogleTaskTask remoteTask : list) {
- GtasksTaskContainer container = parseRemoteTask(remoteTask);
- String id = remoteTask.getId();
-
- // update parents, prior sibling
- for(String child : remoteTask.getChild_ids())
- parents.put(child, id);
- String parent = parents.get(id); // can be null, which means top level task
- container.parentId = parent;
- if(parentToPriorSiblingMap.containsKey(parent))
- container.priorSiblingId = parentToPriorSiblingMap.get(parent);
- parentToPriorSiblingMap.put(parent, id);
-
- // update order, indent
- container.gtaskMetadata.setValue(GtasksMetadata.ORDER, order++);
- int indent = findIndentation(parents, indentation, id);
- indentation.put(id, indent);
- container.gtaskMetadata.setValue(GtasksMetadata.INDENT, indent);
-
- // update reminder flags for incoming remote tasks to prevent annoying
- if(container.task.hasDueDate() && container.task.getValue(Task.DUE_DATE) < DateUtilities.now())
- container.task.setFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE, false);
- gtasksMetadataService.findLocalMatch(container);
- remoteTasks.add(container);
- }
- }
-
- private int findIndentation(HashMap parents,
- HashMap indentation, String task) {
- if(indentation.containsKey(task))
- return indentation.get(task);
-
- if(!parents.containsKey(task))
- return 0;
-
- 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);
- if(local.gtaskMetadata.containsNonNullValue(GtasksMetadata.LIST_ID))
- list = local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID);
- gtasksTaskListUpdater.updateParentAndSibling(local);
-
- ConvenientTaskCreator createdTask;
- try {
- createdTask = taskService.createTask(list, local.task.getValue(Task.TITLE));
- createdTask.parentId(local.parentId);
- } catch (JSONException e) {
- throw new RuntimeException(e);
- }
-
- String remoteId = updateTaskHelper(local, null, createdTask);
- gtasksTaskListUpdater.addRemoteTaskMapping(local.task.getId(), remoteId);
- local.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, remoteId);
-
- return local;
- }
-
- private String updateTaskHelper(GtasksTaskContainer local,
- GtasksTaskContainer remote, TaskBuilder> builder) throws IOException {
-
- String idTask = local.gtaskMetadata.getValue(GtasksMetadata.ID);
- String idList = local.gtaskMetadata.getValue(GtasksMetadata.LIST_ID);
-
- 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));
- }
-
- // other properties
- if(shouldTransmit(local, Task.DUE_DATE, remote))
- builder.taskDate(local.task.getValue(Task.DUE_DATE));
- if(shouldTransmit(local, Task.COMPLETION_DATE, remote))
- builder.completed(local.task.isCompleted());
- if(shouldTransmit(local, Task.DELETION_DATE, remote))
- builder.deleted(local.task.isDeleted());
- if(shouldTransmit(local, Task.NOTES, remote))
- builder.notes(local.task.getValue(Task.NOTES));
-
- String id = idList;
-
- // write task
- if(builder instanceof TaskModifier) {
- ListAction moveAction = l.move(idTask, local.parentId, local.priorSiblingId);
- ListAction action = ((TaskModifier) builder).done();
- if(remote == null || local.parentId != remote.parentId || local.priorSiblingId != remote.priorSiblingId)
- taskService.executeListActions(idList, action, moveAction);
- else
- taskService.executeListActions(idList, action);
- } else {
- id = ((ConvenientTaskCreator)builder).go();
- ListAction moveAction = l.move(id, local.parentId, local.priorSiblingId);
- taskService.executeListActions(idList, moveAction);
- }
-
- return id;
- } catch (JSONException e) {
- throw new GoogleTasksException(e);
- }
- }
-
- /** Create a task container for the given RtmTaskSeries
- * @throws JSONException */
- private GtasksTaskContainer parseRemoteTask(GoogleTaskTask remoteTask) {
- Task task = new Task();
- ArrayList metadata = new ArrayList();
-
- task.setValue(Task.TITLE, remoteTask.getName());
- task.setValue(Task.CREATION_DATE, DateUtilities.now());
- task.setValue(Task.COMPLETION_DATE, remoteTask.getCompleted_date());
- task.setValue(Task.DELETION_DATE, remoteTask.isDeleted() ? DateUtilities.now() : 0);
-
- long dueDate = remoteTask.getTask_date();
- task.setValue(Task.DUE_DATE, task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate));
- task.setValue(Task.NOTES, remoteTask.getNotes());
-
- Metadata gtasksMetadata = GtasksMetadata.createEmptyMetadata(AbstractModel.NO_ID);
- gtasksMetadata.setValue(GtasksMetadata.ID, remoteTask.getId());
- gtasksMetadata.setValue(GtasksMetadata.LIST_ID, remoteTask.getList_id());
-
- GtasksTaskContainer container = new GtasksTaskContainer(task, metadata,
- gtasksMetadata);
- return container;
- }
-
- @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.");
- }
-
- /**
- * Send changes for the given Task across the wire. If a remoteTask is
- * supplied, we attempt to intelligently only transmit the values that
- * have changed.
- */
- @Override
- protected void push(GtasksTaskContainer local, GtasksTaskContainer remote) throws IOException {
- try {
- gtasksTaskListUpdater.updateParentAndSibling(local);
-
- String id = local.gtaskMetadata.getValue(GtasksMetadata.ID);
- TaskModifier modifyTask = l.modifyTask(id);
- if(shouldTransmit(local, Task.TITLE, remote))
- modifyTask.name(local.task.getValue(Task.TITLE));
- updateTaskHelper(local, remote, modifyTask);
-
- } catch (JSONException e) {
- throw new GoogleTasksException(e);
- }
- }
-
- // ----------------------------------------------------------------------
- // --------------------------------------------------------- read / write
- // ----------------------------------------------------------------------
-
- @Override
- protected GtasksTaskContainer read(TodorooCursor cursor) throws IOException {
- return gtasksMetadataService.readTaskAndMetadata(cursor);
- }
-
- @Override
- protected void write(GtasksTaskContainer task) throws IOException {
- gtasksMetadataService.saveTaskAndMetadata(task);
- }
-
- // ----------------------------------------------------------------------
- // --------------------------------------------------------- misc helpers
- // ----------------------------------------------------------------------
-
- @Override
- protected int matchTask(ArrayList tasks, GtasksTaskContainer target) {
- int length = tasks.size();
- for(int i = 0; i < length; i++) {
- GtasksTaskContainer task = tasks.get(i);
- if(AndroidUtilities.equals(task.gtaskMetadata.getValue(GtasksMetadata.ID),
- target.gtaskMetadata.getValue(GtasksMetadata.ID)))
- return i;
- }
- return -1;
- }
-
- /**
- * Determine whether this task's property should be transmitted
- * @param task task to consider
- * @param property property to consider
- * @param remoteTask remote task proxy
- * @return
- */
- private boolean shouldTransmit(SyncContainer task, Property> property, SyncContainer remoteTask) {
- if(!task.task.containsValue(property))
- return false;
-
- if(remoteTask == null)
- return true;
- if(!remoteTask.task.containsValue(property))
- return true;
-
- // special cases - match if they're zero or nonzero
- if(property == Task.COMPLETION_DATE ||
- property == Task.DELETION_DATE)
- return !AndroidUtilities.equals((Long)task.task.getValue(property) == 0,
- (Long)remoteTask.task.getValue(property) == 0);
-
- return !AndroidUtilities.equals(task.task.getValue(property),
- remoteTask.task.getValue(property));
- }
-
- @Override
- protected int updateNotification(Context context, Notification notification) {
- String notificationTitle = context.getString(R.string.gtasks_notification_title);
- Intent intent = new Intent(context, GtasksPreferences.class);
- PendingIntent notificationIntent = PendingIntent.getActivity(context, 0,
- intent, 0);
- notification.setLatestEventInfo(context,
- notificationTitle, context.getString(R.string.SyP_progress),
- notificationIntent);
- return Constants.NOTIFICATION_SYNC;
- }
-
- @Override
- protected void transferIdentifiers(GtasksTaskContainer source,
- GtasksTaskContainer destination) {
- destination.gtaskMetadata = source.gtaskMetadata;
- }
-}
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java
deleted file mode 100644
index 3450188bf..000000000
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.todoroo.astrid.gtasks.sync;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import com.todoroo.astrid.data.Metadata;
-import com.todoroo.astrid.data.Task;
-import com.todoroo.astrid.gtasks.GtasksMetadata;
-import com.todoroo.astrid.sync.SyncContainer;
-
-/**
- * RTM Task Container
- *
- * @author Tim Su
- *
- */
-public class GtasksTaskContainer extends SyncContainer {
-
- public Metadata gtaskMetadata;
-
- // position information
- public String parentId = null;
- public String priorSiblingId = null;
-
- public GtasksTaskContainer(Task task, ArrayList metadata, Metadata gtaskMetadata) {
- this.task = task;
- this.metadata = metadata;
- this.gtaskMetadata = gtaskMetadata;
- if(this.gtaskMetadata == null) {
- this.gtaskMetadata = GtasksMetadata.createEmptyMetadata(task.getId());
- }
- }
-
- public GtasksTaskContainer(Task task, ArrayList metadata) {
- this.task = task;
- this.metadata = metadata;
-
- for(Iterator iterator = metadata.iterator(); iterator.hasNext(); ) {
- Metadata item = iterator.next();
- if(GtasksMetadata.METADATA_KEY.equals(item.getValue(Metadata.KEY))) {
- gtaskMetadata = item;
- iterator.remove();
- // don't break, could be multiple
- }
- }
- if(this.gtaskMetadata == null) {
- this.gtaskMetadata = GtasksMetadata.createEmptyMetadata(task.getId());
- }
- }
-
- @Override
- public void prepareForSaving() {
- super.prepareForSaving();
- metadata.add(gtaskMetadata);
- }
-}
\ No newline at end of file
diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java
index c7bff5c36..7f725e46a 100644
--- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java
+++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java
@@ -58,6 +58,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;
@@ -75,7 +76,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;
@@ -88,7 +88,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;
/**
@@ -618,10 +617,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 ce14b624e..96e071a20 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
@@ -624,7 +623,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/service/AstridDependencyInjector.java b/astrid/src/com/todoroo/astrid/service/AstridDependencyInjector.java
index ff60b23ff..760b78277 100644
--- a/astrid/src/com/todoroo/astrid/service/AstridDependencyInjector.java
+++ b/astrid/src/com/todoroo/astrid/service/AstridDependencyInjector.java
@@ -11,11 +11,7 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TaskDao;
-import com.todoroo.astrid.gtasks.GtasksListService;
-import com.todoroo.astrid.gtasks.GtasksMetadataService;
-import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.tags.TagService;
-import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
import com.todoroo.astrid.utility.Constants;
/**
@@ -66,12 +62,6 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
injectables.put("alertsTable", "alerts");
injectables.put("syncTable", "sync");
- // com.todoroo.astrid.gtasks
- injectables.put("gtasksPreferenceService", GtasksPreferenceService.class);
- injectables.put("gtasksListService", GtasksListService.class);
- injectables.put("gtasksMetadataService", GtasksMetadataService.class);
- injectables.put("gtasksTaskListUpdater", GtasksTaskListUpdater.class);
-
// com.todoroo.astrid.tags
injectables.put("tagService", TagService.class);
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;