Skip to content

Commit

Permalink
Merge branch 'master' into headline_dialog_improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner authored Sep 24, 2024
2 parents 77b18e8 + c445821 commit 4921be2
Show file tree
Hide file tree
Showing 77 changed files with 522 additions and 258 deletions.
18 changes: 17 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
android:name=".activity.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="standard"
android:launchMode="singleTask"
android:taskAffinity=".activity.MainActivity"
android:windowSoftInputMode="stateUnchanged|adjustResize">
<intent-filter>
Expand Down Expand Up @@ -110,6 +110,22 @@
android:name="other.writeily.widget.WrFilesWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />

<receiver
android:name=".widget.TodoWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/todo_widget" />
</receiver>

<service
android:name=".widget.TodoWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,27 @@ private static void launch(
final Intent intent;
if (GsFileBrowserListAdapter.isVirtualFolder(file) || file.isDirectory()) {
intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
} else {
intent = new Intent(activity, DocumentActivity.class);
}

intent.putExtra(Document.EXTRA_FILE, file);
if (!(activity instanceof DocumentActivity) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
as.isMultiWindowEnabled()
) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
}

if (lineNumber != null) {
intent.putExtra(Document.EXTRA_FILE_LINE_NUMBER, lineNumber);
}
if (lineNumber != null) {
intent.putExtra(Document.EXTRA_FILE_LINE_NUMBER, lineNumber);
}

if (doPreview != null) {
intent.putExtra(Document.EXTRA_DO_PREVIEW, doPreview);
if (doPreview != null) {
intent.putExtra(Document.EXTRA_DO_PREVIEW, doPreview);
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && as.isMultiWindowEnabled()) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
}
intent.putExtra(Document.EXTRA_FILE, file);

