Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Added new Sort order: ID descending
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Jan 31, 2011
1 parent 21fa49c commit f226cbd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 6 additions & 5 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string-array name="sort">
<item>Priority</item>
<item>Id</item>
<item>Text (A-Z)</item>
</string-array>
<string-array name="sort">
<item>Priority</item>
<item>ID Ascending</item>
<item>ID Descending</item>
<item>Text (A-Z)</item>
</string-array>

</resources>
13 changes: 12 additions & 1 deletion src/com/todotxt/todotxttouch/TaskHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class TaskHelper {
private final static Pattern contextPattern = Pattern
.compile("(?:^|\\s)@(\\S*\\w)");

private final static Pattern projectPattern = Pattern.compile("\\+(\\S*\\w)");
private final static Pattern projectPattern = Pattern
.compile("\\+(\\S*\\w)");

private final static Pattern prependedDatePattern = Pattern
.compile("^(\\d{4})-(\\d{2})-(\\d{2}) (.*)");
Expand Down Expand Up @@ -113,6 +114,16 @@ public int compare(Task arg0, Task arg1) {
}
};

public static Comparator<Task> byIdReverse = new Comparator<Task>() {
@Override
public int compare(Task arg0, Task arg1) {
if (arg0 != null && arg1 != null) {
return Long.valueOf(arg1.id).compareTo(arg0.id);
}
return -1;
}
};

public static Comparator<Task> byPrio = new Comparator<Task>() {
@Override
public int compare(Task arg0, Task arg1) {
Expand Down
5 changes: 4 additions & 1 deletion src/com/todotxt/todotxttouch/TodoTxtTouch.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public class TodoTxtTouch extends ListActivity implements

private final static int SORT_PRIO = 0;
private final static int SORT_ID = 1;
private final static int SORT_TEXT = 2;
private final static int SORT_ID_REVERSE = 2;
private final static int SORT_TEXT = 3;

private final static int REQUEST_FILTER = 1;
private final static int REQUEST_PREFERENCES = 2;
Expand Down Expand Up @@ -676,6 +677,8 @@ void setFilteredTasks(boolean reload) {
Collections.sort(tasks, TaskHelper.byPrio);
} else if (m_sort == SORT_ID) {
Collections.sort(tasks, TaskHelper.byId);
} else if (m_sort == SORT_ID_REVERSE) {
Collections.sort(tasks, TaskHelper.byIdReverse);
} else if (m_sort == SORT_TEXT) {
Collections.sort(tasks, TaskHelper.byText);
}
Expand Down

0 comments on commit f226cbd

Please sign in to comment.