From d56d6138002783d0f3cd84835295bbe657180891 Mon Sep 17 00:00:00 2001 From: Patrick Schneider Date: Sat, 4 Nov 2023 11:49:36 +0100 Subject: [PATCH] Resolves #43. Adds last modified sort option. --- .../org/secuso/privacyfriendlynotes/model/SortingOrder.kt | 3 ++- .../org/secuso/privacyfriendlynotes/room/dao/NoteDao.kt | 6 ++++++ .../privacyfriendlynotes/ui/main/MainActivityViewModel.kt | 2 ++ app/src/main/res/drawable/ic_baseline_mode_edit_24dp.xml | 5 +++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/arrays.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_baseline_mode_edit_24dp.xml diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/model/SortingOrder.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/model/SortingOrder.kt index 7b6d0b43..a1ddf0f6 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/model/SortingOrder.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/model/SortingOrder.kt @@ -20,6 +20,7 @@ class SortingOrder(context: Context) { enum class Options { AlphabeticalAscending, TypeAscending, - Creation + Creation, + LastModified } } \ No newline at end of file diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/room/dao/NoteDao.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/room/dao/NoteDao.kt index 60384492..33f59d23 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/room/dao/NoteDao.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/room/dao/NoteDao.kt @@ -51,6 +51,9 @@ interface NoteDao { @get:Query("SELECT * FROM notes WHERE in_trash = 0 ORDER BY _id ASC") val allActiveNotesCreation: Flow> + @get:Query("SELECT * FROM notes WHERE in_trash = 0 ORDER BY last_modified DESC") + val allActiveNotesModified: Flow> + @get:Query("SELECT * FROM notes WHERE in_trash = 1 ORDER BY name DESC") val allTrashedNotes: LiveData> @@ -66,6 +69,9 @@ interface NoteDao { @Query("SELECT * FROM notes WHERE ((LOWER(name) LIKE '%'|| LOWER(:thisFilterText) || '%') OR (LOWER(content) LIKE '%'|| LOWER(:thisFilterText) || '%' AND type = 3) OR type = 1) AND in_trash='0' ORDER BY _id ASC") fun activeNotesFilteredCreation(thisFilterText: String): Flow?> + @Query("SELECT * FROM notes WHERE ((LOWER(name) LIKE '%'|| LOWER(:thisFilterText) || '%') OR (LOWER(content) LIKE '%'|| LOWER(:thisFilterText) || '%' AND type = 3) OR type = 1) AND in_trash='0' ORDER BY last_modified DESC") + fun activeNotesFilteredModified(thisFilterText: String): Flow?> + @Query("SELECT * FROM notes WHERE ((LOWER(name) LIKE '%'|| LOWER(:thisFilterText) || '%') OR (LOWER(content) LIKE '%'|| LOWER(:thisFilterText) || '%' AND type = 3) OR type = 1) AND in_trash='1' ORDER BY name DESC") fun trashedNotesFiltered(thisFilterText: String): Flow> diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt index 9db68191..f75c4afd 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt @@ -116,6 +116,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica SortingOrder.Options.AlphabeticalAscending -> repository.noteDao().allActiveNotesAlphabetical SortingOrder.Options.TypeAscending -> repository.noteDao().allActiveNotesType SortingOrder.Options.Creation -> repository.noteDao().allActiveNotesCreation + SortingOrder.Options.LastModified -> repository.noteDao().allActiveNotesModified } flow.collect { notes.value = it @@ -131,6 +132,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica SortingOrder.Options.AlphabeticalAscending -> repository.noteDao().activeNotesFilteredAlphabetical(filter) SortingOrder.Options.TypeAscending -> repository.noteDao().activeNotesFilteredType(filter) SortingOrder.Options.Creation -> repository.noteDao().activeNotesFilteredCreation(filter) + SortingOrder.Options.LastModified -> repository.noteDao().activeNotesFilteredModified(filter) } filterNoteFlow(filter, flow).collect { filteredNotes.value = it diff --git a/app/src/main/res/drawable/ic_baseline_mode_edit_24dp.xml b/app/src/main/res/drawable/ic_baseline_mode_edit_24dp.xml new file mode 100644 index 00000000..6787c41a --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_mode_edit_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b5182d35..560f6693 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -142,5 +142,6 @@ Alphabetisch Notizart Erstellungszeit + Zuletzt verändert \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 5d47f77a..fdd4f87f 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -59,6 +59,7 @@ @drawable/ic_sort_by_alpha_icon_24dp @drawable/ic_baseline_edit_note_icon_24dp @drawable/ic_baseline_access_time_icon_24dp + @drawable/ic_baseline_mode_edit_24dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 458492a1..bbeba942 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -171,6 +171,7 @@ Alphabetical Note Type Creation Time + Last Modified