From f4c2421ba51b0407d7ec1e2868a74877ea0f13d2 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Fri, 1 Jul 2022 13:48:07 +0000 Subject: [PATCH] Add support for filtering subtasks - add getting parent id from Astrid's Tasks app refs #104 --- .../prefs/ApplicationPreferences.java | 9 +++++ .../EventFiltersPreferencesFragment.java | 10 +++++- .../todoagenda/prefs/HideSubtasks.java | 34 +++++++++++++++++++ .../todoagenda/prefs/InstanceSettings.java | 16 +++++++++ .../todoagenda/task/AbstractTaskProvider.java | 11 ++++++ .../andstatus/todoagenda/task/TaskEvent.java | 13 +++++++ .../task/astrid/AstridCloneTasksProvider.java | 4 ++- app/src/main/res/values/arrays.xml | 8 +++++ app/src/main/res/values/strings.xml | 3 ++ .../res/xml/preferences_event_filters.xml | 8 ++++- 10 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/andstatus/todoagenda/prefs/HideSubtasks.java diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java index 75ae33fd..5b1a655d 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java @@ -34,6 +34,7 @@ import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILTER_MODE; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HIDE_BASED_ON_KEYWORDS; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HIDE_DUPLICATES; +import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HIDE_SUBTASKS; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_INDICATE_ALERTS; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_INDICATE_RECURRING; @@ -355,6 +356,14 @@ public static void setHideDuplicates(Context context, boolean value) { setBoolean(context, PREF_HIDE_DUPLICATES, value); } + public static HideSubtasks getHideSubtasks(Context context) { + return HideSubtasks.fromValue(getString(context, PREF_HIDE_SUBTASKS, "")) + } + + public static void setHideSubtasks(Context content, HideSubtasks value) { + setString(context, PREF_HIDE_SUBTASKS, value.value); + } + public static void setAllDayEventsPlacement(Context context, AllDayEventsPlacement value) { setString(context, PREF_ALL_DAY_EVENTS_PLACEMENT, value.value); } diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/EventFiltersPreferencesFragment.java b/app/src/main/java/org/andstatus/todoagenda/prefs/EventFiltersPreferencesFragment.java index 5080074e..a8b5cfab 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/EventFiltersPreferencesFragment.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/EventFiltersPreferencesFragment.java @@ -29,6 +29,7 @@ private void showStatus() { showEventsEnded(); showEvenRange(); showHideBasedOnKeywords(); + showHideSubtasks(); showAllDayEventsPlacement(); showTaskScheduling(); showTasksWithoutDates(); @@ -55,6 +56,13 @@ private void showHideBasedOnKeywords() { } } + private void showHideSubtasks() { + Preference preference = findPreference(InstanceSettings.PREF_HIDE_SUBTASKS); + if (preference != null) { + preference.setSummary(ApplicationPreferences.getHideSubtasks(getActivity()).valueResId) + } + } + private void showAllDayEventsPlacement() { Preference preference = findPreference(InstanceSettings.PREF_ALL_DAY_EVENTS_PLACEMENT); if (preference != null) { @@ -93,4 +101,4 @@ public void onPause() { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { showStatus(); } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/HideSubtasks.java b/app/src/main/java/org/andstatus/todoagenda/prefs/HideSubtasks.java new file mode 100644 index 00000000..d1a54b29 --- /dev/null +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/HideSubtasks.java @@ -0,0 +1,34 @@ +package org.andstatus.todoagenda.prefs; + +import androidx.annoation.StringRes; + +import org.andstatus.todoagenda.R; + +/** + * See https://github.com/andstatus/todoagenda/issues/104 + * @author felix.stupp+github@banananet.work + */ +public enum HideSubtasks { + SHOW_ALL("show_all", R.string.pref_hide_subtasks_show_all), + HIDE_ALL("hide_all", R.string.pref_hide_subtasks_hide_all); + + public final static HideSubtasks defaultValue = SHOW_ALL; + + public final String value; + @StringRes + public final int valueResId; + + HideSubtasks(String value, int valueResId) { + this.value = value; + this.valueResId = valueResId; + } + + public static HideSubtasks fromValue(String value) { + for (HideSubtasks item : HideSubtasks.values()) { + if (item.value.equals(value)) { + return item; + } + } + return defaultValue; + } +} diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java index 44c342bb..1da21bfd 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java @@ -123,6 +123,8 @@ public class InstanceSettings { private boolean showOnlyClosestInstanceOfRecurringEvent = false; static final String PREF_HIDE_DUPLICATES = "hideDuplicates"; private boolean hideDuplicates = false; + static final String PREF_HIDE_SUBTASKS = "hideSubtasks"; + private HideSubtasks hideSubtasks = HideSubtasks.defaultValue; static final String PREF_ALL_DAY_EVENTS_PLACEMENT = "allDayEventsPlacement"; private AllDayEventsPlacement allDayEventsPlacement = AllDayEventsPlacement.defaultValue; static final String PREF_TASK_SCHEDULING = "taskScheduling"; @@ -273,6 +275,9 @@ private InstanceSettings setFromJson(JSONObject json) { if (json.has(PREF_HIDE_DUPLICATES)) { hideDuplicates = json.getBoolean(PREF_HIDE_DUPLICATES); } + if (json.has(PREF_HIDE_SUBTASKS)) { + hideSubtasks = HideSubtasks.fromValue(json.getString(PREF_HIDE_SUBTASKS)); + } if (json.has(PREF_ALL_DAY_EVENTS_PLACEMENT)) { allDayEventsPlacement = AllDayEventsPlacement.fromValue(json.getString(PREF_ALL_DAY_EVENTS_PLACEMENT)); } @@ -376,6 +381,7 @@ private InstanceSettings setFromApplicationPreferences(InstanceSettings settings showOnlyClosestInstanceOfRecurringEvent = ApplicationPreferences .getShowOnlyClosestInstanceOfRecurringEvent(context); hideDuplicates = ApplicationPreferences.getHideDuplicates(context); + setHideSubtasks(ApplicationPreferences.getHideSubtasks(context)); setAllDayEventsPlacement(ApplicationPreferences.getAllDayEventsPlacement(context)); taskScheduling = ApplicationPreferences.getTaskScheduling(context); taskWithoutDates = ApplicationPreferences.getTasksWithoutDates(context); @@ -466,6 +472,7 @@ public JSONObject toJson() { json.put(PREF_MULTILINE_DETAILS, multilineDetails); json.put(PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT, showOnlyClosestInstanceOfRecurringEvent); json.put(PREF_HIDE_DUPLICATES, hideDuplicates); + json.put(PREF_HIDE_SUBTASKS, hideSubtasks.value); json.put(PREF_ALL_DAY_EVENTS_PLACEMENT, allDayEventsPlacement.value); json.put(PREF_TASK_SCHEDULING, taskScheduling.value); json.put(PREF_TASK_WITHOUT_DATES, taskWithoutDates.value); @@ -660,6 +667,15 @@ public boolean getHideDuplicates() { return hideDuplicates; } + public HideSubtasks getHideSubtasks() { + return hideSubtasks; + } + + public InstanceSettings setHideSubtasks(HideSubtasks hideSubtasks) { + this.hideSubtasks = hideSubtasks; + return this; + } + public AllDayEventsPlacement getAllDayEventsPlacement() { return allDayEventsPlacement; } diff --git a/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java b/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java index 1f517f46..6a7eb43a 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java @@ -4,6 +4,7 @@ import android.content.Intent; import org.andstatus.todoagenda.prefs.FilterMode; +import org.andstatus.todoagenda.prefs.HideSubtasks; import org.andstatus.todoagenda.prefs.TaskScheduling; import org.andstatus.todoagenda.provider.EventProvider; import org.andstatus.todoagenda.provider.EventProviderType; @@ -54,6 +55,16 @@ protected boolean matchedFilter(TaskEvent task) { if (task.hasDueDate() && task.getDueDate().isAfter(getSettings().getEndOfTimeRange())) return false; } } + HideSubtasks hideSubtasks = getSettings().getHideSubtasks(); + if (hideSubtasks != HideSubtasks.SHOW_ALL && task.isSubtask()) { + switch (hideSubtasks) { + case HideSubtasks.HIDE_ALL: + return false; + case HideSubtasks.SHOW_ALL: // for completed switch + default: + break; + } + } return !mKeywordsFilter.matched(task.getTitle()); } diff --git a/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java b/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java index 237fdd7f..034db33e 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java @@ -20,6 +20,7 @@ public class TaskEvent implements WidgetEvent { private DateTime dueDate; private int color; private TaskStatus status = TaskStatus.UNKNOWN; + private Long parent = null; public TaskEvent(InstanceSettings settings, DateTimeZone zone) { this.settings = settings; @@ -105,4 +106,16 @@ public TaskStatus getStatus() { public void setStatus(TaskStatus status) { this.status = status; } + + public Long getParent() { + return parent; + } + + public void setParent(Long parent) { + this.parent = parent; + } + + public boolean isSubtask() { + return parent != null; + } } diff --git a/app/src/main/java/org/andstatus/todoagenda/task/astrid/AstridCloneTasksProvider.java b/app/src/main/java/org/andstatus/todoagenda/task/astrid/AstridCloneTasksProvider.java index 4da22126..f2ac6b04 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/astrid/AstridCloneTasksProvider.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/astrid/AstridCloneTasksProvider.java @@ -46,8 +46,9 @@ public class AstridCloneTasksProvider extends AbstractTaskProvider { private static final String TASKS_COLUMN_START_DATE = "hideUntil"; private static final String TASKS_COLUMN_IMPORTANCE = "importance"; private static final String TASKS_COLUMN_COMPLETED = "completed"; + private static final String TASKS_COLUMN_PARENT = "parent"; private static final String[] PROJECTION = {TASKS_COLUMN_ID, TASKS_COLUMN_TITLE, TASKS_COLUMN_DUE_DATE, - TASKS_COLUMN_START_DATE, TASKS_COLUMN_IMPORTANCE, TASKS_COLUMN_COMPLETED}; + TASKS_COLUMN_START_DATE, TASKS_COLUMN_IMPORTANCE, TASKS_COLUMN_COMPLETED, TASKS_COLUMN_PARENT}; private final AstridCloneTaskSource taskSource; @@ -129,6 +130,7 @@ private TaskEvent newTask(Cursor cursor) { task.setDates(startMillis, dueMillis); int priority = cursor.getInt(cursor.getColumnIndex(TASKS_COLUMN_IMPORTANCE)); int color = context.getColor(priorityToColor(priority)); + Long parent = getPositiveLongOrNull(cursor, TASKS_COLUMN_PARENT); task.setColor(getAsOpaque(color)); return task; diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index ca30dc9b..d88b69dc 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -272,4 +272,12 @@ top_day bottom_day + + @string/pref_hide_subtasks_show_all + @string/pref_hide_subtasks_hide_all + + + show_all + hide_all + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8597b45e..1439234f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -208,6 +208,9 @@ Hide based on keywords in a title Show only the closest instance of a recurring event Hide duplicates + Hide subtasks + Show all subtasks + Hide all subtasks All day events placement At the top of the day\'s events At the bottom of the day\'s events diff --git a/app/src/main/res/xml/preferences_event_filters.xml b/app/src/main/res/xml/preferences_event_filters.xml index 9151fae4..6d540bdf 100644 --- a/app/src/main/res/xml/preferences_event_filters.xml +++ b/app/src/main/res/xml/preferences_event_filters.xml @@ -34,6 +34,12 @@ android:defaultValue="false" android:key="hideDuplicates" android:title="@string/hide_duplicates" /> + - \ No newline at end of file +