-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
148 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/GetRegionRoutingService.kt
This file was deleted.
Oops, something went wrong.
10 changes: 9 additions & 1 deletion
10
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GetRegionRouteResponse> | ||
fun getRegionRoutes(@Body request: GetRegionRouteRequest): Single<List<RegionRoute>> | ||
|
||
@POST("info/routeInfo.json") | ||
fun getRegionRouteInfo(@Body request: GetRouteDetailsRequest): Single<RouteDetails> | ||
} |
89 changes: 89 additions & 0 deletions
89
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/RegionRoutingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> = emptyList(), | ||
operatorId: String? = null | ||
): Single<List<RegionRoute>> | ||
|
||
fun getRoutes( | ||
query: String, | ||
location: Location? | ||
): Observable<List<RegionRoute>> | ||
|
||
fun getRoutes( | ||
regionName: String, | ||
query: String | ||
): Single<List<RegionRoute>> | ||
|
||
fun getRegionRouteInfo( | ||
region: String, | ||
operatorId: String, | ||
routeID: Int | ||
): Single<RouteDetails> | ||
|
||
class RegionRoutingRepositoryImpl( | ||
private val regionRoutingApi: RegionRoutingApi, | ||
private val regionService: RegionService | ||
) : RegionRoutingRepository { | ||
override fun getRegionRoutes( | ||
region: String, | ||
query: String?, | ||
modes: List<String>, | ||
operatorId: String? | ||
): Single<List<RegionRoute>> { | ||
return regionRoutingApi.getRegionRoutes( | ||
GetRegionRouteRequest( | ||
region = region, | ||
query = query, | ||
modes = modes, | ||
operatorId = operatorId | ||
) | ||
) | ||
} | ||
|
||
override fun getRoutes(regionName: String, query: String): Single<List<RegionRoute>> { | ||
val request = GetRegionRouteRequest( | ||
region = regionName, | ||
query = query | ||
) | ||
return regionRoutingApi.getRegionRoutes(request) | ||
} | ||
|
||
override fun getRoutes(query: String, location: Location?): Observable<List<RegionRoute>> { | ||
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<RouteDetails> { | ||
val request = | ||
GetRouteDetailsRequest(region, operatorId, routeID) | ||
|
||
return regionRoutingApi.getRegionRouteInfo(request) | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Direction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Stop> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/GetRouteDetailsRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.skedgo.tripkit.regionrouting.data | ||
|
||
data class GetRouteDetailsRequest( | ||
val operatorID: String, | ||
val region: String, | ||
val routeID: Int | ||
) |
4 changes: 2 additions & 2 deletions
4
...t/regionrouting/GetRegionRouteResponse.kt → ...tripkit/regionrouting/data/RegionRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/RouteDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Direction>, | ||
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 | ||
) |
9 changes: 9 additions & 0 deletions
9
TripKitAndroid/src/main/java/com/skedgo/tripkit/regionrouting/data/Stop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |