diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java index 872e4c95d..39c89f0e6 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java @@ -266,13 +266,14 @@ public abstract class CommentsFragment extends ListFragment { Runnable doneRunnable = new Runnable() { @Override public void run() { - refreshUpdatesList(); + synchronized (this) { + refreshUpdatesList(); + } } }; if (hasModel()) { performFetch(manual, doneRunnable); } else { -// actFmSyncService.fetchPersonalUpdates(manual, doneRunnable); doneRunnable.run(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java index efc6be4ff..acf8320d5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java @@ -129,7 +129,7 @@ public class TagCommentsFragment extends CommentsFragment { protected void performFetch(boolean manual, Runnable done) { if (tagData != null) { ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), done); - new FetchHistory(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true).execute(); + new FetchHistory(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, done).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index 7fdf6be1b..80298c2d0 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -341,22 +341,24 @@ public class TagViewFragment extends TaskListFragment { Runnable callback = new Runnable() { @Override public void run() { - Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - reloadTagData(false); - refresh(); - ((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.TLA_no_items); - } - }); + synchronized(this) { + Activity activity = getActivity(); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + reloadTagData(false); + refresh(); + ((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.TLA_no_items); + } + }); + } } } }; ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback); - new FetchHistory(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true).execute(); + new FetchHistory(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, callback).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java index a5e0de47f..da2bec6e5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java @@ -82,7 +82,7 @@ public class TaskCommentsFragment extends CommentsFragment { protected void performFetch(boolean manual, Runnable done) { if (task != null) { ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), done); - new FetchHistory(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false).execute(); + new FetchHistory(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false, done).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java index f6af15f20..5d7e4b4ec 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java @@ -34,6 +34,7 @@ public class FetchHistory { private final String taskTitle; private final long modifiedAfter; private final boolean includeTaskHistory; + private final Runnable done; @Autowired private ActFmInvoker actFmInvoker; @@ -48,7 +49,7 @@ public class FetchHistory { private ActFmPreferenceService actFmPreferenceService; public FetchHistory(RemoteModelDao dao, LongProperty historyTimeProperty, - String table, String uuid, String taskTitle, long modifiedAfter, boolean includeTaskHistory) { + String table, String uuid, String taskTitle, long modifiedAfter, boolean includeTaskHistory, Runnable done) { DependencyInjectionService.getInstance().inject(this); this.dao = dao; this.historyTimeProperty = historyTimeProperty; @@ -57,6 +58,7 @@ public class FetchHistory { this.taskTitle = taskTitle; this.modifiedAfter = modifiedAfter; this.includeTaskHistory = includeTaskHistory; + this.done = done; } @SuppressWarnings("nls") @@ -160,9 +162,13 @@ public class FetchHistory { } } } + } catch (IOException e) { Log.e(ERROR_TAG, "Error getting model history", e); } + + if (done != null) + done.run(); } }).start(); } diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index 83d55356b..5249e946e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -408,21 +408,23 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene Runnable callback = new Runnable() { @Override public void run() { - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - setUpListAdapter(); - loadingText.setText(R.string.ENA_no_comments); - loadingText.setVisibility(items.size() == 0 ? View.VISIBLE : View.GONE); - } - }); + synchronized(this) { + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + setUpListAdapter(); + loadingText.setText(R.string.ENA_no_comments); + loadingText.setVisibility(items.size() == 0 ? View.VISIBLE : View.GONE); + } + }); + } } } }; ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), callback); - new FetchHistory(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false).execute(); + new FetchHistory(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false, callback).execute(); } private void addComment() {