-
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?
Conversation
…id/view-builder-and-speed-json
…, and demo app update.
…, and demo app update.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
@ahmedre I believe the actual key should be "speed"
when there's a value. E.g.
{
"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
do { | |
return try decoder.decode(Annotation.self, from: data) | |
} catch { | |
onError(error) | |
return nil | |
} |
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.
yes, you are right - my mistake! agree re: try/catching the parsing with an error callback 👍
@@ -19,14 +19,16 @@ import com.stadiamaps.ferrostar.composeui.views.components.TripProgressView | |||
import com.stadiamaps.ferrostar.core.NavigationUiState | |||
|
|||
data class NavigationViewComponentBuilder( | |||
val instructionsView: @Composable (modifier: Modifier, uiState: NavigationUiState) -> Unit, | |||
val progressView: | |||
internal val instructionsView: |
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:
NavigationViewComponentBuilder.Default()
.instructionsView { }
Which is very easy to do and highly problematic.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
@ianthetechie now that this view model uses the DefaultNavigationViewModel
. We should be able to refactor it to use the existing uiState from ferrostar and implement its own additional state for things like route loading, etc. Just to highlight how easy it is to customize without interrupting the default navigation behavior.
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.
Looks good to me but I'll wait for @ahmedre to comment since he may have an opinion based on what they're building 👍
On the We can swap If we want to go this route, should we consider making |
DefaultNavigationViewModel
SpeedUnit