Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
korshaknn committed Sep 13, 2021
1 parent 9c33e88 commit 1900612
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import com.mapbox.navigator.FallbackVersionsObserver
import com.mapbox.navigator.IncidentsOptions
import com.mapbox.navigator.NavigatorConfig
import com.mapbox.navigator.PollingConfig
import com.mapbox.navigator.RouterInterface
import com.mapbox.navigator.TileEndpointConfiguration
import com.mapbox.navigator.TilesConfig
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -1103,8 +1104,8 @@ class MapboxNavigation(
accessToken ?: throw RuntimeException(MAPBOX_NAVIGATION_TOKEN_EXCEPTION_ROUTER)
),
ModuleProviderArgument(
MapboxNativeNavigator::class.java,
MapboxNativeNavigatorImpl
RouterInterface::class.java,
MapboxNativeNavigatorImpl.router
)
)
MapboxModuleType.NavigationTripNotification -> arrayOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.mapbox.navigation.base.route.RouterOrigin.Offboard
import com.mapbox.navigation.base.route.RouterOrigin.Onboard
import com.mapbox.navigator.RouterOrigin

internal fun RouterOrigin.mapToSDKRouteOrigin(): com.mapbox.navigation.base.route.RouterOrigin {
internal fun RouterOrigin.mapToSdkRouteOrigin(): com.mapbox.navigation.base.route.RouterOrigin {
return when (this) {
RouterOrigin.ONLINE -> Offboard
RouterOrigin.ONBOARD -> Onboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package com.mapbox.navigation.route.internal

import android.util.Log
import com.mapbox.annotation.module.MapboxModule
import com.mapbox.annotation.module.MapboxModuleType
import com.mapbox.api.directions.v5.MapboxDirections
Expand All @@ -18,13 +17,12 @@ import com.mapbox.navigation.base.route.RouteRefreshError
import com.mapbox.navigation.base.route.Router
import com.mapbox.navigation.base.route.RouterCallback
import com.mapbox.navigation.base.route.RouterFailure
import com.mapbox.navigation.navigator.internal.MapboxNativeNavigator
import com.mapbox.navigation.route.internal.util.ACCESS_TOKEN_QUERY_PARAM
import com.mapbox.navigation.route.internal.util.httpUrl
import com.mapbox.navigation.route.internal.util.redactQueryParam
import com.mapbox.navigation.route.onboard.OfflineRoute
import com.mapbox.navigation.utils.internal.LoggerProvider
import com.mapbox.navigation.utils.internal.ThreadController
import com.mapbox.navigation.utils.internal.logW
import com.mapbox.navigator.RouteRefreshOptions
import com.mapbox.navigator.RouterInterface
import com.mapbox.navigator.RoutingProfile
Expand All @@ -36,10 +34,9 @@ import java.net.URL
@MapboxModule(MapboxModuleType.NavigationRouter)
class RouterWrapper(
private val accessToken: String,
navigatorNative: MapboxNativeNavigator,
private val router: RouterInterface,
) : Router {

private val router: RouterInterface = navigatorNative.router
private val mainJobControl by lazy { ThreadController.getMainScopeAndRootJob() }

override fun getRoute(routeOptions: RouteOptions, callback: RouterCallback): Long {
Expand All @@ -57,32 +54,24 @@ class RouterWrapper(
mainJobControl.scope.launch {
if (result.isValue) {
val routes = parseDirectionsResponse(result.value!!, routeOptions)

Log.d("nav-native", "get route SUCCESS")
routes.forEach {
Log.d("nav-native", "uuid = ${it.requestUuid()}")
}

if (routes.isNullOrEmpty()) {
callback.onFailure(
listOf(
RouterFailure(
urlWithoutToken,
origin.mapToSDKRouteOrigin(),
origin.mapToSdkRouteOrigin(),
ROUTES_LIST_EMPTY
)
),
routeOptions
)
} else {
callback.onRoutesReady(routes, origin.mapToSDKRouteOrigin())
callback.onRoutesReady(routes, origin.mapToSdkRouteOrigin())
}
} else {
Log.d("nav-native", "get route FAILURE ${result.error}")

result.error!!.run {
if (error == REQUEST_CANCELLED) {
LoggerProvider.logger.w(
logW(
TAG,
Message(
"""
Expand All @@ -92,18 +81,18 @@ class RouterWrapper(
""".trimIndent()
)
)
callback.onCanceled(routeOptions, origin.mapToSDKRouteOrigin())
callback.onCanceled(routeOptions, origin.mapToSdkRouteOrigin())
} else {
val failureReasons = listOf(
RouterFailure(
url = urlWithoutToken,
routerOrigin = origin.mapToSDKRouteOrigin(),
routerOrigin = origin.mapToSdkRouteOrigin(),
message = error,
code = code
)
)

LoggerProvider.logger.w(
logW(
TAG,
Message(
"""
Expand Down Expand Up @@ -138,8 +127,6 @@ class RouterWrapper(
return router.getRouteRefresh(refreshOptions, route.toJson()) { result, _ ->
mainJobControl.scope.launch {
if (result.isValue) {
Log.d("nav-native", "get route refresh SUCCESS")

val refreshedRoute =
withContext(ThreadController.IODispatcher) {
DirectionsRoute.fromJson(
Expand All @@ -150,8 +137,6 @@ class RouterWrapper(
}
callback.onRefresh(refreshedRoute)
} else {
Log.d("nav-native", "get route refresh FAILURE ${result.error}")

result.error!!.run {
val errorMessage =
"""
Expand All @@ -162,7 +147,7 @@ class RouterWrapper(
requestId = $requestId
""".trimIndent()

LoggerProvider.logger.w(TAG, Message(errorMessage))
logW(TAG, Message(errorMessage))

callback.onError(
RouteRefreshError("Route refresh failed", Exception(errorMessage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class RouterWrapperTests {

routerWrapper = RouterWrapper(
accessToken,
mapboxNativeNavigator
mapboxNativeNavigator.router
)
}

Expand Down

0 comments on commit 1900612

Please sign in to comment.