mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-28 20:29:54 +00:00
Add viewMode to BaseNote.toJson
This commit is contained in:
parent
b5e13ce73a
commit
9fd735ba95
4 changed files with 89 additions and 7 deletions
|
@ -146,7 +146,7 @@ object Converters {
|
|||
JSONObject().apply {
|
||||
put("id", reminder.id) // Store date as long timestamp
|
||||
put("dateTime", reminder.dateTime.time) // Store date as long timestamp
|
||||
put("repetition", reminder.repetition?.let { repetitionToJson(it) })
|
||||
put("repetition", reminder.repetition?.let { repetitionToJsonObject(it) })
|
||||
}
|
||||
}
|
||||
return JSONArray(objects)
|
||||
|
@ -165,10 +165,14 @@ object Converters {
|
|||
|
||||
@TypeConverter
|
||||
fun repetitionToJson(repetition: Repetition): String {
|
||||
return repetitionToJsonObject(repetition).toString()
|
||||
}
|
||||
|
||||
fun repetitionToJsonObject(repetition: Repetition): JSONObject {
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("value", repetition.value)
|
||||
jsonObject.put("unit", repetition.unit.name) // Store the TimeUnit as a string
|
||||
return jsonObject.toString()
|
||||
return jsonObject
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
|
|
|
@ -80,7 +80,8 @@ fun BaseNote.toJson(): String {
|
|||
.put("color", color)
|
||||
.put("title", title)
|
||||
.put("pinned", pinned)
|
||||
.put("date-created", timestamp)
|
||||
.put("timestamp", timestamp)
|
||||
.put("modifiedTimestamp", modifiedTimestamp)
|
||||
.put("labels", JSONArray(labels))
|
||||
|
||||
when (type) {
|
||||
|
@ -94,6 +95,7 @@ fun BaseNote.toJson(): String {
|
|||
}
|
||||
}
|
||||
jsonObject.put("reminders", Converters.remindersToJSONArray(reminders))
|
||||
jsonObject.put("viewMode", viewMode.name)
|
||||
return jsonObject.toString(2)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.philkes.notallyx.data.model.BaseNote
|
|||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.Reminder
|
||||
import com.philkes.notallyx.data.model.SpanRepresentation
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
|
@ -252,7 +253,7 @@ class GoogleKeepImporterTest {
|
|||
files,
|
||||
audios,
|
||||
reminders,
|
||||
null,
|
||||
NoteViewMode.EDIT,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import com.philkes.notallyx.test.createListItem
|
||||
import java.util.Date
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito.anyString
|
||||
|
@ -16,9 +18,10 @@ class ModelExtensionsTest {
|
|||
"color": "#E2F6D3",
|
||||
"title": "Test",
|
||||
"pinned": false,
|
||||
"date-created": 1742822848689,
|
||||
"timestamp": 1742822848689,
|
||||
"modifiedTimestamp": 1742823434623,
|
||||
"labels": [
|
||||
"Ggg"
|
||||
"TestLabel"
|
||||
],
|
||||
"items": [
|
||||
{
|
||||
|
@ -58,7 +61,8 @@ class ModelExtensionsTest {
|
|||
"dateTime": 1742822940000,
|
||||
"repetition": "{\"value\":1,\"unit\":\"DAYS\"}"
|
||||
}
|
||||
]
|
||||
],
|
||||
"viewMode": "READ_ONLY"
|
||||
}
|
||||
"""
|
||||
val colorMock = mockStatic(android.graphics.Color::class.java)
|
||||
|
@ -81,6 +85,77 @@ class ModelExtensionsTest {
|
|||
baseNote.items,
|
||||
)
|
||||
assertEquals(1, baseNote.reminders.size)
|
||||
assertEquals(1742822848689, baseNote.timestamp)
|
||||
assertEquals(1742823434623, baseNote.modifiedTimestamp)
|
||||
assertEquals(NoteViewMode.READ_ONLY, baseNote.viewMode)
|
||||
assertEquals(listOf("TestLabel"), baseNote.labels)
|
||||
assertEquals(Repetition(1, RepetitionTimeUnit.DAYS), baseNote.reminders[0].repetition)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BaseNote toJson()`() {
|
||||
val baseNote =
|
||||
BaseNote(
|
||||
id = 1,
|
||||
Type.LIST,
|
||||
Folder.DELETED,
|
||||
"#E2F6D3",
|
||||
"Title",
|
||||
true,
|
||||
12354632465L,
|
||||
945869546L,
|
||||
listOf("label"),
|
||||
"Body",
|
||||
listOf(SpanRepresentation(0, 10, bold = true)),
|
||||
mutableListOf(
|
||||
createListItem("Item1", true, false),
|
||||
createListItem("Item2", true, true),
|
||||
),
|
||||
listOf(FileAttachment("localImage", "originalImage", "image/jpeg")),
|
||||
listOf(FileAttachment("localFile", "originalFile", "text/plain")),
|
||||
listOf(Audio("audio", 10L, 12312334L)),
|
||||
listOf(Reminder(1, Date(1743253506957), Repetition(10, RepetitionTimeUnit.WEEKS))),
|
||||
NoteViewMode.READ_ONLY,
|
||||
)
|
||||
|
||||
val json = baseNote.toJson()
|
||||
|
||||
assertEquals(
|
||||
"""
|
||||
{
|
||||
"reminders": [{
|
||||
"dateTime": 1743253506957,
|
||||
"id": 1,
|
||||
"repetition": {
|
||||
"unit": "WEEKS",
|
||||
"value": 10
|
||||
}
|
||||
}],
|
||||
"pinned": true,
|
||||
"color": "#E2F6D3",
|
||||
"modifiedTimestamp": 945869546,
|
||||
"type": "LIST",
|
||||
"title": "Title",
|
||||
"viewMode": "READ_ONLY",
|
||||
"items": [
|
||||
{
|
||||
"checked": true,
|
||||
"body": "Item1",
|
||||
"isChild": false
|
||||
},
|
||||
{
|
||||
"checked": true,
|
||||
"body": "Item2",
|
||||
"isChild": true
|
||||
}
|
||||
],
|
||||
"timestamp": 12354632465,
|
||||
"labels": ["label"]
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
.trimStart(),
|
||||
json,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue