Skip to content

Commit

Permalink
RouteAlert refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
korshaknn committed Mar 16, 2021
1 parent 70377be commit adbe1e4
Show file tree
Hide file tree
Showing 84 changed files with 2,833 additions and 1,286 deletions.
411 changes: 268 additions & 143 deletions libnavigation-base/api/current.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.api.directions.v5.models.VoiceInstructions
import com.mapbox.geojson.Geometry
import com.mapbox.geojson.Point
import com.mapbox.navigation.base.trip.model.alert.UpcomingRouteAlert
import com.mapbox.navigation.base.trip.model.roadobject.UpcomingRoadObject

/**
* This class contains all progress information at any given time during a navigation session. This
Expand Down Expand Up @@ -37,7 +37,7 @@ import com.mapbox.navigation.base.trip.model.alert.UpcomingRouteAlert
* @param fractionTraveled [Float] fraction traveled along the current route. This value is
* between 0 and 1 and isn't guaranteed to reach 1 before the user reaches the end of the route.
* @param remainingWaypoints [Int] number of waypoints remaining on the current route.
* @param upcomingRouteAlerts list of upcoming route alerts.
* @param upcomingRoadObjects list of upcoming road objects.
*/
class RouteProgress private constructor(
val route: DirectionsRoute,
Expand All @@ -53,7 +53,7 @@ class RouteProgress private constructor(
val durationRemaining: Double,
val fractionTraveled: Float,
val remainingWaypoints: Int,
val upcomingRouteAlerts: List<UpcomingRouteAlert>
val upcomingRoadObjects: List<UpcomingRoadObject>
) {

/**
Expand All @@ -72,7 +72,7 @@ class RouteProgress private constructor(
.durationRemaining(durationRemaining)
.fractionTraveled(fractionTraveled)
.remainingWaypoints(remainingWaypoints)
.upcomingRouteAlerts(upcomingRouteAlerts)
.upcomingRoadObjects(upcomingRoadObjects)

/**
* Indicates whether some other object is "equal to" this one.
Expand All @@ -96,7 +96,7 @@ class RouteProgress private constructor(
if (durationRemaining != other.durationRemaining) return false
if (fractionTraveled != other.fractionTraveled) return false
if (remainingWaypoints != other.remainingWaypoints) return false
if (upcomingRouteAlerts != other.upcomingRouteAlerts) return false
if (upcomingRoadObjects != other.upcomingRoadObjects) return false

return true
}
Expand All @@ -118,7 +118,7 @@ class RouteProgress private constructor(
result = 31 * result + durationRemaining.hashCode()
result = 31 * result + fractionTraveled.hashCode()
result = 31 * result + remainingWaypoints
result = 31 * result + upcomingRouteAlerts.hashCode()
result = 31 * result + upcomingRoadObjects.hashCode()
return result
}

Expand All @@ -140,7 +140,7 @@ class RouteProgress private constructor(
"durationRemaining=$durationRemaining, " +
"fractionTraveled=$fractionTraveled, " +
"remainingWaypoints=$remainingWaypoints, " +
"upcomingRouteAlerts=$upcomingRouteAlerts" +
"upcomingRoadObjects=$upcomingRoadObjects" +
")"
}

Expand All @@ -162,7 +162,7 @@ class RouteProgress private constructor(
private var durationRemaining: Double = 0.0
private var fractionTraveled: Float = 0f
private var remainingWaypoints: Int = 0
private var upcomingRouteAlerts: List<UpcomingRouteAlert> = emptyList()
private var upcomingRoadObjects: List<UpcomingRoadObject> = emptyList()

/**
* Current [DirectionsRoute] geometry with a buffer
Expand Down Expand Up @@ -267,12 +267,12 @@ class RouteProgress private constructor(
apply { this.remainingWaypoints = remainingWaypoints }

/**
* List of upcoming route alerts with distances from current location to each of them.
* List of upcoming road objects with distances from current location to each of them.
*
* @return Builder
*/
fun upcomingRouteAlerts(upcomingRouteAlerts: List<UpcomingRouteAlert>): Builder =
apply { this.upcomingRouteAlerts = upcomingRouteAlerts }
fun upcomingRoadObjects(upcomingRoadObjects: List<UpcomingRoadObject>): Builder =
apply { this.upcomingRoadObjects = upcomingRoadObjects }

/**
* Build new instance of [RouteProgress]
Expand All @@ -295,7 +295,7 @@ class RouteProgress private constructor(
durationRemaining,
fractionTraveled,
remainingWaypoints,
upcomingRouteAlerts
upcomingRoadObjects
)
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.mapbox.navigation.base.trip.model.roadobject

/**
* Abstract class that serves as a base for all road objects.
*
* Available road object types are:
* - [TunnelEntrance]
* - [TunnelExit]
* - [CountryBorderCrossing]
* - [TollCollection]
* - [RestStop]
* - [RestrictedAreaEntrance]
* - [RestrictedAreaExit]
* - [BridgeEntrance]
* - [BridgeExit]
* - [Incident]
* - [Custom]
*
* @param objectType constant describing the object type, see [RoadObjectType].
* @param distanceFromStartOfRoute distance to this object since the start of the route.
* Will be null for road objects returned by Electronic Horizon.
* @param objectGeometry geometry details of the object.
*/
abstract class RoadObject(
val objectType: Int,
distanceFromStartOfRoute: Double?,
val objectGeometry: RoadObjectGeometry,
) {
/**
* Distance to this object since the start of the route.
* Will be null for road objects returned by Electronic Horizon.
*/
val distanceFromStartOfRoute: Double? = distanceFromStartOfRoute?.let {
if (it >= 0) it else null
}

/**
* Indicates whether some other object is "equal to" this one.
*/
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as RoadObject

if (objectType != other.objectType) return false
if (distanceFromStartOfRoute != other.distanceFromStartOfRoute) return false
if (objectGeometry != other.objectGeometry) return false

return true
}

/**
* Returns a hash code value for the object.
*/
override fun hashCode(): Int {
var result = objectType.hashCode()
result = 31 * result + distanceFromStartOfRoute.hashCode()
result = 31 * result + (objectGeometry.hashCode())
return result
}

/**
* Returns a string representation of the object.
*/
override fun toString(): String {
return "RoadObject(" +
"type=$objectType, " +
"distanceFromStartOfRoute=$distanceFromStartOfRoute, " +
"objectGeometry=$objectGeometry" +
")"
}
}
Loading

0 comments on commit adbe1e4

Please sign in to comment.