diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java index 4d88a2614..0a41ddb01 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java @@ -8,6 +8,7 @@ import java.util.concurrent.atomic.AtomicReference; import android.app.Activity; import android.database.Cursor; +import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; @@ -21,6 +22,9 @@ import com.timsu.astrid.R; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; +import com.todoroo.andlib.sql.Criterion; +import com.todoroo.andlib.sql.Functions; +import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; @@ -263,14 +267,6 @@ public class AstridOrderedListFragmentHelper implements OrderedListFragmen updater.applyToDescendants(itemId, new AstridOrderedListUpdater.OrderedListNodeVisitor() { @Override public void visitNode(AstridOrderedListUpdater.Node node) { -// Task childTask = taskService.fetchById(node.taskId, Task.RECURRENCE); -// -// if(!TextUtils.isEmpty(childTask.getValue(Task.RECURRENCE))) { -// Metadata metadata = updater.getTaskMetadata(list, node.taskId); -// metadata.setValue(updater.indentProperty(), parentIndent); -// metadataService.save(metadata); -// } - model.setId(node.taskId); model.setValue(Task.COMPLETION_DATE, completionDate); taskService.save(model); @@ -282,6 +278,30 @@ public class AstridOrderedListFragmentHelper implements OrderedListFragmen }); if(chained.size() > 0) { + // move recurring items to item parent + TodorooCursor recurring = taskService.query(Query.select(Task.ID, Task.RECURRENCE).where( + Criterion.and(Task.ID.in(chained.toArray(new Long[chained.size()])), + Task.RECURRENCE.isNotNull(), Functions.length(Task.RECURRENCE).gt(0)))); + try { + Task t = new Task(); + boolean madeChanges = false; + for (recurring.moveToFirst(); !recurring.isAfterLast(); recurring.moveToNext()) { + t.clear(); + t.readFromCursor(recurring); + if (!TextUtils.isEmpty(t.getValue(Task.RECURRENCE))) { + updater.moveToParentOf(t.getId(), itemId); + madeChanges = true; + } + } + + if (madeChanges) { + updater.writeSerialization(list, updater.serializeTree()); + } + } finally { + recurring.close(); + } + + chainedCompletions.put(itemId, chained); taskAdapter.notifyDataSetInvalidated(); } diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListUpdater.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListUpdater.java index c4c0a5ccb..fc63c8fc6 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListUpdater.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/AstridOrderedListUpdater.java @@ -227,6 +227,24 @@ public abstract class AstridOrderedListUpdater { moveHelper(list, filter, target, before); } + public void moveToParentOf(long moveThis, long toParentOfThis) { + Node target = idToNode.get(toParentOfThis); + if (target == null) + return; + + Node toMove = idToNode.get(moveThis); + if (toMove == null) + return; + + Node newParent = target.parent; + Node oldParent = toMove.parent; + + oldParent.children.remove(toMove); + toMove.parent = newParent; + newParent.children.add(toMove); + setNodeIndent(toMove, toMove.parent.indent + 1); + } + private void moveHelper(LIST list, Filter filter, Node moveThis, Node beforeThis) { Node oldParent = moveThis.parent; ArrayList oldSiblings = oldParent.children;