Fixed the last known ordering bugs

pull/14/head
Sam Bosley 14 years ago
parent e6f9e0bf44
commit ae04a726a6

@ -47,7 +47,11 @@ public class GtasksListActivity extends DraggableTaskListActivity {
public void drop(int from, int to) {
long targetTaskId = taskAdapter.getItemId(from);
long destinationTaskId = taskAdapter.getItemId(to);
gtasksTaskListUpdater.moveTo(targetTaskId, destinationTaskId);
if(to == getListView().getCount() - 1)
gtasksTaskListUpdater.moveTo(targetTaskId, -1);
else
gtasksTaskListUpdater.moveTo(targetTaskId, destinationTaskId);
gtasksSyncOnSaveService.triggerMoveForMetadata(gtasksMetadataService.getTaskMetadata(targetTaskId));
loadTaskListContent(true);
}

@ -70,7 +70,6 @@ public class GtasksTaskListUpdater {
long newParent = computeNewParent(listRef.get(), taskId, indent + delta - 1);
if (newParent == taskId) {
System.err.println("Tried to set parent to self");
metadata.setValue(GtasksMetadata.PARENT_TASK, Task.NO_ID);
} else {
metadata.setValue(GtasksMetadata.PARENT_TASK, newParent);
@ -131,7 +130,7 @@ public class GtasksTaskListUpdater {
private static class Node {
public final long taskId;
public final Node parent;
public Node parent;
public final ArrayList<Node> children = new ArrayList<Node>();
public Node(long taskId, Node parent) {
@ -155,22 +154,26 @@ public class GtasksTaskListUpdater {
return;
Node root = buildTreeModel(list);
debugPrint(root, 0);
Node target = findNode(root, targetTaskId);
if(target != null && target.parent != null) {
if(moveBeforeTaskId == -1) {
target.parent.children.remove(target);
root.children.add(target);
target.parent = root;
} else {
Node sibling = findNode(root, moveBeforeTaskId);
if(sibling != null) {
int index = sibling.parent.children.indexOf(sibling);
target.parent.children.remove(target);
sibling.parent.children.add(index, target);
target.parent = sibling.parent;
}
}
}
debugPrint(root, 0);
traverseTreeAndWriteValues(root, new AtomicLong(0), -1);
}
@ -224,6 +227,8 @@ public class GtasksTaskListUpdater {
Node node = currentNode.get().parent;
for(int i = indent; i < previousIndentValue; i++)
node = node.parent;
if(node == null)
node = root;
currentNode.set(new Node(taskId, node));
node.children.add(currentNode.get());
}
@ -251,6 +256,15 @@ public class GtasksTaskListUpdater {
});
}
public void debugPrint(Node root, int depth) {
for(int i = 0; i < depth; i++) System.err.print(" + ");
System.err.format("%03d", root.taskId);
System.err.print("\n");
for(int i = 0; i < root.children.size(); i++)
debugPrint(root.children.get(i), depth + 1);
}
private final Task taskContainer = new Task();
private void saveAndUpdateModifiedDate(Metadata metadata, long taskId) {

Loading…
Cancel
Save