Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for the action buttons, closes #2386 #2388

Merged
merged 18 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe the behaviour you are trying to achieve here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, when adding a new task below another, the task's priority would usually be the same.
The goal is to set/unset the priority to be the same as the top one.

This is what felt right to me for multi line:

  • if at least one priority is different than the top one - set all to the top priority
  • if they are the same and same as the top one - remove priorities as there is nothing else to do (another press restores it)

That also means, that any priorities can be removed with at most two presses.
Might also add a check for the bottom line as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long pressing the priority button copies the priority from the first task to all the others?

Does this really need a long press? Currently one can select all the tasks and assign them a priority pretty easily.

You can select multiple tasks by simply creating a selection covering multiple tasks in the editor or by using the search dialog.

So search -> select all -> priority action -> select priority to assign to all selected tasks.

Copy link
Contributor Author

@wshoy wshoy Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long pressing the priority button copies the priority from the first task to all the others?

By "top" I mean the previous line from selection. Priority is copied to the selected lines.
The exact behavior is not set in stone, it's what I came up with.

Does this really need a long press? Currently one can select all the tasks and assign them a priority pretty easily.

In my experience, it feels much easier and responsive in daily use, as it makes creating another task with priority a little bit faster than the other methods.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.

So the current workflow is:

select -> priority action -> choose

And the new workflow for this use case is

select -> long press priority action

We're replacing 2 short presses with one long press.

Copy link
Contributor Author

@wshoy wshoy Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well put

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change those colors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The B and C colors were disproportionately bright compared to the red color of A. The A priority, being most important, should be at least as much noticeable as the other ones.
The yellow E color was much brighter than all the other colors and didn't match the hue sequence.

I used the perceived brightness formula to match the colors:

Before:
EF2929 - 0.53
F57900 - 0.64
73D216 - 0.68
0099CC - 0.53
EDD400 - 0.81
888A85 - 0.54

