-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add dialogue for sorting todo.txt files This commit adds a dialogue used to sort todo.txt files by context, project, or priority. * Add Comparator for sorting SttTasks This commit creates a class implementing Comparator so that SttTasks can be sorted with default Java sorting methods. * Add sorting algorithm for todo.txt files This commit adds a case which implements sorting of tasks in todo.txt files. * Add button for sorting todo.txt files This commit adds a button to the toolbar which brings up the prompt to sort todo.txt files. * Reformatted to android-studio standard This commit used the reformat-text option on android-studio to improve code formatting. * added contributor
- Loading branch information
Showing
11 changed files
with
131 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/main/java/net/gsantner/opoc/format/todotxt/extension/SttTaskComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package net.gsantner.opoc.format.todotxt.extension; | ||
|
||
|
||
import net.gsantner.opoc.format.todotxt.SttTask; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class SttTaskComparator implements Comparator<SttTask> { | ||
protected String sortBy; | ||
protected boolean isAscending; | ||
|
||
public SttTaskComparator() { | ||
} | ||
|
||
public String getSortBy() { | ||
return sortBy; | ||
} | ||
|
||
public void setSortBy(String value) { | ||
sortBy = value; | ||
} | ||
|
||
public boolean getAscending() { | ||
return isAscending; | ||
} | ||
|
||
public void setAscending(boolean value) { | ||
isAscending = value; | ||
} | ||
|
||
@Override | ||
public int compare(SttTask x, SttTask y) { | ||
int difference = 0; | ||
switch (sortBy) { | ||
case "priority": { | ||
difference = compare(x.getPriority(), y.getPriority()); | ||
break; | ||
} | ||
case "context": { | ||
difference = compare(x.getContexts(), y.getContexts()); | ||
break; | ||
} | ||
case "project": { | ||
difference = compare(x.getProjects(), y.getProjects()); | ||
break; | ||
} | ||
default: { | ||
return 0; | ||
} | ||
} | ||
if (getAscending()) difference = -1 * difference; | ||
return difference; | ||
} | ||
|
||
private int compare(char x, char y) { | ||
if (Character.toLowerCase(y) < Character.toLowerCase(x)) | ||
return 1; | ||
if (Character.toLowerCase(y) == Character.toLowerCase(x)) | ||
return 0; | ||
return -1; | ||
} | ||
|
||
private int compare(List<String> x, List<String> y) { | ||
if (x.isEmpty() & y.isEmpty()) return 0; | ||
if (x.isEmpty()) return 1; | ||
if (y.isEmpty()) return -1; | ||
return x.get(0).compareTo(y.get(0)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters