diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/HttpClientModule.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/HttpClientModule.kt index fd000a52..2d5f94ab 100644 --- a/TripKitAndroid/src/main/java/com/skedgo/tripkit/HttpClientModule.kt +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/HttpClientModule.kt @@ -9,7 +9,8 @@ import com.skedgo.tripkit.configuration.AppVersionNameRepository import com.skedgo.tripkit.configuration.GetAppVersion import com.skedgo.tripkit.configuration.Server import com.skedgo.tripkit.data.HttpClientCustomDataStore -import com.skedgo.tripkit.regionrouting.GetRegionRoutingService +import com.skedgo.tripkit.data.regions.RegionService +import com.skedgo.tripkit.regionrouting.RegionRoutingRepository import com.skedgo.tripkit.regionrouting.RegionRoutingApi import dagger.Lazy import dagger.Module @@ -139,8 +140,8 @@ open class HttpClientModule( @Singleton @Provides - open fun getRegionRoutingService(api: RegionRoutingApi): GetRegionRoutingService { - return GetRegionRoutingService.GetRegionRoutingServiceImpl(api) + open fun getRegionRoutingService(api: RegionRoutingApi, regionService: RegionService): RegionRoutingRepository { + return RegionRoutingRepository.RegionRoutingRepositoryImpl(api, regionService) } } diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRoutingService.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRoutingService.kt deleted file mode 100644 index fd3c8ee5..00000000 --- a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRoutingService.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.skedgo.tripkit.regionrouting - -import io.reactivex.Single - -interface GetRegionRoutingService { - - fun getRegionRoutes( - region: String, - query: String? = null, - modes: List = emptyList(), - operatorId: String? = null - ): Single - - class GetRegionRoutingServiceImpl(private val regionRoutingApi: RegionRoutingApi) : GetRegionRoutingService { - override fun getRegionRoutes( - region: String, - query: String?, - modes: List, - operatorId: String? - ): Single { - return regionRoutingApi.getRegionRoutes( - GetRegionRouteRequest( - region = region, - query = query, - modes = modes, - operatorId = operatorId - ) - ) - } - } - -} \ No newline at end of file diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingApi.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingApi.kt index 7b0b476d..2c09e55c 100644 --- a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingApi.kt +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingApi.kt @@ -1,9 +1,17 @@ package com.skedgo.tripkit.regionrouting +import com.skedgo.tripkit.regionrouting.data.GetRegionRouteRequest +import com.skedgo.tripkit.regionrouting.data.GetRouteDetailsRequest +import com.skedgo.tripkit.regionrouting.data.RegionRoute +import com.skedgo.tripkit.regionrouting.data.RouteDetails import io.reactivex.Single +import retrofit2.http.Body import retrofit2.http.POST interface RegionRoutingApi { @POST("info/routes.json") - fun getRegionRoutes(request: GetRegionRouteRequest): Single + fun getRegionRoutes(@Body request: GetRegionRouteRequest): Single> + + @POST("info/routeInfo.json") + fun getRegionRouteInfo(@Body request: GetRouteDetailsRequest): Single } \ No newline at end of file diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingRepository.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingRepository.kt new file mode 100644 index 00000000..365c1992 --- /dev/null +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingRepository.kt @@ -0,0 +1,89 @@ +package com.skedgo.tripkit.regionrouting + +import com.skedgo.tripkit.common.model.Location +import com.skedgo.tripkit.data.regions.RegionService +import com.skedgo.tripkit.regionrouting.data.GetRegionRouteRequest +import com.skedgo.tripkit.regionrouting.data.GetRouteDetailsRequest +import com.skedgo.tripkit.regionrouting.data.RegionRoute +import com.skedgo.tripkit.regionrouting.data.RouteDetails +import io.reactivex.Observable +import io.reactivex.Single + +interface RegionRoutingRepository { + + fun getRegionRoutes( + region: String, + query: String? = null, + modes: List = emptyList(), + operatorId: String? = null + ): Single> + + fun getRoutes( + query: String, + location: Location? + ): Observable> + + fun getRoutes( + regionName: String, + query: String + ): Single> + + fun getRegionRouteInfo( + region: String, + operatorId: String, + routeID: Int + ): Single + + class RegionRoutingRepositoryImpl( + private val regionRoutingApi: RegionRoutingApi, + private val regionService: RegionService + ) : RegionRoutingRepository { + override fun getRegionRoutes( + region: String, + query: String?, + modes: List, + operatorId: String? + ): Single> { + return regionRoutingApi.getRegionRoutes( + GetRegionRouteRequest( + region = region, + query = query, + modes = modes, + operatorId = operatorId + ) + ) + } + + override fun getRoutes(regionName: String, query: String): Single> { + val request = GetRegionRouteRequest( + region = regionName, + query = query + ) + return regionRoutingApi.getRegionRoutes(request) + } + + override fun getRoutes(query: String, location: Location?): Observable> { + return ( + if (location != null) { + regionService.getRegionByLocationAsync(location) + } else { + regionService.getRegionsAsync().map { it.first() } + } + ).flatMapSingle { region -> + val request = GetRegionRouteRequest( + region = region.name ?: "", + query = query + ) + regionRoutingApi.getRegionRoutes(request) + } + } + + override fun getRegionRouteInfo(region: String, operatorId: String, routeID: Int): Single { + val request = + GetRouteDetailsRequest(region, operatorId, routeID) + + return regionRoutingApi.getRegionRouteInfo(request) + } + } + +} \ No newline at end of file diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Direction.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Direction.kt new file mode 100644 index 00000000..f92d393f --- /dev/null +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Direction.kt @@ -0,0 +1,9 @@ +package com.skedgo.tripkit.regionrouting.data + +data class Direction( + val encodedShape: String, + val id: String, + val name: String, + val shapeIsDetailed: Boolean, + val stops: List +) \ No newline at end of file diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRouteRequest.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRegionRouteRequest.kt similarity index 83% rename from TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRouteRequest.kt rename to TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRegionRouteRequest.kt index 9d35e6b9..2235a492 100644 --- a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRouteRequest.kt +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRegionRouteRequest.kt @@ -1,4 +1,4 @@ -package com.skedgo.tripkit.regionrouting +package com.skedgo.tripkit.regionrouting.data import com.google.gson.annotations.SerializedName @@ -7,7 +7,7 @@ data class GetRegionRouteRequest( val query: String? = null, @SerializedName("operatorID") val operatorId: String? = null, - val modes: List = emptyList(), + val modes: List? = null, @SerializedName("routesIDs") val routesIds: List = emptyList(), val routesNames: List = emptyList(), diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRouteDetailsRequest.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRouteDetailsRequest.kt new file mode 100644 index 00000000..929a91ef --- /dev/null +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRouteDetailsRequest.kt @@ -0,0 +1,7 @@ +package com.skedgo.tripkit.regionrouting.data + +data class GetRouteDetailsRequest( + val operatorID: String, + val region: String, + val routeID: Int +) \ No newline at end of file diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRouteResponse.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RegionRoute.kt similarity index 87% rename from TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRouteResponse.kt rename to TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RegionRoute.kt index 44419d31..75237a6c 100644 --- a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRouteResponse.kt +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RegionRoute.kt @@ -1,9 +1,9 @@ -package com.skedgo.tripkit.regionrouting +package com.skedgo.tripkit.regionrouting.data import com.skedgo.tripkit.routing.ModeInfo import com.skedgo.tripkit.routing.ServiceColor -data class GetRegionRouteResponse( +data class RegionRoute( val id: String, val operatorID: String, val shortName: String, diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RouteDetails.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RouteDetails.kt new file mode 100644 index 00000000..760e7587 --- /dev/null +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RouteDetails.kt @@ -0,0 +1,17 @@ +package com.skedgo.tripkit.regionrouting.data + +import com.skedgo.tripkit.routing.ModeInfo +import com.skedgo.tripkit.routing.ServiceColor + +data class RouteDetails( + val directions: List, + val id: String, + val mode: String, + val modeInfo: ModeInfo, + val operatorId: String, + val operatorName: String, + val region: String, + val routeColor: ServiceColor, + val routeName: String, + val shortName: String +) \ No newline at end of file diff --git a/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Stop.kt b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Stop.kt new file mode 100644 index 00000000..e7b2be24 --- /dev/null +++ b/TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Stop.kt @@ -0,0 +1,9 @@ +package com.skedgo.tripkit.regionrouting.data + +data class Stop( + val common: Boolean, + val lat: Int, + val lng: Int, + val name: String, + val stopCode: String +) \ No newline at end of file