After:
EF2929 - 0.53
d16900 - 0.55
59a112 - 0.52
0091c2 - 0.51
a952cb - 0.51
878986 - 0.53

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 @@ -103,7 +103,7 @@ public static void showDatetimeFormatDialog(final Activity activity, final Highl
final Button datePickButton = viewRoot.findViewById(R.id.start_datepicker_button);
final Button timePickButton = viewRoot.findViewById(R.id.start_timepicker_button);
final CheckBox formatInsteadCheckbox = viewRoot.findViewById(R.id.get_format_instead_date_or_time_checkbox);
final CheckBox alwaysNowCheckBox = viewRoot.findViewById(R.id.always_use_current_datetime_checkbox);
final CheckBox useCurrentDateCheckbox = viewRoot.findViewById(R.id.use_current_datetime_checkbox);

final List<String> recentFormats = getRecentFormats(activity);
final List<String> allFormats = getAllFormats(recentFormats);
Expand All @@ -117,7 +117,7 @@ public static void showDatetimeFormatDialog(final Activity activity, final Highl
popupWindow.setOnItemClickListener((parent, view, position, id) -> {
formatEditText.setText(allFormats.get(position));
popupWindow.dismiss();
setToNow(cal, alwaysNowCheckBox.isChecked());
setToNow(cal, useCurrentDateCheckbox.isChecked());
previewTextView.setText(cu.formatDateTime(locale, formatEditText.getText().toString(), cal.getTimeInMillis()));
});

Expand All @@ -143,7 +143,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
@Override
public void afterTextChanged(Editable s) {
if (editTime + DELAY > System.currentTimeMillis()) {
setToNow(cal, alwaysNowCheckBox.isChecked());
setToNow(cal, useCurrentDateCheckbox.isChecked());
previewTextView.setText(cu.formatDateTime(locale, formatEditText.getText().toString(), cal.getTimeInMillis()));
final boolean error = previewTextView.getText().toString().isEmpty() && !formatEditText.getText().toString().isEmpty();
formatEditText.setError(error ? "^^^!!! 'normal text'" : null);
Expand All @@ -165,6 +165,7 @@ public void afterTextChanged(Editable s) {

// Pick Date Dialog
datePickButton.setOnClickListener(button -> new DatePickerDialog(activity, (view, year, month, day) -> {
useCurrentDateCheckbox.setChecked(false);
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, day);
Expand All @@ -174,22 +175,24 @@ public void afterTextChanged(Editable s) {

// Pick Time Dialog
timePickButton.setOnClickListener(button -> new TimePickerDialog(activity, (timePicker, hour, min) -> {
useCurrentDateCheckbox.setChecked(false);
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, min);
previewTextView.setText(cu.formatDateTime(locale, formatEditText.getText().toString(), cal.getTimeInMillis()));
}, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true).show()
);

// hide buttons when both check box are checked
final View.OnClickListener onOptionsChangedListener = v -> {
boolean dateChangeable = !formatInsteadCheckbox.isChecked() && !alwaysNowCheckBox.isChecked();
timePickButton.setEnabled(dateChangeable);
datePickButton.setEnabled(dateChangeable);
formatInsteadCheckbox.setOnClickListener(v -> {
dateHeadline.setEnabled(!formatInsteadCheckbox.isChecked());
alwaysNowCheckBox.setEnabled(!formatInsteadCheckbox.isChecked());
};
formatInsteadCheckbox.setOnClickListener(onOptionsChangedListener);
alwaysNowCheckBox.setOnClickListener(onOptionsChangedListener);
datePickButton.setEnabled(!formatInsteadCheckbox.isChecked());
timePickButton.setEnabled(!formatInsteadCheckbox.isChecked());
useCurrentDateCheckbox.setEnabled(!formatInsteadCheckbox.isChecked());
});

useCurrentDateCheckbox.setOnClickListener(v -> {
setToNow(cal, useCurrentDateCheckbox.isChecked());
previewTextView.setText(cu.formatDateTime(locale, formatEditText.getText().toString(), cal.getTimeInMillis()));
});

// set builder and implement buttons to discard and submit
builder.setView(viewRoot)
Expand All @@ -204,7 +207,7 @@ public void afterTextChanged(Editable s) {
final AlertDialog dialog = builder.create();

callbackInsertTextToEditor.set((selectedFormat) -> {
setToNow(cal, alwaysNowCheckBox.isChecked());
setToNow(cal, useCurrentDateCheckbox.isChecked());
String text = cu.formatDateTime(locale, selectedFormat, cal.getTimeInMillis());
previewTextView.setText(text);
hlEditor.insertOrReplaceTextOnCursor(getOutput(
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/res/layout/time_format_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="false"
android:text="@string/pick_date"
android:textAllCaps="false" />

Expand All @@ -150,17 +149,16 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="false"
android:text="@string/pick_time"
android:textAllCaps="false" />
</LinearLayout>

<CheckBox
android:id="@+id/always_use_current_datetime_checkbox"
android:id="@+id/use_current_datetime_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/always_use_current_date_and_time" />
android:text="@string/use_current_date_and_time" />
</LinearLayout>

</ScrollView>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">اختر تاريخاً</string>
<string name="pick_time">اختر الوقت</string>
<string name="get_format_instead_date_or_time">كتابة الصيغة وليس التاريخ أو الوقت</string>
<string name="always_use_current_date_and_time">دائما استخدم الوقت والتاريخ الحاليين</string>
<string name="use_current_date_and_time">دائما استخدم الوقت والتاريخ الحاليين</string>
<string name="result">النتيجة</string>
<string name="just_time">الوقت فقط</string>
<string name="just_date">التاريخ فقط</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Izaberi datum</string>
<string name="pick_time">Odredi vrijeme</string>
<string name="get_format_instead_date_or_time">Format umjesto datuma ili vremena</string>
<string name="always_use_current_date_and_time">Uvijek prikaži trenutni datum i vrijeme</string>
<string name="use_current_date_and_time">Uvijek prikaži trenutni datum i vrijeme</string>
<string name="result">Rezultat</string>
<string name="just_time">Samo vrijeme</string>
<string name="just_date">Samo datum</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Tria la data</string>
<string name="pick_time">Tria l\'hora</string>
<string name="get_format_instead_date_or_time">Obtén el format en lloc de la data o l\'hora</string>
<string name="always_use_current_date_and_time">Utilitza sempre la data i l\'hora actual</string>
<string name="use_current_date_and_time">Utilitza sempre la data i l\'hora actual</string>
<string name="result">Resultat</string>
<string name="just_time">Només l\'hora</string>
<string name="just_date">Només la data</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Vybrat datum</string>
<string name="pick_time">Vybrat čas</string>
<string name="get_format_instead_date_or_time">Formát místo data nebo času</string>
<string name="always_use_current_date_and_time">Vždy používat aktuální datum &amp; čas</string>
<string name="use_current_date_and_time">Vždy používat aktuální datum &amp; čas</string>
<string name="result">Výsledek</string>
<string name="just_time">Pouze čas</string>
<string name="just_date">Pouze datum</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Vælg dato</string>
<string name="pick_time">Vælg tidspunkt</string>
<string name="get_format_instead_date_or_time">Hent format i stedet dato eller tid</string>
<string name="always_use_current_date_and_time">Benyt altid aktuel dato &amp; tid</string>
<string name="use_current_date_and_time">Benyt altid aktuel dato &amp; tid</string>
<string name="result">Resultat</string>
<string name="just_time">Kun tid</string>
<string name="just_date">Kun dato</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Datum auswählen</string>
<string name="pick_time">Zeit auswählen</string>
<string name="get_format_instead_date_or_time">Format statt Datum und Zeit</string>
<string name="always_use_current_date_and_time">Immer die aktuelle Uhrzeit verwenden</string>
<string name="use_current_date_and_time">Immer die aktuelle Uhrzeit verwenden</string>
<string name="result">Ergebnis</string>
<string name="just_time">Nur Zeit</string>
<string name="just_date">Nur Datum</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Επιλέξτε ημερομηνία</string>
<string name="pick_time">Επιλέξτε ώρα</string>
<string name="get_format_instead_date_or_time">Χρήση μορφής αντί για ημερομηνία ή ώρα</string>
<string name="always_use_current_date_and_time">Να χρησιμοποιείται πάντα η τρέχουσα ημερομηνία &amp; ώρα</string>
<string name="use_current_date_and_time">Να χρησιμοποιείται πάντα η τρέχουσα ημερομηνία &amp; ώρα</string>
<string name="result">Αποτέλεσμα</string>
<string name="just_time">Μόνο ώρα</string>
<string name="just_date">Μόνο ημερομηνία</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Elegir fecha</string>
<string name="pick_time">Elegir hora</string>
<string name="get_format_instead_date_or_time">Cambiar formato de fecha y hora</string>
<string name="always_use_current_date_and_time">Utilizar siempre la fecha actual &amp; hora</string>
<string name="use_current_date_and_time">Utilizar siempre la fecha actual &amp; hora</string>
<string name="result">Resultado</string>
<string name="just_time">Sólo hora</string>
<string name="just_date">Sólo fecha</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pick_date">Vali kuupäev</string>
<string name="pick_time">Mära kellaaeg</string>
<string name="get_format_instead_date_or_time">Hankige kuupäeva või kellaaja asemel vorming</string>
<string name="always_use_current_date_and_time">Kasuta alati praegust kuupäeva &amp; aega</string>
<string name="use_current_date_and_time">Kasuta alati praegust kuupäeva &amp; aega</string>
<string name="result">Tulemus</string>
<string name="just_time">Ainult aeg</string>
<string name="just_date">Ainult kuupäev</string>
Expand Down
Loading
Loading