-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LocationIQ api client and change additionalData to contain a json…
… object
- Loading branch information
1 parent
219d163
commit f51da02
Showing
9 changed files
with
137 additions
and
28 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
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
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
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
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
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
5 changes: 5 additions & 0 deletions
5
data-lib/src/main/java/me/profiluefter/profinote/data/geocoding/GeocodingService.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,5 @@ | ||
package me.profiluefter.profinote.data.geocoding | ||
|
||
interface GeocodingService { | ||
suspend fun reverse(latitude: Double, longitude: Double): String | ||
} |
54 changes: 54 additions & 0 deletions
54
...-lib/src/main/java/me/profiluefter/profinote/data/geocoding/LocationIQGeocodingService.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,54 @@ | ||
package me.profiluefter.profinote.data.geocoding | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.annotations.SerializedName | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import retrofit2.create | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
import javax.inject.Singleton | ||
|
||
class LocationIQGeocodingService @Inject constructor( | ||
private val api: LocationIQAPI, | ||
@Named("locationIQ") | ||
private val key: String | ||
) : GeocodingService { | ||
override suspend fun reverse(latitude: Double, longitude: Double): String = | ||
api.reverse(latitude, longitude, key).displayName | ||
} | ||
|
||
interface LocationIQAPI { | ||
@GET("v1/reverse.php") | ||
suspend fun reverse( | ||
@Query("lat") latitude: Double, | ||
@Query("lon") longitude: Double, | ||
@Query("key") key: String, | ||
@Query("format") format: String = "json" | ||
): ReverseResponse | ||
} | ||
|
||
data class ReverseResponse( | ||
@SerializedName("display_name") | ||
val displayName: String | ||
) | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object LocationIQModule { | ||
@Provides | ||
@Singleton | ||
fun locationIQAPIClient(gson: Gson, client: OkHttpClient): LocationIQAPI = Retrofit.Builder() | ||
.baseUrl("https://eu1.locationiq.com/") | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create(gson)) | ||
.build() | ||
.create() | ||
} |
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