Skip to content

Commit

Permalink
plusonelabs#163 Hide duplicated events
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Oct 9, 2019
1 parent d57899b commit e271194
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,30 @@ private List<WidgetEntry> queryWidgetEntries(InstanceSettings settings) {
eventEntries.addAll(visualizer.queryEventEntries());
}
Collections.sort(eventEntries);
List<WidgetEntry> widgetEntries = settings.getShowDayHeaders() ? addDayHeaders(eventEntries) : eventEntries;
List<WidgetEntry> deduplicated = settings.getHideDuplicates() ? hideDuplicates(eventEntries) : eventEntries;
List<WidgetEntry> widgetEntries = settings.getShowDayHeaders() ? addDayHeaders(deduplicated) : deduplicated;
widgetEntries.add(LastEntry.from(settings, widgetEntries));
return widgetEntries;
}

private List<WidgetEntry> hideDuplicates(List<WidgetEntry> inputEntries) {
List<WidgetEntry> deduplicated = new ArrayList<>();
List<WidgetEntry> hidden = new ArrayList<>();
for(int ind1 = 0; ind1 < inputEntries.size(); ind1++) {
WidgetEntry inputEntry = inputEntries.get(ind1);
if (!hidden.contains(inputEntry)) {
deduplicated.add(inputEntry);
for(int ind2 = ind1 + 1; ind2 < inputEntries.size(); ind2++) {
WidgetEntry entry2 = inputEntries.get(ind2);
if (!hidden.contains(entry2) && inputEntry.duplicates(entry2)) {
hidden.add(entry2);
}
}
}
}
return deduplicated;
}

private List<WidgetEntry> addDayHeaders(List<WidgetEntry> listIn) {
List<WidgetEntry> listOut = new ArrayList<>();
if (!listIn.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILL_ALL_DAY;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILL_ALL_DAY_DEFAULT;
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_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 @@ -94,6 +95,7 @@ public static void fromInstanceSettings(Context context, Integer widgetId) {
setBoolean(context, PREF_MULTILINE_TITLE, settings.isTitleMultiline());
setBoolean(context, PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT, settings
.getShowOnlyClosestInstanceOfRecurringEvent());
setBoolean(context, PREF_HIDE_DUPLICATES, settings.getHideDuplicates());
setBoolean(context, PREF_INDICATE_ALERTS, settings.getIndicateAlerts());
setBoolean(context, PREF_INDICATE_RECURRING, settings.getIndicateRecurring());
for (Map.Entry<TextShadingPref, TextShading> entry: settings.shadings.entrySet()) {
Expand Down Expand Up @@ -316,6 +318,14 @@ public static void setShowOnlyClosestInstanceOfRecurringEvent(Context context, b
setBoolean(context, PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT, value);
}

public static boolean getHideDuplicates(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_HIDE_DUPLICATES, false);
}

public static void setHideDuplicates(Context context, boolean value) {
setBoolean(context, PREF_HIDE_DUPLICATES, value);
}

private static void setString(Context context, String key, String value) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public class InstanceSettings {
static final String PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT =
"showOnlyClosestInstanceOfRecurringEvent";
private boolean showOnlyClosestInstanceOfRecurringEvent = false;
static final String PREF_HIDE_DUPLICATES = "hideDuplicates";
private boolean hideDuplicates = false;

// ----------------------------------------------------------------------------------
// Calendars and task lists
Expand Down Expand Up @@ -227,6 +229,9 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws
settings.showOnlyClosestInstanceOfRecurringEvent = json.getBoolean(
PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT);
}
if (json.has(PREF_HIDE_DUPLICATES)) {
settings.hideDuplicates = json.getBoolean(PREF_HIDE_DUPLICATES);
}
if (json.has(PREF_INDICATE_ALERTS)) {
settings.indicateAlerts = json.getBoolean(PREF_INDICATE_ALERTS);
}
Expand Down Expand Up @@ -282,6 +287,7 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId
settings.titleMultiline = ApplicationPreferences.isTitleMultiline(context);
settings.showOnlyClosestInstanceOfRecurringEvent = ApplicationPreferences
.getShowOnlyClosestInstanceOfRecurringEvent(context);
settings.hideDuplicates = ApplicationPreferences.getHideDuplicates(context);
settings.indicateAlerts = ApplicationPreferences.getBoolean(context, PREF_INDICATE_ALERTS, true);
settings.indicateRecurring = ApplicationPreferences.getBoolean(context, PREF_INDICATE_RECURRING, false);
settings.widgetHeaderLayout = ApplicationPreferences.getWidgetHeaderLayout(context);
Expand Down Expand Up @@ -352,6 +358,7 @@ public JSONObject toJson() {
json.put(PREF_EVENT_ENTRY_LAYOUT, eventEntryLayout.value);
json.put(PREF_MULTILINE_TITLE, titleMultiline);
json.put(PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT, showOnlyClosestInstanceOfRecurringEvent);
json.put(PREF_HIDE_DUPLICATES, hideDuplicates);
json.put(PREF_INDICATE_ALERTS, indicateAlerts);
json.put(PREF_INDICATE_RECURRING, indicateRecurring);
json.put(PREF_WIDGET_HEADER_LAYOUT, widgetHeaderLayout.value);
Expand Down Expand Up @@ -498,6 +505,10 @@ public boolean getShowOnlyClosestInstanceOfRecurringEvent() {
return showOnlyClosestInstanceOfRecurringEvent;
}

public boolean getHideDuplicates() {
return hideDuplicates;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static CalendarEntry fromEvent(CalendarEvent event, DateTime entryDate) {
return entry;
}

@Override
public String getTitle() {
String title = event.getTitle();
if (TextUtils.isEmpty(title)) {
Expand All @@ -52,6 +53,7 @@ public boolean isAllDay() {
return allDay;
}

@Override
public String getLocation() {
return event.getLocation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public OrderedEventSource getSource() {
return event.getEventSource();
}

@Override
public String getTitle() {
return event.getTitle();
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/andstatus/todoagenda/widget/WidgetEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public OrderedEventSource getSource() {
return OrderedEventSource.EMPTY;
}

public String getTitle() {
return getClass().getName();
}

public String getLocation() {
return getClass().getName();
}

@Override
public String toString() {
return this.getClass().getSimpleName() + " [startDate=" + startDate + "]";
Expand Down Expand Up @@ -66,4 +74,11 @@ public TimeSection getEndTimeSection() {
? TimeSection.PAST
: (DateUtil.isToday(getStartDate()) ? TimeSection.TODAY : TimeSection.FUTURE);
}

public boolean duplicates(WidgetEntry other) {
return getStartDate().equals(other.getStartDate()) &&
getEndDate().equals(other.getEndDate()) &&
getTitle().equals(other.getTitle()) &&
getLocation().equals(other.getLocation());
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<string name="ended_one_year_ago">Ended one year ago</string>
<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>

<!-- Preference header: Feedback -->
<string name="feedback_prefs">Feedback</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences_event_filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
android:defaultValue="false"
android:key="showOnlyClosestInstanceOfRecurringEvent"
android:title="@string/show_only_closest_instance_of_recurring_event" />
<org.andstatus.todoagenda.prefs.MultilineCheckBoxPreference
android:defaultValue="false"
android:key="hideDuplicates"
android:title="@string/hide_duplicates" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit e271194

Please sign in to comment.