Skip to content

Commit a8c2f2b

Browse files
committed
chore: add location accurancy to app objects
1 parent ef51a06 commit a8c2f2b

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

library/src/main/java/cloud/pace/sdk/appkit/AppManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal class AppManager(private val dispatchers: DispatcherProvider = DefaultD
5959

6060
Timber.i("Check local available apps at $userLocation")
6161

62-
when (val apps = appRepository.getLocationBasedApps(userLocation.latitude, userLocation.longitude)) {
62+
when (val apps = appRepository.getLocationBasedApps(userLocation.latitude, userLocation.longitude, userLocation.accuracy.toDouble())) {
6363
is Success -> {
6464
val result = apps.result
6565
Timber.d("Received ${result.size} apps: ${result.map { it.url }}")

library/src/main/java/cloud/pace/sdk/appkit/app/api/AppRepository.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import timber.log.Timber
2626

2727
interface AppRepository {
2828

29-
suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>>
29+
suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double? = null): Completion<List<App>>
3030
suspend fun getAppsByUrl(url: String, references: List<String>): Completion<List<App>>
3131
suspend fun getUrlByAppId(appId: String): Completion<String?>
3232
fun getFuelingUrl(poiId: String, completion: (String) -> Unit)
@@ -40,7 +40,7 @@ class AppRepositoryImpl(
4040
private val manifestClient: ManifestClient
4141
) : AppRepository {
4242

43-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
43+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
4444
val apps = geoApiManager.apps(latitude, longitude).getOrElse {
4545
return Failure(it)
4646
}
@@ -51,7 +51,7 @@ class AppRepositoryImpl(
5151

5252
apps
5353
.map {
54-
async { it.toLocationBasedApps(userLocation) }
54+
async { it.toLocationBasedApps(userLocation, locationAccuracy) }
5555
}
5656
.flatMap {
5757
runCatching { it.await() }.getOrNull() ?: emptyList()
@@ -113,16 +113,16 @@ class AppRepositoryImpl(
113113
}
114114
}
115115

116-
private suspend fun GeoGasStation.toLocationBasedApps(userLocation: LatLng): List<App> {
116+
private suspend fun GeoGasStation.toLocationBasedApps(userLocation: LatLng, locationAccuracy: Double? = null): List<App> {
117117
val references = listOf(id)
118118
val distance = coordinate?.let { userLocation.distanceTo(it).toInt() }
119119

120120
return appUrls[FUELING_TYPE]?.map {
121-
createLocationBasedApps(it, references, distance)
121+
createLocationBasedApps(it, references, distance, locationAccuracy)
122122
}?.flatten() ?: emptyList()
123123
}
124124

125-
private suspend fun createLocationBasedApps(appUrl: String?, references: List<String>?, distance: Int? = null): List<App> {
125+
private suspend fun createLocationBasedApps(appUrl: String?, references: List<String>?, distance: Int? = null, locationAccuracy: Double? = null): List<App> {
126126
appUrl ?: return emptyList()
127127

128128
val manifest = runCatching { manifestClient.getManifest(appUrl) }.getOrNull()
@@ -144,7 +144,8 @@ class AppRepositoryImpl(
144144
display = manifest?.display,
145145
poiId = it.key,
146146
distance = distance,
147-
brandUrl = appUrl
147+
brandUrl = appUrl,
148+
locationAccuracy = locationAccuracy
148149
)
149150
}
150151
}

library/src/main/java/cloud/pace/sdk/appkit/model/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ data class App(
1212
val display: String? = null,
1313
val poiId: String? = null,
1414
val distance: Int? = null,
15-
val brandUrl: String? = null
15+
val brandUrl: String? = null,
16+
val locationAccuracy: Double? = null
1617
)

library/src/test/java/cloud/pace/sdk/appkit/AppManagerTest.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class AppManagerTest : CloudSDKKoinComponent {
5353
`when`(mockLocation.latitude).then { 49.012722 }
5454
`when`(mockLocation.longitude).then { 8.427326 }
5555
`when`(mockLocation.speed).then { 3f }
56+
`when`(mockLocation.accuracy).then { 2f }
5657

5758
mockkObject(PACECloudSDK)
5859
every { PACECloudSDK.configuration.speedThresholdInKmPerHour } returns 50
@@ -76,7 +77,7 @@ class AppManagerTest : CloudSDKKoinComponent {
7677
)
7778

7879
val appRepository = object : TestAppRepository() {
79-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
80+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
8081
return Success(listOf(app1))
8182
}
8283
}
@@ -130,7 +131,7 @@ class AppManagerTest : CloudSDKKoinComponent {
130131
)
131132

132133
val appRepository = object : TestAppRepository() {
133-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
134+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
134135
return Success(listOf(app1))
135136
}
136137
}
@@ -212,7 +213,7 @@ class AppManagerTest : CloudSDKKoinComponent {
212213
@Test
213214
fun `no app due to network error`() {
214215
val appRepository = object : TestAppRepository() {
215-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
216+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
216217
return Failure(Exception())
217218
}
218219
}
@@ -288,14 +289,15 @@ class AppManagerTest : CloudSDKKoinComponent {
288289
)
289290

290291
val appRepository = object : TestAppRepository() {
291-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
292+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
292293
return Success(listOf(app1))
293294
}
294295
}
295296

296297
every { location.latitude } returns 49.012722
297298
every { location.longitude } returns 8.427326
298299
every { location.speed } returns 3f
300+
every { location.accuracy } returns 2f
299301
every { location.speedAccuracyMetersPerSecond } returns 2f
300302

301303
val testModule = module {
@@ -379,7 +381,7 @@ class AppManagerTest : CloudSDKKoinComponent {
379381
)
380382

381383
val appRepository = object : TestAppRepository() {
382-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
384+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
383385
return Success(listOf(app1, app2, app3))
384386
}
385387
}

library/src/test/java/cloud/pace/sdk/appkit/utils/MockFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ open class TestLocationProvider(
7373

7474
open class TestAppRepository : AppRepository {
7575

76-
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double): Completion<List<App>> {
76+
override suspend fun getLocationBasedApps(latitude: Double, longitude: Double, locationAccuracy: Double?): Completion<List<App>> {
7777
return Success(emptyList())
7878
}
7979

0 commit comments

Comments
 (0)