Skip to content

Commit

Permalink
Resolves #43.
Browse files Browse the repository at this point in the history
Adds last modified sort option.
  • Loading branch information
coderPaddyS committed Nov 4, 2023
1 parent 5f4a727 commit d56d613
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SortingOrder(context: Context) {
enum class Options {
AlphabeticalAscending,
TypeAscending,
Creation
Creation,
LastModified
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ interface NoteDao {
@get:Query("SELECT * FROM notes WHERE in_trash = 0 ORDER BY _id ASC")
val allActiveNotesCreation: Flow<List<Note>>

@get:Query("SELECT * FROM notes WHERE in_trash = 0 ORDER BY last_modified DESC")
val allActiveNotesModified: Flow<List<Note>>

@get:Query("SELECT * FROM notes WHERE in_trash = 1 ORDER BY name DESC")
val allTrashedNotes: LiveData<List<Note>>

Expand All @@ -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<List<Note?>?>

@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<List<Note?>?>

@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<List<Note>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_mode_edit_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="?attr/colorIconFill" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@
<item>Alphabetisch</item>
<item>Notizart</item>
<item>Erstellungszeit</item>
<item>Zuletzt verändert</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<item>@drawable/ic_sort_by_alpha_icon_24dp</item>
<item>@drawable/ic_baseline_edit_note_icon_24dp</item>
<item>@drawable/ic_baseline_access_time_icon_24dp</item>
<item>@drawable/ic_baseline_mode_edit_24dp</item>
<!-- <item>Alphabetical Descending</item>-->
</integer-array>

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 @@ -171,6 +171,7 @@
<item>Alphabetical</item>
<item>Note Type</item>
<item>Creation Time</item>
<item>Last Modified</item>
</string-array>

</resources>

0 comments on commit d56d613

Please sign in to comment.