-
Notifications
You must be signed in to change notification settings - Fork 320
NAVAND-714 - Added Waypoints to NavigationRoute; - RouteOptionsUpdater refactored; #6005
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mapbox.navigation.base.internal.extensions | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsRoute | ||
import com.mapbox.api.directions.v5.models.RouteOptions | ||
import com.mapbox.navigation.base.internal.route.Waypoint | ||
import com.mapbox.navigation.base.trip.model.RouteProgress | ||
|
||
/** | ||
* Return true if the waypoint is requested explicitly. False otherwise. | ||
*/ | ||
fun Waypoint.isRequestedWaypoint(): Boolean = | ||
when (this.internalType) { | ||
Waypoint.InternalType.Regular, | ||
Waypoint.InternalType.Silent -> true | ||
Waypoint.InternalType.EvCharging -> false | ||
} | ||
|
||
/** | ||
* Return true if the waypoint is tracked in [RouteProgress.currentLegProgress]#legIndex, based on | ||
* [DirectionsRoute.legs] index. False otherwise. | ||
*/ | ||
fun Waypoint.isLegWaypoint(): Boolean = | ||
when (this.internalType) { | ||
Waypoint.InternalType.Regular, | ||
Waypoint.InternalType.EvCharging -> true | ||
Waypoint.InternalType.Silent -> false | ||
} | ||
|
||
/** | ||
* Return the index of **next requested** coordinate. See [RouteOptions.coordinatesList] | ||
* | ||
* For instance, EV waypoints are not requested explicitly, so they are not taken into account. | ||
*/ | ||
fun indexOfNextRequestedCoordinate( | ||
waypoints: List<Waypoint>, | ||
remainingWaypoints: Int, | ||
): Int? { | ||
if (remainingWaypoints > waypoints.size) { | ||
return null | ||
} | ||
val nextWaypointIndex = waypoints.size - remainingWaypoints | ||
var requestedIndex = 0 | ||
waypoints.forEachIndexed { index, waypoint -> | ||
if (waypoint.isRequestedWaypoint()) { | ||
if (index >= nextWaypointIndex) { | ||
return requestedIndex | ||
} | ||
requestedIndex++ | ||
} | ||
} | ||
return null | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
package com.mapbox.navigation.base.internal.route | ||||||
|
||||||
import androidx.annotation.IntDef | ||||||
import com.mapbox.geojson.Point | ||||||
|
||||||
class Waypoint internal constructor( | ||||||
val location: Point, | ||||||
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.
Suggested change
This would be handy instead of copying the location/name data. It could be 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. do you mean fakeing 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. We don't need be faking them, we can be finding them in the route response object depending on the index. 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. We don't always have 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. Okay, let's revisit later if needed. |
||||||
val name: String, | ||||||
val target: Point?, | ||||||
internal val internalType: InternalType | ||||||
) { | ||||||
|
||||||
@Type | ||||||
val type: Int = when (internalType) { | ||||||
InternalType.Regular -> REGULAR | ||||||
InternalType.Silent -> SILENT | ||||||
InternalType.EvCharging -> EV_CHARGING | ||||||
} | ||||||
|
||||||
companion object { | ||||||
const val REGULAR = 1 | ||||||
const val SILENT = 2 | ||||||
const val EV_CHARGING = 3 | ||||||
} | ||||||
|
||||||
@Target( | ||||||
AnnotationTarget.PROPERTY, | ||||||
AnnotationTarget.VALUE_PARAMETER, | ||||||
AnnotationTarget.FUNCTION, | ||||||
AnnotationTarget.TYPE | ||||||
) | ||||||
@Retention(AnnotationRetention.BINARY) | ||||||
@IntDef(REGULAR, SILENT, EV_CHARGING) | ||||||
annotation class Type | ||||||
|
||||||
override fun equals(other: Any?): Boolean { | ||||||
if (this === other) return true | ||||||
if (javaClass != other?.javaClass) return false | ||||||
|
||||||
other as Waypoint | ||||||
|
||||||
if (location != other.location) return false | ||||||
if (type != other.type) return false | ||||||
if (name != other.name) return false | ||||||
if (target != other.target) return false | ||||||
|
||||||
return true | ||||||
} | ||||||
|
||||||
override fun hashCode(): Int { | ||||||
var result = location.hashCode() | ||||||
result = 31 * result + type | ||||||
result = 31 * result + name.hashCode() | ||||||
result = 31 * result + target.hashCode() | ||||||
return result | ||||||
} | ||||||
|
||||||
override fun toString(): String { | ||||||
return "Waypoint(location=$location, type=$type, name='$name', target=$target)" | ||||||
} | ||||||
|
||||||
internal enum class InternalType { | ||||||
Regular, | ||||||
Silent, | ||||||
EvCharging, | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mapbox.navigation.base.internal.utils | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import com.mapbox.geojson.Point | ||
import com.mapbox.navigation.base.internal.route.Waypoint | ||
import org.jetbrains.annotations.TestOnly | ||
|
||
@VisibleForTesting | ||
object WaypointFactory { | ||
@TestOnly | ||
fun provideWaypoint( | ||
location: Point, | ||
name: String, | ||
target: Point?, | ||
@Waypoint.Type type: Int, | ||
): Waypoint = Waypoint( | ||
location, | ||
name, | ||
target, | ||
when (type) { | ||
Waypoint.REGULAR -> Waypoint.InternalType.Regular | ||
Waypoint.SILENT -> Waypoint.InternalType.Silent | ||
Waypoint.EV_CHARGING -> Waypoint.InternalType.EvCharging | ||
else -> throw IllegalStateException("Unknown waypoint type $type") | ||
}, | ||
) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.