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 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..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 @@ -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 @@ -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,11 +151,23 @@ class NoteListUITesting { } @Test - fun checkSortingNotesTimeStamp() { - changeSortType(SortType.TIMESTAMP) + fun checkSortingNotesCreationTime() { + changeSortType(SortType.CREATION_TIME) - val sortedNotes = notes.sortedBy { it.timeStamp } + val sortedNotes = notes.sortedBy { it.creationTime } + + for (i in sortedNotes.indices) { + composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i) + .assertTextContains(value = sortedNotes[i].content) + } + } + + @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) @@ -160,7 +176,8 @@ class NoteListUITesting { @Test fun checkChangingSortingNotes() { - checkSortingNotesTimeStamp() + checkSortingNotesCreationTime() + checkSortingNotesUpdatedTime() checkSortingNotesContent() } } \ No newline at end of file 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..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 @@ -14,6 +14,7 @@ import androidx.room.PrimaryKey @Entity data class Note( var content: String = "", - var timeStamp: Long = 0, + 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 33e2613..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 @@ -24,7 +24,8 @@ 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 } + 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 8ab9b1f..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, - TIMESTAMP + 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 ef32233..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,8 +42,12 @@ 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 - _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