-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/android/view builder and speed json #360
base: main
Are you sure you want to change the base?
Changes from all commits
b5151f0
8a989e7
a1dd74b
8a7659b
a7d5d28
2d4f5f7
92a2b5e
7b892e0
44d9608
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,7 +18,7 @@ class SpeedSerializationAdapter : JsonAdapter<Speed>() { | |||||||||||||
is Speed.NoLimit -> writer.name("none").value(true) | ||||||||||||||
is Speed.Unknown -> writer.name("unknown").value(true) | ||||||||||||||
is Speed.Value -> | ||||||||||||||
writer.name("value").value(speed.value).name("unit").value(speed.unit.text) | ||||||||||||||
writer.name("speed").value(speed.value).name("unit").value(speed.unit.text) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahmedre I believe the actual key should be {
"speed": 56,
"unit": "km/h"
}, Let me know if there are additional cases. Definitely a bit of an obnoxious json object 😄. Also, do we want to try catch the annotations parsing? On iOS we just convert a json parsing error to nil/null for annotations and an onError callback so that developers can log the failure. We figured better to let navigation succeed even in the case of a degraded/malformed annotations. See ferrostar/apple/Sources/FerrostarCore/Annotations/AnnotationPublisher.swift Lines 70 to 75 in 61e299a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, you are right - my mistake! agree re: try/catching the parsing with an error callback 👍 |
||||||||||||||
} | ||||||||||||||
writer.endObject() | ||||||||||||||
} | ||||||||||||||
|
@@ -33,7 +33,7 @@ class SpeedSerializationAdapter : JsonAdapter<Speed>() { | |||||||||||||
var unit: String? = null | ||||||||||||||
|
||||||||||||||
while (reader.hasNext()) { | ||||||||||||||
when (reader.selectName(JsonReader.Options.of("none", "unknown", "value", "unit"))) { | ||||||||||||||
when (reader.selectName(JsonReader.Options.of("none", "unknown", "speed", "unit"))) { | ||||||||||||||
0 -> none = reader.nextBoolean() | ||||||||||||||
1 -> unknown = reader.nextBoolean() | ||||||||||||||
2 -> value = reader.nextDouble() | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package com.stadiamaps.ferrostar | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.stadiamaps.ferrostar.core.DefaultNavigationViewModel | ||
import com.stadiamaps.ferrostar.core.FerrostarCore | ||
import com.stadiamaps.ferrostar.core.LocationProvider | ||
import com.stadiamaps.ferrostar.core.LocationUpdateListener | ||
import com.stadiamaps.ferrostar.core.NavigationUiState | ||
import com.stadiamaps.ferrostar.core.NavigationViewModel | ||
import com.stadiamaps.ferrostar.core.annotation.AnnotationPublisher | ||
import com.stadiamaps.ferrostar.core.annotation.valhalla.valhallaExtendedOSRMAnnotationPublisher | ||
import com.stadiamaps.ferrostar.core.isNavigating | ||
import java.util.concurrent.Executors | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
|
@@ -24,7 +25,8 @@ import uniffi.ferrostar.UserLocation | |
class DemoNavigationViewModel( | ||
// This is a simple example, but these would typically be dependency injected | ||
private val ferrostarCore: FerrostarCore = AppModule.ferrostarCore, | ||
) : ViewModel(), LocationUpdateListener, NavigationViewModel { | ||
annotationPublisher: AnnotationPublisher<*> = valhallaExtendedOSRMAnnotationPublisher() | ||
) : DefaultNavigationViewModel(ferrostarCore, annotationPublisher), LocationUpdateListener { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ianthetechie now that this view model uses the |
||
private val locationStateFlow = MutableStateFlow<UserLocation?>(null) | ||
private val executor = Executors.newSingleThreadScheduledExecutor() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids users accidentally trying to do:
Which is very easy to do and highly problematic.