nextLaunchTransparentBg = (activity instanceof MainActivity);
GsContextUtils.instance.animateToActivity(activity, intent, false, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import net.gsantner.markor.model.Document;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.markor.web.MarkorWebViewClient;
import net.gsantner.markor.widget.TodoWidgetProvider;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions;
import net.gsantner.opoc.frontend.settings.GsFontPreferenceCompat;
import net.gsantner.opoc.frontend.textview.TextViewUndoRedo;
Expand Down Expand Up @@ -284,6 +285,10 @@ public void onPause() {
_appSettings.addRecentFile(_document.file);
_appSettings.setDocumentPreviewState(_document.path, _isPreviewVisible);
_appSettings.setLastEditPosition(_document.path, TextViewUtils.getSelection(_hlEditor)[0]);

if(_document.path.equals(_appSettings.getTodoFile().getAbsolutePath())){
TodoWidgetProvider.updateTodoWidgets();
}
super.onPause();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.gsantner.markor.frontend.filebrowser.MarkorFileBrowserFactory;
import net.gsantner.markor.model.Document;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.markor.widget.TodoWidgetProvider;
import net.gsantner.opoc.format.GsSimpleMarkdownParser;
import net.gsantner.opoc.frontend.base.GsFragmentBase;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserFragment;
Expand Down Expand Up @@ -486,6 +487,7 @@ public GsFileBrowserFragment getNotebook() {
protected void onPause() {
super.onPause();
WrMarkorWidgetProvider.updateLauncherWidgets();
TodoWidgetProvider.updateTodoWidgets();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.gsantner.markor.model.AppSettings;
import net.gsantner.markor.util.BackupUtils;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.markor.widget.TodoWidgetProvider;
import net.gsantner.opoc.frontend.base.GsActivityBase;
import net.gsantner.opoc.frontend.base.GsPreferenceFragmentBase;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions;
Expand Down Expand Up @@ -231,6 +232,7 @@ protected void onPreferenceChanged(final SharedPreferences prefs, final String k
}
} else if (eq(key, R.string.pref_key__notebook_directory, R.string.pref_key__quicknote_filepath, R.string.pref_key__todo_filepath)) {
WrMarkorWidgetProvider.updateLauncherWidgets();
TodoWidgetProvider.updateTodoWidgets();
}
}

Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ protected void runSurroundAction(final String open, final String close, final bo
final CharSequence selection = text.subSequence(ss, se);

// Case delims around selection
if ((ss > ol) && ((se + cl) <= text.length())) {
if ((ss >= ol) && ((se + cl) <= text.length())) {
final String before = text.subSequence(ss - ol, ss).toString();
final String after = text.subSequence(se, se + cl).toString();
if (before.equals(open) && after.equals(close)) {
Expand Down Expand Up @@ -966,32 +966,34 @@ public void runSpecialKeyAction() {
_hlEditor.simulateKeyPress(KeyEvent.KEYCODE_MOVE_END);
} else if (callbackPayload.equals(rstr(R.string.key_pos_1_document))) {
_hlEditor.setSelection(0);
} else if (callbackPayload.equals(rstr(R.string.key_pos_end_document))) {
_hlEditor.setSelection(_hlEditor.length());
} else if (callbackPayload.equals(rstr(R.string.move_text_one_line_up))) {
ActionButtonBase.moveLineSelectionBy1(_hlEditor, true);
} else if (callbackPayload.equals(rstr(R.string.move_text_one_line_down))) {
ActionButtonBase.moveLineSelectionBy1(_hlEditor, false);
} else if (callbackPayload.equals(rstr(R.string.key_pos_end_document))) {
_hlEditor.setSelection(_hlEditor.length());
} else if (callbackPayload.equals(rstr(R.string.select_current_line))) {
selectWholeLines(_hlEditor.getText());
} else if (callbackPayload.equals(rstr(R.string.key_ctrl_a))) {
_hlEditor.setSelection(0, _hlEditor.length());
} else if (callbackPayload.equals(rstr(R.string.key_tab))) {
_hlEditor.insertOrReplaceTextOnCursor("\u0009");
} else if (callbackPayload.equals(rstr(R.string.zero_width_space))) {
_hlEditor.insertOrReplaceTextOnCursor("\u200B");
} else if (callbackPayload.equals(rstr(R.string.search))) {
onSearch();
} else if (callbackPayload.equals(rstr(R.string.em_space))) {
_hlEditor.insertOrReplaceTextOnCursor("\u2003");
} else if (callbackPayload.equals(rstr(R.string.break_page_pdf_print))) {
_hlEditor.insertOrReplaceTextOnCursor("<div style='page-break-after:always;'></div>");
} else if (callbackPayload.equals(rstr(R.string.search))) {
onSearch();
} else if (callbackPayload.equals(rstr(R.string.ohm))) {
_hlEditor.insertOrReplaceTextOnCursor("Ω");
} else if (callbackPayload.equals(rstr(R.string.char_punctation_mark_arrows))) {
_hlEditor.insertOrReplaceTextOnCursor("»«");
} else if (callbackPayload.equals(rstr(R.string.continued_overline))) {
_hlEditor.insertOrReplaceTextOnCursor("‾‾‾‾‾");
} else if (callbackPayload.equals(rstr(R.string.shrug))) {
_hlEditor.insertOrReplaceTextOnCursor(\\_(ツ)_/¯");
} else if (callbackPayload.equals(rstr(R.string.char_punctation_mark_arrows))) {
_hlEditor.insertOrReplaceTextOnCursor("»«");
} else if (callbackPayload.equals(rstr(R.string.select_current_line))) {
selectWholeLines(_hlEditor.getText());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<ActionItem> getFormatActionList() {
new ActionItem(R.string.abid_todotxt_add_project, R.drawable.ic_new_label_black_24dp, R.string.add_project),
new ActionItem(R.string.abid_todotxt_priority, R.drawable.ic_star_border_black_24dp, R.string.priority),
new ActionItem(R.string.abid_todotxt_archive_done_tasks, R.drawable.ic_archive_black_24dp, R.string.archive_completed_tasks),
new ActionItem(R.string.abid_todotxt_current_date, R.drawable.ic_date_range_black_24dp, R.string.current_date),
new ActionItem(R.string.abid_todotxt_due_date, R.drawable.ic_date_range_black_24dp, R.string.due_date),
new ActionItem(R.string.abid_todotxt_sort_todo, R.drawable.ic_sort_by_alpha_black_24dp, R.string.sort_by),
new ActionItem(R.string.abid_common_insert_link, R.drawable.ic_link_black_24dp, R.string.insert_link),
new ActionItem(R.string.abid_common_insert_image, R.drawable.ic_image_black_24dp, R.string.insert_image),
Expand Down Expand Up @@ -106,20 +106,11 @@ public boolean onActionClick(final @StringRes int action) {
}
case R.string.abid_todotxt_priority: {
MarkorDialogFactory.showPriorityDialog(getActivity(), selTasks.get(0).getPriority(), (priority) -> {
ArrayList<ReplacePattern> patterns = new ArrayList<>();
if (priority.length() > 1) {
patterns.add(new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, ""));
} else if (priority.length() == 1) {
final String _priority = String.format("(%c) ", priority.charAt(0));
patterns.add(new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, _priority));
patterns.add(new ReplacePattern("^\\s*", _priority));
}
runRegexReplaceAction(patterns);
trimLeadingWhiteSpace();
setPriority(priority.length() == 1 ? priority.charAt(0) : TodoTxtTask.PRIORITY_NONE);
});
return true;
}
case R.string.abid_todotxt_current_date: {
case R.string.abid_todotxt_due_date: {
setDueDate(_appSettings.getDueDateOffset());
return true;
}
Expand Down Expand Up @@ -166,7 +157,52 @@ public boolean onActionLongClick(final @StringRes int action) {
}
return true;
}
case R.string.abid_todotxt_current_date: {
case R.string.abid_todotxt_priority: {
final Editable text = _hlEditor.getText();
final int[] sel = TextViewUtils.getSelection(_hlEditor);
final int lineStart = TextViewUtils.getLineStart(text, sel[0]);
final int lineEnd = TextViewUtils.getLineEnd(text, sel[1]);
final List<TodoTxtTask> tasks = TodoTxtTask.getTasks(text, new int[]{sel[0], sel[1]});
char prevPriority = '\0', nextPriority = '\0';
boolean areAllSamePriority = true;
if (lineStart != 0) {
final int prevLineStart = TextViewUtils.getLineStart(text, lineStart - 1);
final int prevLineEnd = TextViewUtils.getLineEnd(text, prevLineStart);
final String prevLine = text.subSequence(prevLineStart, prevLineEnd).toString();
prevPriority = new TodoTxtTask(prevLine).getPriority();
}
if (lineEnd != text.length()) {
final int nextLineStart = TextViewUtils.getLineStart(text, lineEnd + 1);
final int nextLineEnd = TextViewUtils.getLineEnd(text, nextLineStart);
final String nextLine = text.subSequence(nextLineStart, nextLineEnd).toString();
nextPriority = new TodoTxtTask(nextLine).getPriority();
}
for (TodoTxtTask task : tasks) {
if (task.getPriority() != tasks.get(0).getPriority()) {
areAllSamePriority = false;
break;
}
}
if (areAllSamePriority) {
if(prevPriority != tasks.get(0).getPriority() && prevPriority != '\0') {
setPriority(prevPriority);
}
else if(nextPriority != tasks.get(tasks.size() - 1).getPriority() && nextPriority != '\0') {
setPriority(nextPriority);
}
else {
setPriority(TodoTxtTask.PRIORITY_NONE);
}
} else {
if(prevPriority != '\0') {
setPriority(prevPriority);
} else {
setPriority(tasks.get(0).getPriority());
}
}
return true;
}
case R.string.abid_todotxt_due_date: {
setDate();
return true;
}
Expand Down Expand Up @@ -307,6 +343,19 @@ private static void insertInline(final Editable editable, String thing) {
editable.replace(sel[0], sel[1], thing);
}

private void setPriority(char priority) {
ArrayList<ReplacePattern> patterns = new ArrayList<>();
if (priority == TodoTxtTask.PRIORITY_NONE) {
patterns.add(new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, ""));
} else {
final String _priority = String.format("(%c) ", priority);
patterns.add(new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, _priority));
patterns.add(new ReplacePattern("^\\s*", _priority));
}
runRegexReplaceAction(patterns);
trimLeadingWhiteSpace();
}

private static Calendar parseDateString(final String dateString, final Calendar fallback) {
if (dateString == null || dateString.length() != TodoTxtTask.DATEF_YYYY_MM_DD_LEN) {
return fallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class TodoTxtBasicSyntaxHighlighter extends SyntaxHighlighterBase {
private final static int COLOR_CONTEXT = 0xff88b04b;

private final static int COLOR_PRIORITY_A = 0xffEF2929;
private final static int COLOR_PRIORITY_B = 0xffF57900;
private final static int COLOR_PRIORITY_C = 0xff73D216;
private final static int COLOR_PRIORITY_D = 0xff0099CC;
private final static int COLOR_PRIORITY_E = 0xffEDD400;
private final static int COLOR_PRIORITY_F = 0xff888A85;
private final static int COLOR_PRIORITY_B = 0xffd16900;
private final static int COLOR_PRIORITY_C = 0xff59a112;
private final static int COLOR_PRIORITY_D = 0xff0091c2;
private final static int COLOR_PRIORITY_E = 0xffa952cb;
private final static int COLOR_PRIORITY_F = 0xff878986;

private final static int COLOR_DONE_DARK = 0x999d9d9d;
private final static int COLOR_DONE_LIGHT = 0x993d3d3d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ public List<String> getProjects() {
}

public String getCreationDate() {
return getCreationaDate("");
return getCreationDate("");
}

public String getCreationaDate(final String defaultValue) {
public String getCreationDate(final String defaultValue) {
if (creationDate == null) {
creationDate = parseOneValueOrDefault(line, PATTERN_CREATION_DATE, defaultValue);
}
Expand Down
Loading

0 comments on commit 4921be2

Please sign in to comment.