Fixed bugs relating to indentation and list refreshing

pull/14/head
Sam Bosley 12 years ago
parent 4c7139a7ce
commit fe79994c6a

@ -136,7 +136,9 @@ public class NewOrderedListFragmentHelper<LIST> {
Log.e("drag", "Drag Error", e); //$NON-NLS-1$ //$NON-NLS-2$ Log.e("drag", "Drag Error", e); //$NON-NLS-1$ //$NON-NLS-2$
} }
updater.writeSerialization(list, updater.serializeTree()); updater.writeSerialization(list, updater.serializeTree());
fragment.setUpTaskList(); updater.applyToFilter(getFilter());
fragment.reconstructCursor();
fragment.loadTaskListContent(true);
} }
}; };
@ -160,7 +162,9 @@ public class NewOrderedListFragmentHelper<LIST> {
Log.e("drag", "Indent Error", e); //$NON-NLS-1$ //$NON-NLS-2$ Log.e("drag", "Indent Error", e); //$NON-NLS-1$ //$NON-NLS-2$
} }
updater.writeSerialization(list, updater.serializeTree()); updater.writeSerialization(list, updater.serializeTree());
fragment.setUpTaskList(); updater.applyToFilter(getFilter());
fragment.reconstructCursor();
fragment.loadTaskListContent(true);
} }
}; };

@ -151,6 +151,7 @@ public abstract class NewOrderedListUpdater<LIST> {
node.parent = newParent; node.parent = newParent;
newParent.children.add(node); newParent.children.add(node);
node.indent = newParent.indent + 1; node.indent = newParent.indent + 1;
adjustDescendantsIndent(node, node.indent);
} else if (delta < 0) { } else if (delta < 0) {
if (parent == treeRoot) // Can't deindent a top level item if (parent == treeRoot) // Can't deindent a top level item
return; return;
@ -166,10 +167,18 @@ public abstract class NewOrderedListUpdater<LIST> {
siblings.remove(index); siblings.remove(index);
node.parent = newParent; node.parent = newParent;
node.indent = newParent.indent + 1; node.indent = newParent.indent + 1;
adjustDescendantsIndent(node, node.indent);
newSiblings.add(insertAfter + 1, node); 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) { public void moveTo(long targetTaskId, long beforeTaskId) {
Node target = idToNode.get(targetTaskId); Node target = idToNode.get(targetTaskId);
if (target == null) if (target == null)
@ -194,13 +203,22 @@ public abstract class NewOrderedListUpdater<LIST> {
Node newParent = beforeThis.parent; Node newParent = beforeThis.parent;
ArrayList<Node> newSiblings = newParent.children; ArrayList<Node> newSiblings = newParent.children;
int index = newSiblings.indexOf(beforeThis); int beforeIndex = newSiblings.indexOf(beforeThis);
if (index < 0) if (beforeIndex < 0)
return;
int nodeIndex = oldSiblings.indexOf(moveThis);
if (nodeIndex < 0)
return; return;
moveThis.parent = newParent; moveThis.parent = newParent;
moveThis.indent = moveThis.parent.indent + 1;
oldSiblings.remove(moveThis); oldSiblings.remove(moveThis);
newSiblings.add(index, moveThis);
if (newSiblings == oldSiblings && beforeIndex > nodeIndex) {
beforeIndex--;
}
newSiblings.add(beforeIndex, moveThis);
} }
private void moveToEndOfList(Node moveThis) { private void moveToEndOfList(Node moveThis) {

@ -895,11 +895,34 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
* @param withCustomId * @param withCustomId
* force task with given custom id to be part of list * force task with given custom id to be part of list
*/ */
@SuppressWarnings("nls")
public void setUpTaskList() { public void setUpTaskList() {
if (filter == null) if (filter == null)
return; return;
TodorooCursor<Task> 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<Task> constructCursor() {
String tagName = null; String tagName = null;
if (getActiveTagData() != null) if (getActiveTagData() != null)
tagName = getActiveTagData().getValue(TagData.NAME); tagName = getActiveTagData().getValue(TagData.NAME);
@ -936,35 +959,24 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
groupedQuery = sqlQueryTemplate.get() + " GROUP BY " + Task.ID; groupedQuery = sqlQueryTemplate.get() + " GROUP BY " + Task.ID;
sqlQueryTemplate.set(groupedQuery); sqlQueryTemplate.set(groupedQuery);
// perform query // Peform query
TodorooCursor<Task> currentCursor;
try { try {
currentCursor = taskService.fetchFiltered( return taskService.fetchFiltered(
sqlQueryTemplate.get(), null, taskProperties()); sqlQueryTemplate.get(), null, taskProperties());
} catch (SQLiteException e) { } catch (SQLiteException e) {
// We don't show this error anymore--seems like this can get triggered // 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. // by a strange bug, but there seems to not be any negative side effect.
// For now, we'll suppress the error // For now, we'll suppress the error
// See http://astrid.com/home#tags-7tsoi/task-1119pk // 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() { public void reconstructCursor() {
return filter; TodorooCursor<Task> cursor = constructCursor();
if (cursor == null)
return;
taskAdapter.changeCursor(cursor);
} }
/** /**

Loading…
Cancel
Save