Reimplemented LunaEvent as a bare JSONObject to allow for expandability

This commit is contained in:
2024-11-22 08:01:19 +01:00
parent 653c57e6e0
commit abee1be72c
5 changed files with 90 additions and 83 deletions

View File

@@ -5,6 +5,7 @@ import it.danieleverducci.lunatracker.entities.Logbook
import android.util.Log
import it.danieleverducci.lunatracker.entities.LunaEvent
import org.json.JSONArray
import org.json.JSONException
import java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
@@ -31,9 +32,13 @@ class FileLogbookRepository: LogbookRepository {
val json = FileInputStream(file).bufferedReader().use { it.readText() }
val ja = JSONArray(json)
for (i in 0 until ja.length()) {
val jo = ja.getJSONObject(i)
val evt = LunaEvent.fromJson(jo)
logbook.logs.add(evt)
try {
val evt: LunaEvent = LunaEvent(ja.getJSONObject(i))
logbook.logs.add(evt)
} catch (e: IllegalArgumentException) {
// Mangled JSON?
throw JSONException(e.toString())
}
}
return logbook
}

View File

@@ -59,9 +59,13 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
val ja = JSONArray(json)
val logbook = Logbook()
for (i in 0 until ja.length()) {
val jo = ja.getJSONObject(i)
val evt = LunaEvent.fromJson(jo)
logbook.logs.add(evt)
try {
val evt: LunaEvent = LunaEvent(ja.getJSONObject(i))
logbook.logs.add(evt)
} catch (e: IllegalArgumentException) {
// Mangled JSON?
throw JSONException(e.toString())
}
}
Log.d(TAG, "Loaded ${logbook.logs.size} events into logbook")
return logbook