diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListFragmentHelper.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListFragmentHelper.java index e95d100f9..7bd5f8ce8 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListFragmentHelper.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListFragmentHelper.java @@ -136,7 +136,9 @@ public class NewOrderedListFragmentHelper { Log.e("drag", "Drag Error", e); //$NON-NLS-1$ //$NON-NLS-2$ } updater.writeSerialization(list, updater.serializeTree()); - fragment.setUpTaskList(); + updater.applyToFilter(getFilter()); + fragment.reconstructCursor(); + fragment.loadTaskListContent(true); } }; @@ -160,7 +162,9 @@ public class NewOrderedListFragmentHelper { Log.e("drag", "Indent Error", e); //$NON-NLS-1$ //$NON-NLS-2$ } updater.writeSerialization(list, updater.serializeTree()); - fragment.setUpTaskList(); + updater.applyToFilter(getFilter()); + fragment.reconstructCursor(); + fragment.loadTaskListContent(true); } }; diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java index a90e6c809..f98ca76d6 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java @@ -151,6 +151,7 @@ public abstract class NewOrderedListUpdater { node.parent = newParent; newParent.children.add(node); node.indent = newParent.indent + 1; + adjustDescendantsIndent(node, node.indent); } else if (delta < 0) { if (parent == treeRoot) // Can't deindent a top level item return; @@ -166,10 +167,18 @@ public abstract class NewOrderedListUpdater { siblings.remove(index); node.parent = newParent; node.indent = newParent.indent + 1; + adjustDescendantsIndent(node, node.indent); newSiblings.add(insertAfter + 1, node); } } + private void adjustDescendantsIndent(Node node, int baseIndent) { + for (Node child : node.children) { + child.indent = baseIndent + 1; + adjustDescendantsIndent(child, child.indent); + } + } + public void moveTo(long targetTaskId, long beforeTaskId) { Node target = idToNode.get(targetTaskId); if (target == null) @@ -194,13 +203,22 @@ public abstract class NewOrderedListUpdater { Node newParent = beforeThis.parent; ArrayList newSiblings = newParent.children; - int index = newSiblings.indexOf(beforeThis); - if (index < 0) + int beforeIndex = newSiblings.indexOf(beforeThis); + if (beforeIndex < 0) + return; + + int nodeIndex = oldSiblings.indexOf(moveThis); + if (nodeIndex < 0) return; moveThis.parent = newParent; + moveThis.indent = moveThis.parent.indent + 1; oldSiblings.remove(moveThis); - newSiblings.add(index, moveThis); + + if (newSiblings == oldSiblings && beforeIndex > nodeIndex) { + beforeIndex--; + } + newSiblings.add(beforeIndex, moveThis); } private void moveToEndOfList(Node moveThis) { diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 4f69c6a14..76b56a802 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -895,11 +895,34 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, * @param withCustomId * force task with given custom id to be part of list */ - @SuppressWarnings("nls") public void setUpTaskList() { if (filter == null) return; + TodorooCursor currentCursor = constructCursor(); + if (currentCursor == null) + return; + + // set up list adapters + taskAdapter = createTaskAdapter(currentCursor); + + setListAdapter(taskAdapter); + getListView().setOnScrollListener(this); + registerForContextMenu(getListView()); + + loadTaskListContent(true); + } + + public Property[] taskProperties() { + return TaskAdapter.PROPERTIES; + } + + public Filter getFilter() { + return filter; + } + + @SuppressWarnings("nls") + private TodorooCursor constructCursor() { String tagName = null; if (getActiveTagData() != null) tagName = getActiveTagData().getValue(TagData.NAME); @@ -936,35 +959,24 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, groupedQuery = sqlQueryTemplate.get() + " GROUP BY " + Task.ID; sqlQueryTemplate.set(groupedQuery); - // perform query - TodorooCursor currentCursor; + // Peform query try { - currentCursor = taskService.fetchFiltered( + return taskService.fetchFiltered( sqlQueryTemplate.get(), null, taskProperties()); } catch (SQLiteException e) { // We don't show this error anymore--seems like this can get triggered // by a strange bug, but there seems to not be any negative side effect. // For now, we'll suppress the error // See http://astrid.com/home#tags-7tsoi/task-1119pk - return; + return null; } - - // set up list adapters - taskAdapter = createTaskAdapter(currentCursor); - - setListAdapter(taskAdapter); - getListView().setOnScrollListener(this); - registerForContextMenu(getListView()); - - loadTaskListContent(true); } - public Property[] taskProperties() { - return TaskAdapter.PROPERTIES; - } - - public Filter getFilter() { - return filter; + public void reconstructCursor() { + TodorooCursor cursor = constructCursor(); + if (cursor == null) + return; + taskAdapter.changeCursor(cursor); } /**