Various fixes to get the dialogs looking right, and catching exceptions.

pull/14/head
Tim Su 16 years ago
parent c722008f89
commit ad15acbcf7

@ -25,7 +25,6 @@ public class SyncPreferences extends PreferenceActivity {
@Override
public void onClick(View v) {
Synchronizer.synchronize(SyncPreferences.this);
finish();
}
});

@ -18,6 +18,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.activities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
@ -110,8 +111,8 @@ public class TaskList extends Activity {
// other instance variables
private Map<TagIdentifier, TagModelForView> tagMap;
private List<TaskModelForList> taskArray;
private Map<TaskModelForList, List<TagModelForView>> taskTags;
private ArrayList<TaskModelForList> taskArray;
private HashMap<TaskModelForList, LinkedList<TagModelForView>> taskTags;
private GestureDetector gestureDetector;
private View.OnTouchListener gestureTouchListener;
@ -339,7 +340,7 @@ public class TaskList extends Activity {
// read tags and apply filters
int hiddenTasks = 0; // # of tasks hidden
int completedTasks = 0; // # of tasks on list that are done
taskTags = new HashMap<TaskModelForList, List<TagModelForView>>();
taskTags = new HashMap<TaskModelForList, LinkedList<TagModelForView>>();
for(Iterator<TaskModelForList> i = taskArray.iterator(); i.hasNext();) {
TaskModelForList task = i.next();
@ -351,9 +352,9 @@ public class TaskList extends Activity {
}
// get list of tags
List<TagIdentifier> tagIds = tagController.getTaskTags(this,
LinkedList<TagIdentifier> tagIds = tagController.getTaskTags(this,
task.getTaskIdentifier());
List<TagModelForView> tags = new LinkedList<TagModelForView>();
LinkedList<TagModelForView> tags = new LinkedList<TagModelForView>();
for(TagIdentifier tagId : tagIds) {
TagModelForView tag = tagMap.get(tagId);
tags.add(tag);

@ -20,7 +20,6 @@
package com.timsu.astrid.data.sync;
import java.util.HashSet;
import java.util.Set;
import android.content.ContentValues;
import android.content.Context;
@ -60,8 +59,8 @@ public class SyncDataController extends AbstractController {
// --- sync mapping
/** Get all mappings for the given synchronization service */
public Set<SyncMapping> getSyncMapping(int syncServiceId) throws SQLException {
Set<SyncMapping> list = new HashSet<SyncMapping>();
public HashSet<SyncMapping> getSyncMapping(int syncServiceId) throws SQLException {
HashSet<SyncMapping> list = new HashSet<SyncMapping>();
Cursor cursor = syncDatabase.query(SYNC_TABLE_NAME,
SyncMapping.FIELD_LIST,
SyncMapping.SYNC_SERVICE + " = " + syncServiceId,

@ -21,8 +21,6 @@ package com.timsu.astrid.data.tag;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.ContentValues;
@ -43,9 +41,9 @@ public class TagController extends AbstractController {
// --- tag batch operations
/** Get a list of all tags */
public List<TagModelForView> getAllTags(Activity activity)
public LinkedList<TagModelForView> getAllTags(Activity activity)
throws SQLException {
List<TagModelForView> list = new LinkedList<TagModelForView>();
LinkedList<TagModelForView> list = new LinkedList<TagModelForView>();
Cursor cursor = tagDatabase.query(TAG_TABLE_NAME,
TagModelForView.FIELD_LIST, null, null, null, null, null, null);
activity.startManagingCursor(cursor);
@ -63,17 +61,17 @@ public class TagController extends AbstractController {
// --- tag to task map batch operations
/** Get a list of all tags as an id => tag map */
public Map<TagIdentifier, TagModelForView> getAllTagsAsMap(Activity activity) throws SQLException {
Map<TagIdentifier, TagModelForView> map = new HashMap<TagIdentifier, TagModelForView>();
public HashMap<TagIdentifier, TagModelForView> getAllTagsAsMap(Activity activity) throws SQLException {
HashMap<TagIdentifier, TagModelForView> map = new HashMap<TagIdentifier, TagModelForView>();
for(TagModelForView tag : getAllTags(activity))
map.put(tag.getTagIdentifier(), tag);
return map;
}
/** Get a list of tag identifiers for the given task */
public List<TagIdentifier> getTaskTags(Activity activity, TaskIdentifier
public LinkedList<TagIdentifier> getTaskTags(Activity activity, TaskIdentifier
taskId) throws SQLException {
List<TagIdentifier> list = new LinkedList<TagIdentifier>();
LinkedList<TagIdentifier> list = new LinkedList<TagIdentifier>();
Cursor cursor = tagToTaskMapDatabase.query(TAG_TASK_MAP_NAME,
TagToTaskMapping.FIELD_LIST, TagToTaskMapping.TASK + " = ?",
new String[] { taskId.idAsString() }, null, null, null);
@ -90,9 +88,9 @@ public class TagController extends AbstractController {
}
/** Get a list of task identifiers for the given tag */
public List<TaskIdentifier> getTaggedTasks(Activity activity, TagIdentifier
public LinkedList<TaskIdentifier> getTaggedTasks(Activity activity, TagIdentifier
tagId) throws SQLException {
List<TaskIdentifier> list = new LinkedList<TaskIdentifier>();
LinkedList<TaskIdentifier> list = new LinkedList<TaskIdentifier>();
Cursor cursor = tagToTaskMapDatabase.query(TAG_TASK_MAP_NAME,
TagToTaskMapping.FIELD_LIST, TagToTaskMapping.TAG + " = ?",
new String[] { tagId.idAsString() }, null, null, null);

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import android.app.Activity;
import android.content.ContentValues;
@ -47,8 +46,8 @@ public class TaskController extends AbstractController {
// --- task list operations
/** Return a list of all active tasks with notifications */
public Set<TaskModelForNotify> getTasksWithNotifications() {
Set<TaskModelForNotify> list = new HashSet<TaskModelForNotify>();
public HashSet<TaskModelForNotify> getTasksWithNotifications() {
HashSet<TaskModelForNotify> list = new HashSet<TaskModelForNotify>();
Cursor cursor = database.query(TASK_TABLE_NAME, TaskModelForNotify.FIELD_LIST,
String.format("%s < %d AND (%s != 0 OR %s != 0)",
AbstractTaskModel.PROGRESS_PERCENTAGE,
@ -69,8 +68,8 @@ public class TaskController extends AbstractController {
}
/** Return a list of all active tasks with deadlines */
public List<TaskModelForNotify> getTasksWithDeadlines() {
List<TaskModelForNotify> list = new ArrayList<TaskModelForNotify>();
public ArrayList<TaskModelForNotify> getTasksWithDeadlines() {
ArrayList<TaskModelForNotify> list = new ArrayList<TaskModelForNotify>();
Cursor cursor = database.query(TASK_TABLE_NAME, TaskModelForNotify.FIELD_LIST,
String.format("%s < %d AND (%s != 0 OR %s != 0)",
AbstractTaskModel.PROGRESS_PERCENTAGE,
@ -105,8 +104,8 @@ public class TaskController extends AbstractController {
}
/** Create a list of tasks from the db cursor given */
public List<TaskModelForList> createTaskListFromCursor(Cursor cursor) {
List<TaskModelForList> list = new ArrayList<TaskModelForList>();
public ArrayList<TaskModelForList> createTaskListFromCursor(Cursor cursor) {
ArrayList<TaskModelForList> list = new ArrayList<TaskModelForList>();
if(cursor.getCount() == 0)
return list;
@ -120,8 +119,8 @@ public class TaskController extends AbstractController {
}
/** Get identifiers for all tasks */
public Set<TaskIdentifier> getActiveTaskIdentifiers() {
Set<TaskIdentifier> list = new HashSet<TaskIdentifier>();
public HashSet<TaskIdentifier> getActiveTaskIdentifiers() {
HashSet<TaskIdentifier> list = new HashSet<TaskIdentifier>();
Cursor cursor = database.query(TASK_TABLE_NAME, new String[] { KEY_ROWID },
AbstractTaskModel.PROGRESS_PERCENTAGE + " < " +
AbstractTaskModel.COMPLETE_PERCENTAGE, null, null, null, null, null);

@ -51,24 +51,19 @@ public class RTMSyncService extends SynchronizationService {
}
@Override
void synchronizeService(final Activity activity) {
Date lastSyncDate = Preferences.getSyncRTMLastSync(activity);
if(lastSyncDate == null || true) {
protected void synchronize(final Activity activity) {
if(Preferences.shouldSyncRTM(activity) &&
Preferences.getSyncRTMToken(activity) == null) {
DialogUtilities.okCancelDialog(activity,
activity.getResources().getString(R.string.sync_rtm_notes),
new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
RTMSyncService.super.synchronizeService(activity);
authenticate(activity);
}
}, null);
} else
super.synchronizeService(activity);
}
@Override
protected void synchronize(Activity activity) {
authenticate(activity);
authenticate(activity);
}
@Override
@ -112,23 +107,18 @@ public class RTMSyncService extends SynchronizationService {
rtmService = new ServiceImpl(new ApplicationInfo(
apiKey, sharedSecret, appName));
final String url = rtmService.beginAuthorization(Perms.delete);
syncHandler.post(new Runnable() {
progressDialog.dismiss();
Resources r = activity.getResources();
DialogUtilities.okCancelDialog(activity,
r.getString(R.string.sync_auth_request, "RTM"),
new DialogInterface.OnClickListener() {
@Override
public void run() {
progressDialog.dismiss();
Resources r = activity.getResources();
DialogUtilities.okCancelDialog(activity,
r.getString(R.string.sync_auth_request, "RTM"),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
activity.startActivity(intent);
}
}, null);
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
activity.startActivity(intent);
}
});
}, null);
} else {
performSync(activity);
@ -139,7 +129,17 @@ public class RTMSyncService extends SynchronizationService {
}
}
private void performSync(Activity activity) {
private void performSync(final Activity activity) {
new Thread(new Runnable() {
@Override
public void run() {
performSyncInNewThread(activity);
Synchronizer.closeControllers();
}
}).start();
}
private void performSyncInNewThread(final Activity activity) {
try {
syncHandler.post(new Runnable() {
@Override

@ -3,9 +3,8 @@ package com.timsu.astrid.sync;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import android.app.Activity;
import android.app.ProgressDialog;
@ -40,16 +39,28 @@ public abstract class SynchronizationService {
this.id = id;
}
// called off the UI thread. does some setup
void synchronizeService(final Activity activity) {
progressDialog = ProgressDialog.show(activity, "Synchronization",
"Checking Authorization...");
new Thread(new Runnable() {
syncHandler.post(new Runnable() {
@Override
public void run() {
synchronize(activity);
progressDialog = new ProgressDialog(activity);
progressDialog.setIcon(android.R.drawable.ic_dialog_alert);
progressDialog.setTitle("Synchronization");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(100);
progressDialog.setMessage("Checking Authorization...");
progressDialog.setProgress(0);
progressDialog.show();
}
}).start();;
});
synchronize(activity);
syncHandler.post(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
});
}
/** Synchronize with the service */
@ -137,18 +148,18 @@ public abstract class SynchronizationService {
TagController tagController = Synchronizer.getTagController(activity);
// get data out of the database (note we get non-completed tasks only)
Set<SyncMapping> mappings = syncController.getSyncMapping(getId());
Set<TaskIdentifier> localTasks = taskController.getActiveTaskIdentifiers();
Map<TagIdentifier, TagModelForView> tags =
HashSet<SyncMapping> mappings = syncController.getSyncMapping(getId());
HashSet<TaskIdentifier> localTasks = taskController.getActiveTaskIdentifiers();
HashMap<TagIdentifier, TagModelForView> tags =
tagController.getAllTagsAsMap(activity);
// build local maps / lists
Map<String, SyncMapping> remoteIdToSyncMapping =
HashMap<String, SyncMapping> remoteIdToSyncMapping =
new HashMap<String, SyncMapping>();
Map<TaskIdentifier, SyncMapping> localIdToSyncMapping =
HashMap<TaskIdentifier, SyncMapping> localIdToSyncMapping =
new HashMap<TaskIdentifier, SyncMapping>();
Set<SyncMapping> localChanges = new HashSet<SyncMapping>();
Set<TaskIdentifier> mappedTasks = new HashSet<TaskIdentifier>();
HashSet<SyncMapping> localChanges = new HashSet<SyncMapping>();
HashSet<TaskIdentifier> mappedTasks = new HashSet<TaskIdentifier>();
for(SyncMapping mapping : mappings) {
if(mapping.isUpdated())
localChanges.add(mapping);
@ -158,7 +169,7 @@ public abstract class SynchronizationService {
}
// build remote map
Map<TaskIdentifier, TaskProxy> remoteChangeMap =
HashMap<TaskIdentifier, TaskProxy> remoteChangeMap =
new HashMap<TaskIdentifier, TaskProxy>();
for(TaskProxy remoteTask : remoteTasks) {
if(remoteIdToSyncMapping.containsKey(remoteTask.getRemoteId())) {
@ -175,11 +186,11 @@ public abstract class SynchronizationService {
progressDialog.setProgress(0);
}
});
Set<TaskIdentifier> newlyCreatedTasks = new HashSet<TaskIdentifier>(
HashSet<TaskIdentifier> newlyCreatedTasks = new HashSet<TaskIdentifier>(
localTasks);
newlyCreatedTasks.removeAll(mappedTasks);
for(TaskIdentifier taskId : newlyCreatedTasks) {
List<TagIdentifier> taskTags =
LinkedList<TagIdentifier> taskTags =
tagController.getTaskTags(activity, taskId);
String listName = null;
if(taskTags.size() > 0) {
@ -212,7 +223,7 @@ public abstract class SynchronizationService {
progressDialog.setProgress(0);
}
});
Set<TaskIdentifier> deletedTasks = new HashSet<TaskIdentifier>(mappedTasks);
HashSet<TaskIdentifier> deletedTasks = new HashSet<TaskIdentifier>(mappedTasks);
deletedTasks.removeAll(localTasks);
for(TaskIdentifier taskId : deletedTasks) {
SyncMapping mapping = localIdToSyncMapping.get(taskId);
@ -349,7 +360,7 @@ public abstract class SynchronizationService {
// --- helper classes
private class SyncStats {
protected class SyncStats {
int localCreatedTasks = 0;
int localUpdatedTasks = 0;
int localDeletedTasks = 0;
@ -401,7 +412,7 @@ public abstract class SynchronizationService {
this.outOf = outOf;
}
public void run() {
progressDialog.setProgress(10000*step/outOf);
progressDialog.setProgress(100*step/outOf);
}
}
}

@ -19,12 +19,15 @@ public class Synchronizer {
/** Synchronize all activated sync services */
public static void synchronize(final Activity activity) {
// sync services do cleanup themselves, so currently we only
// support one sync service at a time.
// RTM sync
if(Preferences.shouldSyncRTM(activity)) {
services.get(SYNC_ID_RTM).synchronizeService(activity);
}
closeControllers();
}
/** Clears tokens if services are disabled */
@ -72,7 +75,7 @@ public class Synchronizer {
private static TaskController taskController = null;
private static TagController tagController = null;
private static void closeControllers() {
static void closeControllers() {
if(syncController != null) {
syncController.close();
syncController = null;

@ -145,6 +145,11 @@ public class Preferences {
/** Set RTM Last Successful Sync Date */
public static void setSyncRTMLastSync(Context context, Date date) {
if(date == null) {
clearPref(context, P_SYNC_RTM_LAST_SYNC);
return;
}
Editor editor = getPrefs(context).edit();
editor.putLong(P_SYNC_RTM_LAST_SYNC, date.getTime());
editor.commit();

Loading…
Cancel
Save