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 preference to hide empty days in agenda. #871

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions app/src/main/java/com/orgzly/android/prefs/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class ListWidgetService : RemoteViewsService() {

if (query.isAgenda()) {
val idMap = mutableMapOf<Long, Long>()
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) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
<string name="no_states_defined">Keine Status definiert</string>
<string name="book_name_in_search">Notizbuchname in den Suchergebnissen</string>
<string name="display_notebook_name">Notizbuchname anzeigen</string>
<string name="hide_empty_days_in_agenda">Tage ohne Notizen in Agenda ausblenden</string>
<string name="display_inherited_tags_in_search_results">Geerbte Schlagwörter in Suchergebnissen</string>
<string name="display_inherited_tags_in_search_results_summary">Geerbte Schlagwörter in Suchergebnissen anzeigen</string>
<string name="ongoing_notification">Aktuell</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
<string name="pref_key_keep_screen_on_menu_item" translatable="false">pref_key_keep_screen_on_menu_item</string>
<bool name="pref_default_keep_screen_on_menu_item" translatable="false">false</bool>

<string name="pref_key_hide_empty_days_in_agenda" translatable="false">pref_key_hide_empty_days_in_agenda</string>
<bool name="pref_default_hide_empty_days_in_agenda" translatable="false">false</bool>

<string name="pref_key_selected_note_metadata" translatable="false">pref_key_selected_note_metadata</string>
<string-array name="note_metadata">
<item>@string/tags</item>
Expand Down
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 @@ -445,6 +445,7 @@
<string name="book_name_in_search">Notebook name in search results</string>

<string name="display_notebook_name">Display notebook name</string>
<string name="hide_empty_days_in_agenda">Hide empty days in agenda</string>

<string name="display_inherited_tags_in_search_results">Inherited tags in search results</string>
<string name="display_inherited_tags_in_search_results_summary">Display inherited tags in search results</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/prefs_screen_look_and_feel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@
android:summary="Ignore default locale"
android:defaultValue="@bool/pref_default_ignore_system_locale"/>

<PreferenceCategory android:title="@string/agenda">

<SwitchPreference
android:key="@string/pref_key_hide_empty_days_in_agenda"
android:title="@string/hide_empty_days_in_agenda"
android:defaultValue="@bool/pref_default_hide_empty_days_in_agenda" />
</PreferenceCategory>

</androidx.preference.PreferenceScreen>