Skip to content

Commit eede11d

Browse files
committed
Use route repository
1 parent 730543e commit eede11d

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

app/src/main/java/org/nitri/opentopo/MapFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ class MapFragment : Fragment(), LocationListener, PopupMenu.OnMenuItemClickListe
894894

895895
override fun onLocationChanged(location: Location) {
896896

897-
if (BuildConfig.DEBUG)
898-
Log.d(TAG, "Location: ${location.latitude}, ${location.longitude}, mapRotation: $mapRotation")
897+
//if (BuildConfig.DEBUG)
898+
// Log.d(TAG, "Location: ${location.latitude}, ${location.longitude}, mapRotation: $mapRotation")
899899

900900
requireActivity().runOnUiThread {
901901
locationViewModel?.currentLocation?.postValue(location)

app/src/main/java/org/nitri/opentopo/ors/Directions.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import kotlinx.coroutines.withContext
77
import okhttp3.ResponseBody
88
import org.nitri.ors.api.OpenRouteServiceApi
99
import org.nitri.ors.model.route.RouteRequest
10+
import org.nitri.ors.repository.RouteRepository
1011
import retrofit2.Response
1112

1213
class Directions(val api: OpenRouteServiceApi, private val profile: String) {
1314

15+
val repository = RouteRepository(api)
16+
1417
fun getRouteGpx(coordinates: List<List<Double>>, language: String, result: RouteGpResult) {
1518
CoroutineScope(Dispatchers.IO).launch {
16-
val request = RouteRequest(coordinates = coordinates, language = language)
1719
try {
18-
val response : Response<ResponseBody> = api.getRouteGpx(profile, request)
20+
val response : Response<ResponseBody> = repository.getRouteGpx(coordinates, language, profile)
1921
withContext(Dispatchers.Main) {
2022
val gpxXml = response.body()?.string() ?: ""
2123
if (gpxXml.isNotBlank()) {

ors-client/src/androidTest/java/org/nitri/ors/RouteRepositoryGpxInstrumentedTest.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.junit.Test
1010
import org.junit.runner.RunWith
1111
import org.nitri.ors.client.OpenRouteServiceClient
1212
import org.nitri.ors.model.route.RouteRequest
13+
import org.nitri.ors.repository.RouteRepository
1314
import retrofit2.Response
1415

1516
@RunWith(AndroidJUnit4::class)
@@ -19,16 +20,13 @@ class RouteRepositoryGpxInstrumentedTest {
1920
fun testFetchGpxRoute_successful() = runBlocking {
2021
val context = ApplicationProvider.getApplicationContext<Context>()
2122
val apiKey = context.getString(R.string.ors_api_key)
22-
val api = OpenRouteServiceClient.create(apiKey, context)
23+
val client = OpenRouteServiceClient.create(apiKey, context)
24+
val repository = RouteRepository(client)
2325

24-
val request = RouteRequest(
25-
coordinates = listOf(
26-
listOf(8.681495, 49.41461),
27-
listOf(8.687872, 49.420318)
28-
)
29-
)
26+
val start = Pair(8.681495, 49.41461)
27+
val end = Pair(8.687872, 49.420318)
3028

31-
val response: Response<ResponseBody> = api.getRouteGpx("driving-car", request)
29+
val response: Response<ResponseBody> = repository.getRouteGpx(start, end,"driving-car")
3230

3331
val gpxXml = response.body()?.string()
3432

ors-client/src/main/java/org/nitri/ors/repository/RouteRepository.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.nitri.ors.repository
22

3+
import okhttp3.ResponseBody
34
import org.nitri.ors.api.OpenRouteServiceApi
5+
import org.nitri.ors.model.route.GeoJsonRouteResponse
46
import org.nitri.ors.model.route.RouteRequest
57
import org.nitri.ors.model.route.RouteResponse
8+
import retrofit2.Response
69

710
class RouteRepository(private val api: OpenRouteServiceApi) {
811
suspend fun getRoute(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): RouteResponse {
@@ -12,4 +15,25 @@ class RouteRepository(private val api: OpenRouteServiceApi) {
1215
))
1316
return api.getRoute(profile, request)
1417
}
18+
19+
suspend fun getRouteGpx(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): Response<ResponseBody> {
20+
val request = RouteRequest(coordinates = listOf(
21+
listOf(start.first, start.second),
22+
listOf(end.first, end.second)
23+
))
24+
return api.getRouteGpx(profile, request)
25+
}
26+
27+
suspend fun getRouteGpx(coordinates: List<List<Double>>, language: String, profile: String): Response<ResponseBody> {
28+
val request = RouteRequest(coordinates = coordinates, language = language)
29+
return api.getRouteGpx(profile, request)
30+
}
31+
32+
suspend fun getRouteGeoJson(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): GeoJsonRouteResponse {
33+
val request = RouteRequest(coordinates = listOf(
34+
listOf(start.first, start.second),
35+
listOf(end.first, end.second)
36+
))
37+
return api.getRouteGeoJson(profile, request)
38+
}
1539
}

0 commit comments

Comments
 (0)