Skip to content

Commit

Permalink
Browse todo.txt file by various filters (PR #1408 by @harshad1)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Sep 8, 2021
1 parent a4719b7 commit 7e680df
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ public Object instantiateItem(ViewGroup container, int position) {

@Override
public Fragment getItem(int pos) {
final Fragment existing = _fragCache.get(pos);
if (existing != null) {
return existing;
}

switch (_bottomNav.getMenu().getItem(pos).getItemId()) {
default:
case R.id.nav_notebook: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class CommonTextActions {
public static final int ACTION_SEARCH_ICON = R.drawable.ic_search_black_24dp;
public static final String ACTION_SEARCH = "tmaid_common_search_in_content_of_current_file";

public static final String ACTION_TITLE = "tmaid_common_toolbar_title_clicked_edit_action";

public static final int ACTION_JUMP_BOTTOM_TOP_ICON = R.drawable.ic_vertical_align_center_black_24dp;
public static final String ACTION_JUMP_BOTTOM_TOP = "tmaid_common_jump_to_bottom";

Expand Down Expand Up @@ -170,12 +172,7 @@ public boolean runAction(String action) {
return true;
}
case ACTION_SEARCH: {
SearchOrCustomTextDialogCreator.showSearchDialog(_activity, _hlEditor.getText(), StringUtils.getSelection(_hlEditor), (lineNr) -> {
if (!_hlEditor.hasFocus()) {
_hlEditor.requestFocus();
}
_hlEditor.setSelection(StringUtils.getIndexFromLineOffset(origText, lineNr, 0));
});
SearchOrCustomTextDialogCreator.showSearchDialog(_activity, _hlEditor);
return true;
}
case ACTION_JUMP_BOTTOM_TOP: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ private boolean onClickImpl(final View view) {
return true;
}
case R.string.tmaid_common_toolbar_title_clicked_edit_action: {
final String origText = _hlEditor.getText().toString();
SearchOrCustomTextDialogCreator.showMarkdownHeadlineDialog(_activity, origText, (lineNr) -> {
_hlEditor.setSelection(StringUtils.getIndexFromLineOffset(origText, lineNr, 0));
});
SearchOrCustomTextDialogCreator.showHeadlineDialog(MarkdownReplacePatternGenerator.PREFIX_ATX_HEADING.toString(), _activity, _hlEditor);
return true;
}
case R.string.tmaid_common_move_text_one_line_up:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ public static Spannable basicTodoTxtHighlights(
profiler.restart("Priority F");
createColorSpanForMatches(spannable, TodoTxtTask.PATTERN_PRIORITY_F, colors.getPriorityColor(6));

// Date: Match Creation date before completition date
profiler.restart("Date Color");
createColorSpanForMatches(spannable, TodoTxtTask.PATTERN_DATE, colors.getDateColor(isDarkBg));
createColorSpanForMatches(spannable, TodoTxtTask.PATTERN_CREATION_DATE, colors.getDateColor(isDarkBg), 1);
createColorSpanForMatches(spannable, TodoTxtTask.PATTERN_DUE_DATE, colors.getPriorityColor(1), 2, 3);

// Strike out done tasks (apply no other to-do.txt span format afterwards)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public class TodoTxtTask {
public static final Pattern PATTERN_COMPLETION_DATE = Pattern.compile("(?:^|\\n)(?:[Xx] )(" + PT_DATE + ")?");
public static final Pattern PATTERN_CREATION_DATE = Pattern.compile("(?:^|\\n)(?:\\([A-Za-z]\\)\\s)?(?:[Xx] " + PT_DATE + " )?(" + PT_DATE + ")");

public static final char PRIORITY_NONE = '~';

public enum TodoDueState {
NONE, OVERDUE, TODAY, FUTURE
}

public static String getToday() {
return DATEF_YYYY_MM_DD.format(new Date());
}
Expand Down Expand Up @@ -131,6 +137,7 @@ public static String tasksToString(final List<TodoTxtTask> tasks) {
private String completionDate = null;
private String dueDate = null;
private String description = null;
private TodoDueState dueStatus = null;

public TodoTxtTask(final String line) {
this.line = line;
Expand Down Expand Up @@ -164,11 +171,7 @@ public String getDescription() {
public char getPriority() {
if (priority == null) {
final String ret = parseOneValueOrDefault(line, PATTERN_PRIORITY_ANY, "");
if (ret.length() == 1) {
priority = ret.charAt(0);
} else {
priority = '~'; // No priority == lowest priority
}
priority = ret.isEmpty() ? PRIORITY_NONE : Character.toUpperCase(ret.charAt(0));
}
return priority;
}
Expand Down Expand Up @@ -209,6 +212,19 @@ public String getDueDate(final String defaultValue) {
return dueDate;
}

public TodoDueState getDueStatus() {
if (dueStatus == null) {
final String date = getDueDate();
if (TextUtils.isEmpty(date)) {
dueStatus = TodoDueState.NONE;
} else {
final int comp = date.compareTo(getToday());
dueStatus = (comp > 0) ? TodoDueState.FUTURE : (comp < 0) ? TodoDueState.OVERDUE : TodoDueState.TODAY;
}
}
return dueStatus;
}

public String getCompletionDate() {
return getCompletionDate("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public TodoTxtTextActions(Activity activity, Document document) {
@Override
public boolean runAction(String action, boolean modLongClick, String anotherArg) {
if (action.equals(CommonTextActions.ACTION_SEARCH)) {
final Editable edit = _hlEditor.getText();
SearchOrCustomTextDialogCreator.showTodoSearchDialog(_activity, edit, StringUtils.getSelection(_hlEditor), this::doBasicHighlights, this::selectLines);
SearchOrCustomTextDialogCreator.showSttLineSelectionDialog(_activity, _hlEditor, R.string.search_documents, true, task -> true);
return true;
} else if (action.equals(CommonTextActions.ACTION_TITLE)) {
SearchOrCustomTextDialogCreator.showSttFilteringDialog(_activity, _hlEditor);
return true;
}
return runCommonTextAction(action);
Expand Down Expand Up @@ -118,7 +120,7 @@ public void onClick(View view) {
final String startingPriority = "^\\(([A-Z])\\)\\s";
runRegexReplaceAction(
// If task not done and starts with a priority and contains a pri tag
new ReplacePattern( startingPriority + bodyWithPri, doneMark + "$2 pri:$1$5"),
new ReplacePattern(startingPriority + bodyWithPri, doneMark + "$2 pri:$1$5"),
// else if task not done and starts with a priority and does not contain a pri tag
new ReplacePattern(startingPriority + "(.*)(\\s*)", doneMark + "$2 pri:$1"),
// else if task is done and contains a pri tag
Expand Down Expand Up @@ -164,7 +166,7 @@ public void onClick(View view) {
return;
}
case R.string.tmaid_todotxt_current_date: {
setDate();
setDueDate(_appSettings.getDueDateOffset());
return;
}
case R.string.tmaid_todotxt_archive_done_tasks: {
Expand Down Expand Up @@ -241,24 +243,21 @@ public void run() {

@Override
public boolean onLongClick(View v) {
String origText = _hlEditor.getText().toString();
final CommonTextActions commonTextActions = new CommonTextActions(_activity, _hlEditor);
final TodoTxtTextActions t_this = TodoTxtTextActions.this;

switch (_action) {
case R.string.tmaid_todotxt_add_context: {
SearchOrCustomTextDialogCreator.showSttKeySearchDialog(_activity, origText, t_this::doBasicHighlights, false, t_this::selectLines);
SearchOrCustomTextDialogCreator.showSttKeySearchDialog(_activity, _hlEditor, R.string.browse_by_context, true, true, task -> Arrays.asList(task.getContexts()));
return true;
}
case R.string.tmaid_todotxt_add_project: {
SearchOrCustomTextDialogCreator.showSttKeySearchDialog(_activity, origText, t_this::doBasicHighlights, true, t_this::selectLines);
SearchOrCustomTextDialogCreator.showSttKeySearchDialog(_activity, _hlEditor, R.string.browse_by_project, true, true, task -> Arrays.asList(task.getProjects()));
return true;
}
case R.string.tmaid_common_special_key: {
commonTextActions.runAction(CommonTextActions.ACTION_JUMP_BOTTOM_TOP);
return true;
}

case R.string.tmaid_common_open_link_browser: {
commonTextActions.runAction(CommonTextActions.ACTION_SEARCH);
return true;
Expand All @@ -273,7 +272,7 @@ public boolean onLongClick(View v) {
return true;
}
case R.string.tmaid_todotxt_current_date: {
setDueDate(_appSettings.getDueDateOffset());
setDate();
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ private boolean onClickImpl(final View view) {
return true;
}
case R.string.tmaid_common_toolbar_title_clicked_edit_action: {
final String origText = _hlEditor.getText().toString();
SearchOrCustomTextDialogCreator.showZimWikiHeadlineDialog(_activity, origText, (lineNr) -> {
_hlEditor.setSelection(StringUtils.getIndexFromLineOffset(origText, lineNr, 0));
});
SearchOrCustomTextDialogCreator.showHeadlineDialog(ZimWikiHighlighter.Patterns.HEADING.pattern.toString(), _activity, _hlEditor);
return true;
}
case R.string.tmaid_common_indent:
Expand Down
Loading

0 comments on commit 7e680df

Please sign in to comment.