Synchronize comment/history fetch callbacks

pull/14/head
Sam Bosley 12 years ago
parent f43a318f1e
commit ac6a3d2328

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

@ -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>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), done);
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true).execute();
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, done).execute();
}
}

@ -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>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback);
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true).execute();
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, callback).execute();
}
}

@ -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>(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), done);
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false).execute();
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false, done).execute();
}
}

@ -34,6 +34,7 @@ public class FetchHistory<TYPE extends RemoteModel> {
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<TYPE extends RemoteModel> {
private ActFmPreferenceService actFmPreferenceService;
public FetchHistory(RemoteModelDao<TYPE> 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<TYPE extends RemoteModel> {
this.taskTitle = taskTitle;
this.modifiedAfter = modifiedAfter;
this.includeTaskHistory = includeTaskHistory;
this.done = done;
}
@SuppressWarnings("nls")
@ -160,9 +162,13 @@ public class FetchHistory<TYPE extends RemoteModel> {
}
}
}
} catch (IOException e) {
Log.e(ERROR_TAG, "Error getting model history", e);
}
if (done != null)
done.run();
}
}).start();
}

@ -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>(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), callback);
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false).execute();
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), null, task.getValue(Task.HISTORY_FETCH_DATE), false, callback).execute();
}
private void addComment() {

Loading…
Cancel
Save