Skip to content

Commit

Permalink
Replace Places API with Here API
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaailashsharma committed Dec 27, 2023
1 parent 9561310 commit 0de5d77
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.waste2wealth.com.ktorClient.here.dto


import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable

@Serializable
data class Acces(
@SerializedName("lat")
val lat: Double?,
@SerializedName("lng")
val lng: Double?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package app.waste2wealth.com.ktorClient.here.dto


import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable


@Serializable
data class Address(
@SerializedName("city")
val city: String?,
@SerializedName("countryCode")
val countryCode: String?,
@SerializedName("countryName")
val countryName: String?,
@SerializedName("county")
val county: String?,
@SerializedName("district")
val district: String?,
@SerializedName("label")
val label: String?,
@SerializedName("postalCode")
val postalCode: String?,
@SerializedName("state")
val state: String?,
@SerializedName("stateCode")
val stateCode: String?,
@SerializedName("subdistrict")
val subdistrict: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.waste2wealth.com.ktorClient.here.dto


import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable


@Serializable
data class Category(
@SerializedName("id")
val id: String?,
@SerializedName("name")
val name: String?,
@SerializedName("primary")
val primary: Boolean?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.waste2wealth.com.ktorClient.here.dto


import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable


@Serializable
data class HerePlaces(
@SerializedName("items")
val items: List<Item?>?
)
26 changes: 26 additions & 0 deletions app/src/main/java/app/waste2wealth/com/ktorClient/here/dto/Item.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package app.waste2wealth.com.ktorClient.here.dto


import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable


@Serializable
data class Item(
@SerializedName("access")
val access: List<Acces?>?,
@SerializedName("address")
val address: Address?,
@SerializedName("categories")
val categories: List<Category?>?,
@SerializedName("distance")
val distance: Int?,
@SerializedName("id")
val id: String?,
@SerializedName("position")
val position: Position?,
@SerializedName("resultType")
val resultType: String?,
@SerializedName("title")
val title: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.waste2wealth.com.ktorClient.here.dto


import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable


@Serializable
data class Position(
@SerializedName("lat")
val lat: Double?,
@SerializedName("lng")
val lng: Double?
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package app.waste2wealth.com.ktorClient.repository

import app.waste2wealth.com.ktorClient.Resource
import app.waste2wealth.com.ktorClient.here.dto.HerePlaces
import app.waste2wealth.com.ktorClient.placesAPI.dto.Places
import io.ktor.client.HttpClient
import io.ktor.client.request.get

class PlacesRepoImpl(private val client: HttpClient) : PlacesRepository {
override suspend fun getPlaces(latLong: String): Resource<Places> {
override suspend fun getPlaces(latLong: String): Resource<HerePlaces> {
return try {
Resource.Success(
client.get<Places>(
"https://maps.googleapis.com/maps/api/geocode/json?" +
"latlng=$latLong&key=AIzaSyC_z_sTz6p0bG6pGBetmvs3eJPitx3a8IY"
client.get<HerePlaces>(
"https://revgeocode.search.hereapi.com/v1/" +
"revgeocode?at=$latLong" +
"&apiKey=OVXwPOfMbCfNnN2Vfv3lWpZnf_MMioswgR650v5gDug"
)
)
} catch (e: Exception) {
println("API is ${e.message}")
println("API is ${e.printStackTrace()}")
Resource.Failure(e)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package app.waste2wealth.com.ktorClient.repository

import app.waste2wealth.com.ktorClient.Resource
import app.waste2wealth.com.ktorClient.here.dto.HerePlaces
import app.waste2wealth.com.ktorClient.placesAPI.dto.Places


interface PlacesRepository {
suspend fun getPlaces(latLong: String): Resource<Places>
suspend fun getPlaces(latLong: String): Resource<HerePlaces>
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class LocationViewModel @Inject constructor(
}

is Resource.Success -> {
resource.result.results?.forEach { address ->
listOfAddresses.add(address.formattedAddress)
resource.result.items?.forEach { address ->
listOfAddresses.add(address?.address?.label)
}
latitude = it.latitude
longitude = it.longitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ fun NavigationController(

}
composable(Screens.Community.route) {
CommunitiesSection(
paddingValues = paddingValues,
email = email.value,
name = name.value,
)
// CommunitiesSection(
// paddingValues = paddingValues,
// email = email.value,
// name = name.value,
// )
// CommunityInfo()
}
composable(Screens.ReportWaste.route) {
Expand Down

0 comments on commit 0de5d77

Please sign in to comment.