diff --git a/CHANGELOG.md b/CHANGELOG.md index 67da33ad..48a6fc21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Fixed simultaneous notifications all opening the same note (#43). - Fixed notification click not working if already editing a note. - Fixed notification creating new note if clicked after note is deleted. +- Remove check for internal list note consistency between content and metadata. ## v1.4.0 - Added a label attribute to hide all notes with that label in active & archive destinations. diff --git a/app/src/main/kotlin/com/maltaisn/notes/model/entity/Note.kt b/app/src/main/kotlin/com/maltaisn/notes/model/entity/Note.kt index 474d43f3..ae856e72 100644 --- a/app/src/main/kotlin/com/maltaisn/notes/model/entity/Note.kt +++ b/app/src/main/kotlin/com/maltaisn/notes/model/entity/Note.kt @@ -142,10 +142,10 @@ data class Note( return mutableListOf() } - check(checked.size == items.size) { "Invalid list note data." } +// check(checked.size == items.size) { "Invalid list note data." } return items.mapIndexedTo(mutableListOf()) { i, text -> - ListNoteItem(text.trim(), checked[i]) + ListNoteItem(text.trim(), checked.getOrElse(i) { false }) } } diff --git a/app/src/main/kotlin/com/maltaisn/notes/ui/edit/EditViewModel.kt b/app/src/main/kotlin/com/maltaisn/notes/ui/edit/EditViewModel.kt index 94add40b..ff15926f 100644 --- a/app/src/main/kotlin/com/maltaisn/notes/ui/edit/EditViewModel.kt +++ b/app/src/main/kotlin/com/maltaisn/notes/ui/edit/EditViewModel.kt @@ -546,14 +546,14 @@ class EditViewModel @AssistedInject constructor( } NoteType.LIST -> { // Add items in the correct actual order - val items = arrayOfNulls(listItems.count { it is EditItemItem }) + val items = MutableList(listItems.count { it is EditItemItem }) { TEMP_ITEM } for (item in listItems) { if (item is EditItemItem) { items[item.actualPos] = item } } - content = items.joinToString("\n") { it!!.content.text } - metadata = ListNoteMetadata(items.map { it!!.checked }) + content = items.joinToString("\n") { it.content.text } + metadata = ListNoteMetadata(items.map { it.checked }) } } note = note.copy(title = title, content = content, @@ -862,5 +862,7 @@ class EditViewModel @AssistedInject constructor( private const val KEY_NOTE_ID = "noteId" private const val KEY_IS_NEW_NOTE = "isNewNote" + + private val TEMP_ITEM = EditItemItem(DefaultEditableText(), false, false, 0) } } diff --git a/app/src/test/kotlin/com/maltaisn/notes/model/entity/NoteTest.kt b/app/src/test/kotlin/com/maltaisn/notes/model/entity/NoteTest.kt index f7e77d08..e47ab803 100644 --- a/app/src/test/kotlin/com/maltaisn/notes/model/entity/NoteTest.kt +++ b/app/src/test/kotlin/com/maltaisn/notes/model/entity/NoteTest.kt @@ -85,6 +85,17 @@ class NoteTest { } } + @Test + fun `should handle mismatch in list note metadata and content`() { + val items = listOf( + ListNoteItem("0", false), + ListNoteItem("1", true), + ListNoteItem("2", true)) + var note = listNote(items) + note = note.copy(content = note.content + "\n3") + assertEquals(items + ListNoteItem("3", false), note.listItems) + } + @Test fun `should fail to create deleted note with reminder`() { assertFailsWith {