-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add junction views marshaling support. #425
Changes from all commits
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 |
---|---|---|
|
@@ -35,7 +35,12 @@ public extension VisualInstruction { | |
case image(image: ImageRepresentation, alternativeText: TextRepresentation) | ||
|
||
/** | ||
The compoment contains the localized word for “Exit”. | ||
The component is an image of a zoomed junction, with a fallback text representation. | ||
*/ | ||
case guidanceView(image: GuidanceViewImageRepresentation, alternativeText: TextRepresentation) | ||
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. Add documentation about this case; otherwise it won’t show up in documentation. |
||
|
||
/** | ||
The component contains the localized word for “Exit”. | ||
|
||
This component may appear before or after an `.exitCode` component, depending on the language. You can hide this component if the adjacent `.exitCode` component has an obvious exit-number appearance, for example with an accompanying [motorway exit icon](https://commons.wikimedia.org/wiki/File:Sinnbild_Autobahnausfahrt.svg). | ||
*/ | ||
|
@@ -149,13 +154,30 @@ public extension VisualInstruction.Component { | |
} | ||
} | ||
|
||
/// A guidance view image representation of a visual instruction component. | ||
public struct GuidanceViewImageRepresentation: Equatable { | ||
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. ImageRepresentation isn’t meant to be limited to the /ref #405 (comment) 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.
|
||
/** | ||
Initializes an image representation bearing the image at the given URL. | ||
*/ | ||
public init(imageURL: URL?) { | ||
self.imageURL = imageURL | ||
} | ||
|
||
/** | ||
Returns a remote URL to the image file that represents the component. | ||
*/ | ||
public let imageURL: URL? | ||
|
||
} | ||
|
||
extension VisualInstruction.Component: Codable { | ||
private enum CodingKeys: String, CodingKey { | ||
case kind = "type" | ||
case text | ||
case abbreviatedText = "abbr" | ||
case abbreviatedTextPriority = "abbr_priority" | ||
case imageBaseURL | ||
case imageURL = "url" | ||
case directions | ||
case isActive = "active" | ||
} | ||
|
@@ -164,6 +186,7 @@ extension VisualInstruction.Component: Codable { | |
case delimiter | ||
case text | ||
case image = "icon" | ||
case guidanceView = "guidance-view" | ||
case exit | ||
case exitCode = "exit-number" | ||
case lane | ||
|
@@ -203,6 +226,13 @@ extension VisualInstruction.Component: Codable { | |
self = .exitCode(text: textRepresentation) | ||
case .lane: | ||
preconditionFailure("Lane component should have been initialized before decoding text") | ||
case .guidanceView: | ||
var imageURL: URL? | ||
if let imageURLString = try container.decodeIfPresent(String.self, forKey: .imageURL) { | ||
imageURL = URL(string: imageURLString) | ||
} | ||
let guidanceViewImageRepresentation = GuidanceViewImageRepresentation(imageURL: imageURL) | ||
self = .guidanceView(image: guidanceViewImageRepresentation, alternativeText: textRepresentation) | ||
} | ||
} | ||
|
||
|
@@ -232,6 +262,10 @@ extension VisualInstruction.Component: Codable { | |
textRepresentation = .init(text: "", abbreviation: nil, abbreviationPriority: nil) | ||
try container.encode(indications, forKey: .directions) | ||
try container.encode(isUsable, forKey: .isActive) | ||
case .guidanceView(let image, let alternativeText): | ||
try container.encode(Kind.guidanceView, forKey: .kind) | ||
textRepresentation = alternativeText | ||
try container.encodeIfPresent(image.imageURL?.absoluteString, forKey: .imageURL) | ||
} | ||
|
||
if let textRepresentation = textRepresentation { | ||
|
@@ -254,6 +288,10 @@ extension VisualInstruction.Component: Equatable { | |
let .image(rhsURL, rhsAlternativeText)): | ||
return lhsURL == rhsURL | ||
&& lhsAlternativeText == rhsAlternativeText | ||
case (let .guidanceView(lhsURL, lhsAlternativeText), | ||
let .guidanceView(rhsURL, rhsAlternativeText)): | ||
return lhsURL == rhsURL | ||
&& lhsAlternativeText == rhsAlternativeText | ||
case (let .lane(lhsIndications, lhsIsUsable), | ||
let .lane(rhsIndications, rhsIsUsable)): | ||
return lhsIndications == rhsIndications | ||
|
@@ -263,6 +301,7 @@ extension VisualInstruction.Component: Equatable { | |
(.image, _), | ||
(.exit, _), | ||
(.exitCode, _), | ||
(.guidanceView, _), | ||
(.lane, _): | ||
return false | ||
} | ||
|
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.
Thanks for fixing this typo. 😄