Manual ordering seems to be sort of working, bugs may still exist

pull/14/head
Sam Bosley 12 years ago
parent 13d85be8e8
commit 5ed0555280

@ -114,6 +114,10 @@ public final class TagData extends RemoteModel {
public static final StringProperty TAG_DESCRIPTION = new StringProperty(
TABLE, "tagDescription");
/** Tag ordering */
public static final StringProperty TAG_ORDERING = new StringProperty(
TABLE, "tagOrdering");
/** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TagData.class);

@ -6,7 +6,7 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timsu.astrid"
android:versionName="4.4.1"
android:versionName="4.4.1-subtasks"
android:versionCode="286">
<!-- widgets, alarms, and services will break if Astrid is installed on SD card -->

@ -135,8 +135,8 @@ public class NewOrderedListFragmentHelper<LIST> {
} catch (Exception e) {
Log.e("drag", "Drag Error", e); //$NON-NLS-1$ //$NON-NLS-2$
}
fragment.loadTaskListContent(true);
updater.writeSerialization(list, updater.serializeTree());
fragment.setUpTaskList();
}
};
@ -159,7 +159,8 @@ public class NewOrderedListFragmentHelper<LIST> {
} catch (Exception e) {
Log.e("drag", "Indent Error", e); //$NON-NLS-1$ //$NON-NLS-2$
}
fragment.loadTaskListContent(true);
updater.writeSerialization(list, updater.serializeTree());
fragment.setUpTaskList();
}
};

@ -10,12 +10,18 @@ import org.json.JSONObject;
import android.util.Log;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
public abstract class NewOrderedListUpdater<LIST> {
@Autowired
private TaskService taskService;
public NewOrderedListUpdater() {
DependencyInjectionService.getInstance().inject(this);
idToNode = new HashMap<Long, Node>();
@ -42,8 +48,9 @@ public abstract class NewOrderedListUpdater<LIST> {
private final HashMap<Long, Node> idToNode;
protected abstract String getSerializedTree(LIST list);
protected abstract String getSerializedTree(LIST list, Filter filter);
protected abstract void writeSerialization(LIST list, String serialized);
protected abstract void applyToFilter(Filter filter);
public int getIndentForTask(long targetTaskId) {
Node n = idToNode.get(targetTaskId);
@ -53,7 +60,26 @@ public abstract class NewOrderedListUpdater<LIST> {
}
protected void initialize(LIST list, Filter filter) {
treeRoot = buildTreeModel(getSerializedTree(list));
treeRoot = buildTreeModel(getSerializedTree(list, filter));
}
protected String serializedTreeFromFilter(Filter filter) {
JSONArray array = new JSONArray();
TodorooCursor<Task> tasks = taskService.fetchFiltered(filter.getSqlQuery(), null, Task.ID);
try {
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
try {
JSONObject curr = new JSONObject();
curr.put(Long.toString(tasks.getLong(0)), new JSONArray());
array.put(curr);
} catch (JSONException e) {
e.printStackTrace();
}
}
} finally {
tasks.close();
}
return array.toString();
}
public Long[] getOrderedIds() {
@ -162,15 +188,19 @@ public abstract class NewOrderedListUpdater<LIST> {
}
private void moveHelper(Node moveThis, Node beforeThis) {
Node parent = beforeThis.parent;
ArrayList<Node> siblings = parent.children;
Node oldParent = moveThis.parent;
ArrayList<Node> oldSiblings = oldParent.children;
Node newParent = beforeThis.parent;
ArrayList<Node> newSiblings = newParent.children;
int index = siblings.indexOf(beforeThis);
int index = newSiblings.indexOf(beforeThis);
if (index < 0)
return;
moveThis.parent = parent;
siblings.add(index, moveThis);
moveThis.parent = newParent;
oldSiblings.remove(moveThis);
newSiblings.add(index, moveThis);
}
private void moveToEndOfList(Node moveThis) {

@ -52,7 +52,7 @@ public class SubtasksListFragment extends TaskListFragment {
}
@Override
protected void setUpTaskList() {
public void setUpTaskList() {
helper.beforeSetUpTaskList(filter);
super.setUpTaskList();

@ -49,7 +49,7 @@ public class SubtasksTagListFragment extends TagViewFragment {
}
@Override
protected void setUpTaskList() {
public void setUpTaskList() {
helper.beforeSetUpTaskList(filter);
super.setUpTaskList();

@ -25,32 +25,40 @@ public class SubtasksUpdater extends NewOrderedListUpdater<TagData> {
@Override
protected void initialize(TagData list, Filter filter) {
super.initialize(list, filter);
applySubtasksToFilter(filter);
applyToFilter(filter);
}
@Override
@SuppressWarnings("nls")
public void applySubtasksToFilter(Filter filter) {
public void applyToFilter(Filter filter) {
String query = filter.getSqlQuery();
query = query.replaceAll("ORDER BY .*", "");
query = query + String.format(" ORDER BY %s, %s, %s, %s)",
query = query + String.format(" ORDER BY %s, %s, %s, %s",
Task.DELETION_DATE, Task.COMPLETION_DATE,
getOrderString(), Task.CREATION_DATE);
query = query.replace(TaskCriteria.isVisible().toString(),
Criterion.all.toString());
System.err.println("QUERY: " + query);
filter.setFilterQueryOverride(query);
}
@Override
protected String getSerializedTree(TagData list) {
protected String getSerializedTree(TagData list, Filter filter) {
String order;
if (list == null) {
String order = Preferences.getStringValue(ACTIVE_TASKS_ORDER);
order = Preferences.getStringValue(ACTIVE_TASKS_ORDER);
if (order == null)
order = "{}"; //$NON-NLS-1$
return order;
order = "[]"; //$NON-NLS-1$
} else {
order = list.getValue(TagData.TAG_ORDERING);
}
if (order == null || "[]".equals(order)) { //$NON-NLS-1$
order = serializedTreeFromFilter(filter);
writeSerialization(list, order);
}
return list.getValue(TagData.NAME);
return order;
}
@Override
@ -58,7 +66,7 @@ public class SubtasksUpdater extends NewOrderedListUpdater<TagData> {
if (list == null)
Preferences.setString(ACTIVE_TASKS_ORDER, serialized);
else {
list.setValue(TagData.NAME, serialized);
list.setValue(TagData.TAG_ORDERING, serialized);
tagDataService.save(list);
}
}

@ -896,7 +896,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
* force task with given custom id to be part of list
*/
@SuppressWarnings("nls")
protected void setUpTaskList() {
public void setUpTaskList() {
if (filter == null)
return;

@ -40,7 +40,7 @@ public class Database extends AbstractDatabase {
* Database version number. This variable must be updated when database
* tables are updated, as it determines whether a database needs updating.
*/
public static final int VERSION = 26;
public static final int VERSION = 27;
/**
* Database name (must be unique)
@ -339,6 +339,12 @@ public class Database extends AbstractDatabase {
} catch (SQLiteException e) {
Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e);
}
case 26: try {
database.execSQL("ALTER TABLE " + TagData.TABLE.name + " ADD " +
TagData.TAG_ORDERING.accept(visitor, null));
} catch (SQLiteException e) {
Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e);
}
return true;
}

Loading…
Cancel
Save