From 64e2b7bc1484522ec6185042eb2156cc8d962547 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 31 Oct 2012 15:20:04 -0700 Subject: [PATCH] Refactor some indent logic --- .../astrid/subtasks/NewOrderedListUpdater.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java index c37e88851..a2b0f3d65 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/NewOrderedListUpdater.java @@ -150,8 +150,7 @@ public abstract class NewOrderedListUpdater { siblings.remove(index); node.parent = newParent; newParent.children.add(node); - node.indent = newParent.indent + 1; - adjustDescendantsIndent(node, node.indent); + setNodeIndent(node, newParent.indent + 1); } else if (delta < 0) { if (parent == treeRoot) // Can't deindent a top level item return; @@ -166,12 +165,16 @@ public abstract class NewOrderedListUpdater { int insertAfter = newSiblings.indexOf(parent); siblings.remove(index); node.parent = newParent; - node.indent = newParent.indent + 1; - adjustDescendantsIndent(node, node.indent); + setNodeIndent(node, newParent.indent + 1); newSiblings.add(insertAfter + 1, node); } } + private void setNodeIndent(Node node, int indent) { + node.indent = indent; + adjustDescendantsIndent(node, indent); + } + private void adjustDescendantsIndent(Node node, int baseIndent) { for (Node child : node.children) { child.indent = baseIndent + 1; @@ -212,7 +215,7 @@ public abstract class NewOrderedListUpdater { return; moveThis.parent = newParent; - moveThis.indent = moveThis.parent.indent + 1; + setNodeIndent(moveThis, newParent.indent + 1); oldSiblings.remove(moveThis); if (newSiblings == oldSiblings && beforeIndex > nodeIndex) { @@ -240,9 +243,8 @@ public abstract class NewOrderedListUpdater { siblings.remove(index); for (Node child : task.children) { child.parent = parent; - child.indent = parent.indent + 1; siblings.add(index, child); - adjustDescendantsIndent(child, child.indent); + setNodeIndent(child, parent.indent + 1); index++; } idToNode.remove(taskId);