From 94f4b3366c2d5f24b4daafda7e996c32cd959bff Mon Sep 17 00:00:00 2001 From: mrkuz Date: Mon, 26 Jul 2021 12:34:31 +0200 Subject: [PATCH] Add preference to hide empty days in agenda. Resolves #516 --- .../java/com/orgzly/android/prefs/AppPreferences.java | 10 ++++++++++ .../android/ui/notes/query/agenda/AgendaFragment.kt | 3 ++- .../android/ui/notes/query/agenda/AgendaItems.kt | 7 ++++--- .../com/orgzly/android/widgets/ListWidgetService.kt | 3 ++- app/src/main/res/values-de-rDE/strings.xml | 1 + app/src/main/res/values/prefs_keys.xml | 3 +++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/prefs_screen_look_and_feel.xml | 8 ++++++++ 8 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java b/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java index 9236fef97..40b31547a 100644 --- a/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java +++ b/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java @@ -745,6 +745,16 @@ public static boolean keepScreenOnMenuItem(Context context) { context.getResources().getBoolean(R.bool.pref_default_keep_screen_on_menu_item)); } + /* + * Hide empty days in agenda + */ + + public static boolean hideEmptyDaysInAgenda(Context context) { + return getDefaultSharedPreferences(context).getBoolean( + context.getResources().getString(R.string.pref_key_hide_empty_days_in_agenda), + context.getResources().getBoolean(R.bool.pref_default_hide_empty_days_in_agenda)); + } + /* * Widget */ diff --git a/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaFragment.kt b/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaFragment.kt index 728580875..97158c2d7 100644 --- a/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaFragment.kt +++ b/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaFragment.kt @@ -133,7 +133,8 @@ class AgendaFragment : viewModel.notes().observe(viewLifecycleOwner, Observer { notes -> if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "Observed notes: ${notes.size}") - val items = AgendaItems.getList(notes, currentQuery, item2databaseIds) + val hideEmptyDaysInAgenda = AppPreferences.hideEmptyDaysInAgenda(context) + val items = AgendaItems(hideEmptyDaysInAgenda).getList(notes, currentQuery, item2databaseIds) if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "Replacing data with ${items.size} agenda items") diff --git a/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaItems.kt b/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaItems.kt index e6a23840f..c18b6807d 100644 --- a/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaItems.kt +++ b/app/src/main/java/com/orgzly/android/ui/notes/query/agenda/AgendaItems.kt @@ -9,7 +9,7 @@ import com.orgzly.org.datetime.OrgInterval import com.orgzly.org.datetime.OrgRange import org.joda.time.DateTime -object AgendaItems { +class AgendaItems(private val hideEmptyDaysInAgenda : Boolean) { data class ExpandableOrgRange( val range: OrgRange, val canBeOverdueToday: Boolean, @@ -136,8 +136,9 @@ object AgendaItems { // Add daily dailyNotes.forEach { d -> - // Always add day heading - result.add(AgendaItem.Day(agendaItemId++, DateTime(d.key))) + if (d.value.isNotEmpty() || !hideEmptyDaysInAgenda) { + result.add(AgendaItem.Day(agendaItemId++, DateTime(d.key))) + } if (d.value.isNotEmpty()) { result.addAll(d.value) diff --git a/app/src/main/java/com/orgzly/android/widgets/ListWidgetService.kt b/app/src/main/java/com/orgzly/android/widgets/ListWidgetService.kt index 62bc1b3a8..ea1684417 100644 --- a/app/src/main/java/com/orgzly/android/widgets/ListWidgetService.kt +++ b/app/src/main/java/com/orgzly/android/widgets/ListWidgetService.kt @@ -96,7 +96,8 @@ class ListWidgetService : RemoteViewsService() { if (query.isAgenda()) { val idMap = mutableMapOf() - val agendaItems = AgendaItems.getList(notes, query, idMap) + val hideEmptyDaysInAgenda = AppPreferences.hideEmptyDaysInAgenda(context) + val agendaItems = AgendaItems(hideEmptyDaysInAgenda).getList(notes, query, idMap) dataList = agendaItems.map { when (it) { diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 18038970b..24e7b425d 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -381,6 +381,7 @@ Keine Status definiert Notizbuchname in den Suchergebnissen Notizbuchname anzeigen + Tage ohne Notizen in Agenda ausblenden Geerbte Schlagwörter in Suchergebnissen Geerbte Schlagwörter in Suchergebnissen anzeigen Aktuell diff --git a/app/src/main/res/values/prefs_keys.xml b/app/src/main/res/values/prefs_keys.xml index d221a69f9..4510b562d 100644 --- a/app/src/main/res/values/prefs_keys.xml +++ b/app/src/main/res/values/prefs_keys.xml @@ -296,6 +296,9 @@ pref_key_keep_screen_on_menu_item false + pref_key_hide_empty_days_in_agenda + false + pref_key_selected_note_metadata @string/tags diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index beaf66ce1..22295842d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -445,6 +445,7 @@ Notebook name in search results Display notebook name + Hide empty days in agenda Inherited tags in search results Display inherited tags in search results diff --git a/app/src/main/res/xml/prefs_screen_look_and_feel.xml b/app/src/main/res/xml/prefs_screen_look_and_feel.xml index e5c77d551..95f0abbba 100644 --- a/app/src/main/res/xml/prefs_screen_look_and_feel.xml +++ b/app/src/main/res/xml/prefs_screen_look_and_feel.xml @@ -58,4 +58,12 @@ android:summary="Ignore default locale" android:defaultValue="@bool/pref_default_ignore_system_locale"/> + + + + +