From 5a2e44de8a8ef46fb48b2b4f1cd1aa99136936ce Mon Sep 17 00:00:00 2001 From: Dilan Goodwin Date: Fri, 21 Feb 2025 10:04:02 +0000 Subject: [PATCH 1/4] sortingNotes 001: Implemented notes creation time as a sorting field --- .../data/NoteRepositoryTestingImplementation.kt | 2 +- .../f_notetaking/presentation/NoteListUITesting.kt | 12 ++++++------ .../f_notetaking/domain/model/Note.kt | 2 +- .../f_notetaking/domain/use_case/GetNotes.kt | 2 +- .../f_notetaking/domain/util/SortType.kt | 2 +- .../presentation/notelist/NoteListViewModel.kt | 1 - .../f_notetaking/domain/use_case/NoteUseCasesTest.kt | 5 +++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/data/NoteRepositoryTestingImplementation.kt b/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/data/NoteRepositoryTestingImplementation.kt index cd03b86..0ebbe4a 100644 --- a/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/data/NoteRepositoryTestingImplementation.kt +++ b/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/data/NoteRepositoryTestingImplementation.kt @@ -21,7 +21,7 @@ class NoteRepositoryUiTestingImplementation(notes: List) : NoteRepository currentList.add( Note( content = note.content, - timeStamp = System.currentTimeMillis(), + creationTime = System.currentTimeMillis(), uid = currentList.size ) ) diff --git a/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt b/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt index c057d97..84f2ecf 100644 --- a/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt +++ b/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt @@ -33,9 +33,9 @@ class NoteListUITesting { private lateinit var noteUseCases: NoteUseCases private val notes: List = listOf( - Note(content = "Note1", timeStamp = 1740056347421, uid = 0), - Note(content = "Note2", timeStamp = 1740056372073, uid = 1), - Note(content = "Note3", timeStamp = 1740056372073, uid = 2) + Note(content = "Note1", creationTime = 1740056347421, uid = 0), + Note(content = "Note2", creationTime = 1740056372073, uid = 1), + Note(content = "Note3", creationTime = 1740056372073, uid = 2) ) @get:Rule @@ -148,10 +148,10 @@ class NoteListUITesting { @Test fun checkSortingNotesTimeStamp() { - changeSortType(SortType.TIMESTAMP) + changeSortType(SortType.CREATION_TIME) + + val sortedNotes = notes.sortedBy { it.creationTime } - val sortedNotes = notes.sortedBy { it.timeStamp } - for (i in sortedNotes.indices) { composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i) .assertTextContains(value = sortedNotes[i].content) diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt index 4a7e9be..e70c50e 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt @@ -14,6 +14,6 @@ import androidx.room.PrimaryKey @Entity data class Note( var content: String = "", - var timeStamp: Long = 0, + var creationTime: Long = 0, @PrimaryKey(autoGenerate = true) val uid: Int? = null ) diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt index 33e2613..de22150 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt @@ -24,7 +24,7 @@ class GetNotes(private val repository: NoteRepository) { when (sortType) { SortType.ID -> notes.sortedBy { it.uid } SortType.CONTENT -> notes.sortedBy { it.content.lowercase() } - SortType.TIMESTAMP -> notes.sortedBy { it.timeStamp } + SortType.CREATION_TIME -> notes.sortedBy { it.creationTime } } } } diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt index 8ab9b1f..a599350 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt @@ -3,5 +3,5 @@ package com.learning.simplenotetakingapplication.f_notetaking.domain.util enum class SortType { ID, CONTENT, - TIMESTAMP + CREATION_TIME } \ No newline at end of file diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt index ef32233..854bc80 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt @@ -43,7 +43,6 @@ class NoteListViewModel(private val noteUseCases: NoteUseCases) : ViewModel() { NoteListEvent.SaveNote -> { if (_state.value.newNoteContent.isBlank()) return _state.value.currentNote.content = _state.value.newNoteContent - _state.value.currentNote.timeStamp = System.currentTimeMillis() viewModelScope.launch { noteUseCases.upsertNote(_state.value.currentNote) } onEvent(NoteListEvent.SetNote(note = Note())) } diff --git a/app/src/test/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/NoteUseCasesTest.kt b/app/src/test/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/NoteUseCasesTest.kt index 58c8edf..442afac 100644 --- a/app/src/test/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/NoteUseCasesTest.kt +++ b/app/src/test/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/NoteUseCasesTest.kt @@ -66,8 +66,9 @@ class NoteUseCasesTest { @Test fun gettingNotesOrderedTimeStamp() = runTest { - val listNotes = flattenNotesFlowToList(noteUseCases.getNotes(sortType = SortType.TIMESTAMP)) - assertEquals("", notes.sortedBy { it.timeStamp }, listNotes) + val listNotes = + flattenNotesFlowToList(noteUseCases.getNotes(sortType = SortType.CREATION_TIME)) + assertEquals("", notes.sortedBy { it.creationTime }, listNotes) } @Test From 2c0b415fabab25ce0f087c64b735b898cde7d685 Mon Sep 17 00:00:00 2001 From: Dilan Goodwin Date: Fri, 21 Feb 2025 10:32:53 +0000 Subject: [PATCH 2/4] sortingNotes 002: Created updatedTime value to sort notes by when they were last updated --- .../f_notetaking/domain/model/Note.kt | 1 + .../f_notetaking/domain/use_case/GetNotes.kt | 1 + .../f_notetaking/domain/util/SortType.kt | 3 ++- .../f_notetaking/presentation/notelist/NoteListViewModel.kt | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt index e70c50e..14748f5 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt @@ -15,5 +15,6 @@ import androidx.room.PrimaryKey data class Note( var content: String = "", var creationTime: Long = 0, + var updatedTime: Long = 0, @PrimaryKey(autoGenerate = true) val uid: Int? = null ) diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt index de22150..0589128 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt @@ -25,6 +25,7 @@ class GetNotes(private val repository: NoteRepository) { SortType.ID -> notes.sortedBy { it.uid } SortType.CONTENT -> notes.sortedBy { it.content.lowercase() } SortType.CREATION_TIME -> notes.sortedBy { it.creationTime } + SortType.UPDATED_TIME -> notes.sortedBy { it.updatedTime } } } } diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt index a599350..f4605ce 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt @@ -3,5 +3,6 @@ package com.learning.simplenotetakingapplication.f_notetaking.domain.util enum class SortType { ID, CONTENT, - CREATION_TIME + CREATION_TIME, + UPDATED_TIME } \ No newline at end of file diff --git a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt index 854bc80..2e36fcb 100644 --- a/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt +++ b/app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt @@ -42,6 +42,11 @@ class NoteListViewModel(private val noteUseCases: NoteUseCases) : ViewModel() { is NoteListEvent.UpdateSortType -> _sortType.value = event.sortType NoteListEvent.SaveNote -> { if (_state.value.newNoteContent.isBlank()) return + if (_state.value.currentNote.creationTime == 0.toLong()) { + _state.value.currentNote.creationTime = System.currentTimeMillis() + } + + _state.value.currentNote.updatedTime = System.currentTimeMillis() _state.value.currentNote.content = _state.value.newNoteContent viewModelScope.launch { noteUseCases.upsertNote(_state.value.currentNote) } onEvent(NoteListEvent.SetNote(note = Note())) From 50906ce71f84c2e5feaec75414edf3b2c3170f26 Mon Sep 17 00:00:00 2001 From: Dilan Goodwin Date: Fri, 21 Feb 2025 12:28:18 +0000 Subject: [PATCH 3/4] sortingNotes 003: Created testing for updated time ordering field --- .../presentation/NoteListUITesting.kt | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt b/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt index 84f2ecf..6375c46 100644 --- a/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt +++ b/app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt @@ -48,6 +48,15 @@ class NoteListUITesting { composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick() } + private fun editNote(originalContent: String, newContent: String) { + composeTestRule.onNodeWithText(text = originalContent).performClick() + composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick() + .performTextClearance() + composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick() + .performTextInput(text = newContent) + composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick() + } + private fun changeSortType(sortType: SortType) { composeTestRule.onNodeWithTag(testTag = TestTagChangeSortType).performClick() composeTestRule.onNodeWithText(text = sortType.toString().lowercase()).performClick() @@ -124,13 +133,8 @@ class NoteListUITesting { @Test fun editNote() = runTest { val changedNoteText = "Something" + editNote(originalContent = "Node1", newContent = changedNoteText) - composeTestRule.onNodeWithText("Note1").performClick() - composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick() - .performTextClearance() - composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick() - .performTextInput(text = changedNoteText) - composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick() composeTestRule.onNodeWithText(text = changedNoteText).assertExists() } @@ -147,7 +151,7 @@ class NoteListUITesting { } @Test - fun checkSortingNotesTimeStamp() { + fun checkSortingNotesCreationTime() { changeSortType(SortType.CREATION_TIME) val sortedNotes = notes.sortedBy { it.creationTime } @@ -158,9 +162,22 @@ class NoteListUITesting { } } + @Test + fun checkSortingNotesUpdatedTime() { + changeSortType(SortType.UPDATED_TIME) + + val sortedNotes = notes.sortedBy { it.updatedTime } + + for (i in sortedNotes.indices) { + composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i) + .assertTextContains(value = sortedNotes[i].content) + } + } + @Test fun checkChangingSortingNotes() { - checkSortingNotesTimeStamp() + checkSortingNotesCreationTime() + checkSortingNotesUpdatedTime() checkSortingNotesContent() } } \ No newline at end of file From 93d64ae4c9867b02835515fd68d70d42174c441c Mon Sep 17 00:00:00 2001 From: Dilan Goodwin Date: Fri, 21 Feb 2025 12:29:37 +0000 Subject: [PATCH 4/4] sortingNotes 004: Updated README.md TODOs for the now completed tasks --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0f8e88..7d3da4f 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ On click handler for the note view creates dialog window for editing previous no # ToDos ## Main Application -- [ ] Sorting notes based on creation time -- [ ] Sorting notes based on last edited time +- [x] Sorting notes based on creation time +- [x] Sorting notes based on last edited time - [ ] Deleting notes - [ ] Viewing deleted notes - [ ] Restoring deleted notes ## Widget -- [ ] Selection of note to view \ No newline at end of file +- [ ] Selection of note to view