This commit is contained in:
Piotr Dec 2023-08-16 02:44:36 +02:00
parent 49559993d8
commit 0a00d13706
6 changed files with 328 additions and 15 deletions

View file

@ -0,0 +1,66 @@
package eu.ztsh.garmin
import com.mapbox.navigation.ui.maneuver.model.Maneuver
class ManeuverMapper {
companion object {
fun apply(maneuver: Maneuver): State {
val state = State()
maneuver.apply {
this.primary.apply {
state.direction = Direction()
when (this.type) {
"turn" -> {
state.direction.outType = OutType.Lane
state.direction.roundabout = OutAngle.AsDirection
}
"roundabout" -> {
state.direction.outType = OutType.RightRoundabout
}
"arrive" -> {
state.flag = true
}
}
when (this.modifier) {
"right" -> {
when (this.type) {
"turn" -> state.direction.outAngle = OutAngle.Right
"roundabout" -> {
when (this.degrees) {
137.0 -> state.direction.outAngle = OutAngle.EasyRight
}
}
}
}
"left" -> {
when (this.type) {
"turn" -> state.direction.outAngle = OutAngle.Left
}
}
}
}
this.stepDistance.apply {
this.distanceRemaining?.apply {
distanceFormatter.formatDistance(distanceRemaining!!).split(" ").apply {
state.distance = this[0].toInt()
state.unit = when (this[1]) {
"m" -> Unit.Metres
"km" -> Unit.Kilometres
else -> {Unit.Any}
}
}
}
}
}
return state
}
}
}