More new logic for keeping track of if last history request had more data

pull/14/head
Sam Bosley 12 years ago
parent 34db0fc9fd
commit 1b393dfea0

@ -130,7 +130,8 @@ public class TagCommentsFragment extends CommentsFragment {
protected void performFetch(boolean manual, SyncMessageCallback done) { protected void performFetch(boolean manual, SyncMessageCallback done) {
if (tagData != null) { if (tagData != null) {
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), done); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), done);
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, done).execute(); new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, TagData.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TAGS,
tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), 0, true, done).execute();
} }
} }

@ -456,7 +456,8 @@ public class TagViewFragment extends TaskListFragment {
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TaskListMetadata>(TaskListMetadata.class, null, tagData.getValue(TagData.METADATA_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TaskListMetadata>(TaskListMetadata.class, null, tagData.getValue(TagData.METADATA_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback);
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, null).execute(); new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, TagData.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TAGS,
tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), 0, true, null).execute();
} }
} }

@ -83,7 +83,8 @@ public class TaskCommentsFragment extends CommentsFragment {
protected void performFetch(boolean manual, SyncMessageCallback done) { protected void performFetch(boolean manual, SyncMessageCallback done) {
if (task != null) { if (task != null) {
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), done); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), done);
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), false, done).execute(); new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, Task.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TASKS,
task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), 0, false, done).execute();
} }
} }

@ -10,6 +10,7 @@ import org.json.JSONObject;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
@ -29,10 +30,12 @@ public class FetchHistory<TYPE extends RemoteModel> {
private final RemoteModelDao<TYPE> dao; private final RemoteModelDao<TYPE> dao;
private final LongProperty historyTimeProperty; private final LongProperty historyTimeProperty;
private final IntegerProperty historyHasMoreProperty;
private final String table; private final String table;
private final String uuid; private final String uuid;
private final String taskTitle; private final String taskTitle;
private final long modifiedAfter; private final long modifiedAfter;
private final int offset;
private final boolean includeTaskHistory; private final boolean includeTaskHistory;
private final SyncMessageCallback done; private final SyncMessageCallback done;
@ -48,15 +51,17 @@ public class FetchHistory<TYPE extends RemoteModel> {
@Autowired @Autowired
private ActFmPreferenceService actFmPreferenceService; private ActFmPreferenceService actFmPreferenceService;
public FetchHistory(RemoteModelDao<TYPE> dao, LongProperty historyTimeProperty, public FetchHistory(RemoteModelDao<TYPE> dao, LongProperty historyTimeProperty, IntegerProperty historyHasMoreProperty,
String table, String uuid, String taskTitle, long modifiedAfter, boolean includeTaskHistory, SyncMessageCallback done) { String table, String uuid, String taskTitle, long modifiedAfter, int offset, boolean includeTaskHistory, SyncMessageCallback done) {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
this.dao = dao; this.dao = dao;
this.historyTimeProperty = historyTimeProperty; this.historyTimeProperty = historyTimeProperty;
this.historyHasMoreProperty = historyHasMoreProperty;
this.table = table; this.table = table;
this.uuid = uuid; this.uuid = uuid;
this.taskTitle = taskTitle; this.taskTitle = taskTitle;
this.modifiedAfter = modifiedAfter; this.modifiedAfter = modifiedAfter;
this.offset = offset;
this.includeTaskHistory = includeTaskHistory; this.includeTaskHistory = includeTaskHistory;
this.done = done; this.done = done;
} }
@ -88,11 +93,19 @@ public class FetchHistory<TYPE extends RemoteModel> {
params.add("modified_after"); params.add(modifiedAfter / 1000L); params.add("modified_after"); params.add(modifiedAfter / 1000L);
} }
if (offset > 0) {
params.add("offset"); params.add(offset);
}
params.add("token"); params.add(token); params.add("token"); params.add(token);
try { try {
JSONObject result = actFmInvoker.invoke("model_history_list", params.toArray(new Object[params.size()])); JSONObject result = actFmInvoker.invoke("model_history_list", params.toArray(new Object[params.size()]));
JSONArray list = result.optJSONArray("list"); JSONArray list = result.optJSONArray("list");
boolean hasMore = result.optBoolean("has_more");
long time = result.optLong("time") * 1000; long time = result.optLong("time") * 1000;
if (hasMore && offset == 0) {
historyDao.deleteWhere(History.TARGET_ID.eq(uuid));
}
if (list != null) { if (list != null) {
for (int i = 0; i < list.length(); i++) { for (int i = 0; i < list.length(); i++) {
JSONObject historyJson = list.optJSONObject(i); JSONObject historyJson = list.optJSONObject(i);
@ -129,6 +142,7 @@ public class FetchHistory<TYPE extends RemoteModel> {
try { try {
template = dao.getModelClass().newInstance(); template = dao.getModelClass().newInstance();
template.setValue(historyTimeProperty, time); template.setValue(historyTimeProperty, time);
template.setValue(historyHasMoreProperty, hasMore ? 1 : 0);
dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), template); dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), template);
} catch (InstantiationException e) { } catch (InstantiationException e) {
Log.e(ERROR_TAG, "Error instantiating model for recording time", e); Log.e(ERROR_TAG, "Error instantiating model for recording time", e);

@ -152,9 +152,13 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
return R.drawable.camera_button; return R.drawable.camera_button;
} }
private void fetchTask(long id) {
task = PluginServices.getTaskService().fetchById(id, Task.NOTES, Task.ID, Task.UUID, Task.TITLE, Task.HISTORY_FETCH_DATE, Task.HISTORY_HAS_MORE, Task.USER_ACTIVITIES_PUSHED_AT, Task.ATTACHMENTS_PUSHED_AT);
}
public void loadViewForTaskID(long t){ public void loadViewForTaskID(long t){
try { try {
task = PluginServices.getTaskService().fetchById(t, Task.NOTES, Task.ID, Task.UUID, Task.TITLE, Task.HISTORY_FETCH_DATE, Task.USER_ACTIVITIES_PUSHED_AT, Task.ATTACHMENTS_PUSHED_AT); fetchTask(t);
} catch (SQLiteException e) { } catch (SQLiteException e) {
StartupService.handleSQLiteError(ContextManager.getContext(), e); StartupService.handleSQLiteError(ContextManager.getContext(), e);
} }
@ -421,7 +425,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
public void run() { public void run() {
if (task == null) if (task == null)
return; return;
task = PluginServices.getTaskService().fetchById(task.getId(), Task.NOTES, Task.ID, Task.UUID, Task.TITLE, Task.HISTORY_FETCH_DATE, Task.USER_ACTIVITIES_PUSHED_AT, Task.ATTACHMENTS_PUSHED_AT); fetchTask(task.getId());
if (task == null) if (task == null)
return; return;
setUpListAdapter(); setUpListAdapter();
@ -438,7 +442,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TaskAttachment>(TaskAttachment.class, null, task.getValue(Task.ATTACHMENTS_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TaskAttachment>(TaskAttachment.class, null, task.getValue(Task.ATTACHMENTS_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback);
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), false, callback).execute(); new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, Task.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TASKS,
task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), 0, false, callback).execute();
} }
private void addComment() { private void addComment() {

Loading…
Cancel
Save