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

Add support for filtering subtasks #105

Closed
wants to merge 1 commit into from
Closed
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 @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private void showStatus() {
showEventsEnded();
showEvenRange();
showHideBasedOnKeywords();
showHideSubtasks();
showAllDayEventsPlacement();
showTaskScheduling();
showTasksWithoutDates();
Expand All @@ -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) {
Expand Down Expand Up @@ -93,4 +101,4 @@ public void onPause() {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
showStatus();
}
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/org/andstatus/todoagenda/prefs/HideSubtasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.andstatus.todoagenda.prefs;

import androidx.annoation.StringRes;
Copy link
Member

Choose a reason for hiding this comment

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

Hi @Zocker1999NET Thanks for the contribution.
The strange thing is that your code has lots of compilation errors :-)
Do you use Android Studio for development? I mean it shows all errors and it's easy to fix them...

Copy link
Author

Choose a reason for hiding this comment

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

No :), yesterday I wasn't home while coding, so I wrote the first version in VS Code without any Android/Java plugins applied (otherwise my laptop battery would have been died way too quick). That's why I haven't checked for compile errors for now xD.
I thought I marked this as draft and not as a "ready to merge" PR, but either I missed something or GitHub forgot that … It is not ready to merge yet, I just wanted that you and other collaborators can check on the progress and maybe hint on conceptional errors as early as possible.

Copy link
Member

Choose a reason for hiding this comment

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

As I see, you do most of additions using analogy with adjacent code, so everything is OK so far.
You didn't do all necessary additions for your first step yet, I think,
and this means that adding the new setting to existing tests will allow to show this.

So please don't postpone tests addition to the next implementation step.


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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,12 @@
<item>top_day</item>
<item>bottom_day</item>
</string-array>
<string-array name="pref_hide_subtasks_entries">
<item>@string/pref_hide_subtasks_show_all</item>
<item>@string/pref_hide_subtasks_hide_all</item>
</string-array>
<string-array name="pref_hide_subtasks_values" tools:ignore="MissingTranslation">
<item>show_all</item>
<item>hide_all</item>
</string-array>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
<string name="pref_hide_based_on_keywords_title">Hide based on keywords in a title</string>
<string name="show_only_closest_instance_of_recurring_event">Show only the closest instance of a recurring event</string>
<string name="hide_duplicates">Hide duplicates</string>
<string name="pref_hide_subtasks_title">Hide subtasks</string>
<string name="pref_hide_subtasks_show_all">Show all subtasks</string>
<string name="pref_hide_subtasks_hide_all">Hide all subtasks</string>
<string name="all_day_events_placement_title">All day events placement</string>
<string name="all_day_events_placement_top_of_the_days_events">At the top of the day\'s events</string>
<string name="all_day_events_placement_bottom_of_the_days_events">At the bottom of the day\'s events</string>
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/xml/preferences_event_filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
android:defaultValue="false"
android:key="hideDuplicates"
android:title="@string/hide_duplicates" />
<ListPreference
android:key="hideSubtasks"
android:defaultValue="show_all"
android:entries="@array/pref_show_subtasks_entries"
android:entryValues="@array/pref_show_subtasks_values"
android:title="@string/pref_show_subtasks_title" />
<ListPreference
android:key="allDayEventsPlacement"
android:defaultValue="top_day"
Expand All @@ -59,4 +65,4 @@
android:entryValues="@array/pref_filter_mode_values"
android:title="@string/filter_mode" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>