From c7e0b81dd78d57fac502ff6589f2a2f5a1c9afd8 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 13 Feb 2013 15:33:38 -0800 Subject: [PATCH] Some fixes to handling of task list metadata --- .../actfm/sync/messages/MakeChanges.java | 20 +++++++++++++++++++ .../astrid/subtasks/SubtasksListFragment.java | 5 +---- .../astrid/activity/TaskListFragment.java | 13 ++++++++++-- .../astrid/dao/TaskListMetadataDao.java | 1 + 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java index 83f7e1306..a8c256103 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java @@ -18,15 +18,19 @@ import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.sync.ActFmInvoker; import com.todoroo.astrid.core.PluginServices; +import com.todoroo.astrid.dao.HistoryDao; import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.dao.TagMetadataDao; +import com.todoroo.astrid.dao.TaskListMetadataDao; import com.todoroo.astrid.dao.UserActivityDao; +import com.todoroo.astrid.data.History; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.MetadataApiDao.MetadataCriteria; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagMetadata; +import com.todoroo.astrid.data.TaskListMetadata; import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.tags.TagService; @@ -258,6 +262,11 @@ public class MakeChanges extends ServerToClientMessage taskToTagTemplate.setValue(TaskToTagMetadata.TASK_UUID, toUuid); taskToTagTemplate.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); metadataService.update(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TASK_UUID.eq(fromUuid)), taskToTagTemplate); + + HistoryDao historyDao = PluginServices.getHistoryDao(); + History histTemplate = new History(); + histTemplate.setValue(History.TARGET_ID, toUuid); + historyDao.update(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(oldUuid)), histTemplate); } } @@ -345,6 +354,17 @@ public class MakeChanges extends ServerToClientMessage memberMetadataTemplate.setValue(TagMetadata.TAG_UUID, toUuid); memberMetadataTemplate.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); tagMetadataDao.update(TagMetadata.TAG_UUID.eq(fromUuid), memberMetadataTemplate); + + HistoryDao historyDao = PluginServices.getHistoryDao(); + History histTemplate = new History(); + histTemplate.setValue(History.TARGET_ID, toUuid); + historyDao.update(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(oldUuid)), histTemplate); + + TaskListMetadataDao taskListMetadataDao = PluginServices.getTaskListMetadataDao(); + TaskListMetadata tlm = new TaskListMetadata(); + tlm.setValue(TaskListMetadata.TAG_UUID, toUuid); + tlm.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); + taskListMetadataDao.update(TaskListMetadata.TAG_UUID.eq(fromUuid), tlm); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java index 99811f691..5c0c3c583 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksListFragment.java @@ -53,10 +53,7 @@ public class SubtasksListFragment extends TaskListFragment { @Override public void setUpTaskList() { if (helper instanceof AstridOrderedListFragmentHelper) { - if (isTodayFilter) - ((AstridOrderedListFragmentHelper) helper).setList(SubtasksUpdater.TODAY_TASKS_ORDER); - else if (isInbox) - ((AstridOrderedListFragmentHelper) helper).setList(SubtasksUpdater.ACTIVE_TASKS_ORDER); + ((AstridOrderedListFragmentHelper) helper).setList(taskListMetadata); } helper.beforeSetUpTaskList(filter); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 7c89ead02..0c64b6f0b 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -414,10 +414,19 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, TagData td = getActiveTagData(); String tdId; if (td == null) { + String filterId = null; if (isInbox) - taskListMetadata = taskListMetadataDao.fetchByTagId(TaskListMetadata.FILTER_ID_ALL, TaskListMetadata.PROPERTIES); + filterId = TaskListMetadata.FILTER_ID_ALL; else if (isTodayFilter) - taskListMetadata = taskListMetadataDao.fetchByTagId(TaskListMetadata.FILTER_ID_TODAY, TaskListMetadata.PROPERTIES); + filterId = TaskListMetadata.FILTER_ID_TODAY; + if (!TextUtils.isEmpty(filterId)) { + taskListMetadata = taskListMetadataDao.fetchByTagId(filterId, TaskListMetadata.PROPERTIES); + if (taskListMetadata == null) { + taskListMetadata = new TaskListMetadata(); + taskListMetadata.setValue(TaskListMetadata.FILTER, filterId); + taskListMetadataDao.createNew(taskListMetadata); + } + } } else { tdId = td.getUuid(); taskListMetadata = taskListMetadataDao.fetchByTagId(td.getUuid(), TaskListMetadata.PROPERTIES); diff --git a/astrid/src/com/todoroo/astrid/dao/TaskListMetadataDao.java b/astrid/src/com/todoroo/astrid/dao/TaskListMetadataDao.java index 216b64476..151b0e7fc 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskListMetadataDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskListMetadataDao.java @@ -40,6 +40,7 @@ public class TaskListMetadataDao extends RemoteModelDao { public TaskListMetadata fetchByTagId(String tagUuid, Property...properties) { TodorooCursor taskListMetadata = query(Query.select(properties).where(Criterion.or(TaskListMetadata.TAG_UUID.eq(tagUuid), TaskListMetadata.FILTER.eq(tagUuid)))); + taskListMetadata.moveToFirst(); return returnFetchResult(taskListMetadata); }