Manual merge of improvements from split-out gtasks project and our current branch

pull/14/head
Tim Su 14 years ago
parent a85ba5571d
commit 48e42f910e

@ -258,34 +258,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name="com.todoroo.astrid.gtasks.GtasksOrderAction$GtasksMoveUpAction"
android:label="@string/gtasks_move_up">
<intent-filter>
<action android:name="com.todoroo.astrid.CONTEXT_MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name="com.todoroo.astrid.gtasks.GtasksIndentAction$GtasksIncreaseIndentAction"
android:label="@string/gtasks_increase_indent">
<intent-filter>
<action android:name="com.todoroo.astrid.CONTEXT_MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name="com.todoroo.astrid.gtasks.GtasksIndentAction$GtasksDecreaseIndentAction"
android:label="@string/gtasks_decrease_indent">
<intent-filter>
<action android:name="com.todoroo.astrid.CONTEXT_MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name="com.todoroo.astrid.gtasks.GtasksOrderAction$GtasksMoveDownAction"
android:label="@string/gtasks_move_down">
<intent-filter>
<action android:name="com.todoroo.astrid.CONTEXT_MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<!-- tags -->
<receiver android:name="com.todoroo.astrid.tags.TagsPlugin">

@ -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 <tim@todoroo.com>
*
*/
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;
}
}

@ -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<GtasksTaskContainer> {
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<GtasksTaskContainer> {
// 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<GtasksTaskContainer> {
gtasksTaskListUpdater.createParentSiblingMaps();
// batched read tasks for each list
ArrayList<GtasksTaskContainer> remoteTasks = new ArrayList<GtasksTaskContainer>();
for(StoreObject dashboard : gtasksListService.getLists()) {
String listId = dashboard.getValue(GtasksList.REMOTE_ID);
List<GoogleTaskTask> list = taskService.getTasks(listId);
readTasksIntoRemoteTasks(list, remoteTasks);
}
ArrayList<GtasksTaskContainer> remoteTasks = readAllRemoteTasks();
SyncData<GtasksTaskContainer> syncData = populateSyncData(remoteTasks);
try {
@ -250,7 +246,66 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
}
}
private void readTasksIntoRemoteTasks(List<GoogleTaskTask> list,
@Override
protected void readRemotelyUpdated(SyncData<GtasksTaskContainer> 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<GtasksTaskContainer> populateSyncData(ArrayList<GtasksTaskContainer> remoteTasks) throws JSONException {
// fetch locally created tasks
TodorooCursor<Task> localCreated = gtasksMetadataService.getLocallyCreated(PROPERTIES);
// fetch locally updated tasks
TodorooCursor<Task> localUpdated = gtasksMetadataService.getLocallyUpdated(PROPERTIES);
return new SyncData<GtasksTaskContainer>(remoteTasks, localCreated, localUpdated);
}
// ----------------------------------------------------------------------
// ------------------------------------------------- create / push / pull
// ----------------------------------------------------------------------
private ArrayList<GtasksTaskContainer> readAllRemoteTasks()
throws JSONException, IOException, GoogleLoginException {
ArrayList<GtasksTaskContainer> remoteTasks = new ArrayList<GtasksTaskContainer>();
for(StoreObject dashboard : gtasksListService.getLists()) {
String listId = dashboard.getValue(GtasksList.REMOTE_ID);
List<GoogleTaskTask> list = taskService.getTasks(listId);
addRemoteTasksToList(list, remoteTasks);
}
return remoteTasks;
}
private void addRemoteTasksToList(List<GoogleTaskTask> list,
ArrayList<GtasksTaskContainer> remoteTasks) {
int order = 0;
@ -296,40 +351,6 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
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<GtasksTaskContainer> populateSyncData(ArrayList<GtasksTaskContainer> remoteTasks) throws JSONException {
// fetch locally created tasks
TodorooCursor<Task> localCreated = gtasksMetadataService.getLocallyCreated(PROPERTIES);
// fetch locally updated tasks
TodorooCursor<Task> localUpdated = gtasksMetadataService.getLocallyUpdated(PROPERTIES);
return new SyncData<GtasksTaskContainer>(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<GtasksTaskContainer> {
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<GtasksTaskContainer> {
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<GtasksTaskContainer> {
@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<GoogleTaskTask> 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;
}
/**

@ -13,18 +13,6 @@
<!-- GTasks Indent changed message (%d => new level) -->
<string name="gtasks_indent_toast">New Indentation: %d</string>
<!-- GTasks label: move up -->
<string name="gtasks_move_up">▲ Move Up</string>
<!-- GTasks label: increase indent -->
<string name="gtasks_increase_indent">▶ Move Right</string>
<!-- GTasks label: decrease indent -->
<string name="gtasks_decrease_indent">◀ Move Left</string>
<!-- GTasks label: move down -->
<string name="gtasks_move_down">▼ Move Down</string>
<!-- ============================================== GtasksPreferences == -->
<!-- GTasks Preferences Title -->

@ -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<Task> 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,

@ -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()
};
/**

@ -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;

Loading…
Cancel
Save