diff --git a/.gitignore b/.gitignore index a5b8309..16674e3 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ timeline/.idea/copilot/ ### Project Specific Files ### **/resources/*.schema.json +/sample/**/*.json diff --git a/parser/build.gradle.kts b/parser/build.gradle.kts index 59af1c5..7366106 100644 --- a/parser/build.gradle.kts +++ b/parser/build.gradle.kts @@ -19,6 +19,7 @@ repositories { dependencies { implementation("com.squareup.moshi:moshi-kotlin:1.15.1") + implementation("com.squareup.moshi:moshi-adapters:1.15.1") ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.1") implementation("com.squareup.okio:okio:3.9.0") testImplementation("org.jetbrains.kotlin:kotlin-test") diff --git a/parser/src/main/kotlin/Main.kt b/parser/src/main/kotlin/Main.kt deleted file mode 100644 index 9553807..0000000 --- a/parser/src/main/kotlin/Main.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.hossain.timeline - -fun main() { - println("Main function from parser module.") -} diff --git a/parser/src/main/kotlin/Parser.kt b/parser/src/main/kotlin/Parser.kt index 1d277ba..13d8b13 100644 --- a/parser/src/main/kotlin/Parser.kt +++ b/parser/src/main/kotlin/Parser.kt @@ -2,6 +2,8 @@ package dev.hossain.timeline import ZonedDateTimeAdapter import com.squareup.moshi.Moshi +import com.squareup.moshi.adapters.EnumJsonAdapter +import dev.hossain.timeline.model.ActivityType import dev.hossain.timeline.model.Records import dev.hossain.timeline.model.SemanticTimeline import dev.hossain.timeline.model.Settings @@ -14,6 +16,10 @@ class Parser constructor() { private val moshi: Moshi = Moshi.Builder() .add(ZonedDateTimeAdapter()) + .add( + ActivityType::class.java, + EnumJsonAdapter.create(ActivityType::class.java).withUnknownFallback(ActivityType.UNKNOWN), + ) .build() /** diff --git a/parser/src/main/kotlin/model/Records.kt b/parser/src/main/kotlin/model/Records.kt index 26f6727..94df509 100644 --- a/parser/src/main/kotlin/model/Records.kt +++ b/parser/src/main/kotlin/model/Records.kt @@ -121,7 +121,7 @@ data class AccessPoint( /** * Whether the device that scanned the access point is connected to it. */ - val isConnected: Boolean, + val isConnected: Boolean?, ) /** @@ -178,26 +178,32 @@ enum class ActivityType(val title: String, val extraColor: String) { BOATING("Boating", "#01579b"), CATCHING_POKEMON("Catching Pokémon", "#db4437"), CYCLING("Cycling", "#4db6ac"), + EXITING_VEHICLE("Exiting a vehicle", "#01579b"), FLYING("Flying", "#3f51b5"), HIKING("Hiking", "#c2185b"), HORSEBACK_RIDING("Horseback riding", "#4db6ac"), IN_BUS("On a bus", "#01579b"), IN_CABLECAR("In a cable car", "#01579b"), + IN_CAR("In a car", "#01579b"), IN_FERRY("On a ferry", "#01579b"), + IN_FOUR_WHEELER_VEHICLE("In a four wheeler vehicle", "#01579b"), IN_FUNICULAR("On a funicular", "#01579b"), IN_GONDOLA_LIFT("In a gondola lift", "#01579b"), IN_PASSENGER_VEHICLE("Driving", "#01579b"), + IN_RAIL_VEHICLE("In a rail vehicle", "#01579b"), + IN_ROAD_VEHICLE("In a road vehicle", "#03a9f4"), IN_SUBWAY("On the subway", "#01579b"), IN_TAXI("In a taxi", "#01579b"), IN_TRAIN("On a train", "#01579b"), IN_TRAM("On a tram", "#01579b"), + IN_TWO_WHEELER_VEHICLE("On a two wheeler vehicle", "#01579b"), IN_VEHICLE("In a vehicle", "#03a9f4"), IN_WHEELCHAIR("By wheelchair", "#03a9f4"), KAYAKING("Kayaking", "#4db6ac"), KITESURFING("Kitesurfing", "#4db6ac"), MOTORCYCLING("Motorcycling", "#01579b"), - ON_FOOT("On foot", "#c2185b"), ON_BICYCLE("On a bicycle", "#4db6ac"), + ON_FOOT("On foot", "#c2185b"), PARAGLIDING("Paragliding", "#4db6ac"), ROWING("Rowing", "#c2185b"), RUNNING("Running", "#c2185b"), diff --git a/parser/src/test/kotlin/dev/hossain/timeline/model/RecordsTestCopilot.kt b/parser/src/test/kotlin/dev/hossain/timeline/model/RecordsTestCopilot.kt index ecddc19..2ea6d1d 100644 --- a/parser/src/test/kotlin/dev/hossain/timeline/model/RecordsTestCopilot.kt +++ b/parser/src/test/kotlin/dev/hossain/timeline/model/RecordsTestCopilot.kt @@ -75,7 +75,7 @@ class RecordsTestCopilot { assertEquals("00:00:00:00:00:00", accessPoint.mac) assertEquals(100, accessPoint.strength) assertEquals(2400, accessPoint.frequencyMhz) - assertTrue(accessPoint.isConnected) + assertTrue(accessPoint.isConnected!!) } @Test diff --git a/sample/src/main/kotlin/Main.kt b/sample/src/main/kotlin/Main.kt index 10c4c77..7493323 100644 --- a/sample/src/main/kotlin/Main.kt +++ b/sample/src/main/kotlin/Main.kt @@ -1,5 +1,14 @@ package dev.hossain.timeline +import java.io.File + fun main() { - println("Sample app for timeline project.") + println("Sample app for timeline project.") + val parser = Parser() + // load "Records.json" file + val recordsJson = parser::class.java.classLoader.getResource("Records.json")?.readText()!! + val records = parser.parseRecords(recordsJson) + + println("Got records: ${records.locations.size} records.") + println() }