Skip to content

Commit

Permalink
Returned places list is immutable in Places API 1.1.0
Browse files Browse the repository at this point in the history
This commit fixes #6

Signed-off-by: Rafael Chagas <[email protected]>
  • Loading branch information
rtchagas committed Apr 25, 2019
1 parent a7a3218 commit df1e846
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class GoogleMapsRepository @Inject constructor(
googleClient.findCurrentPlace(request).addOnCompleteListener { task ->
if (task.isSuccessful) {
task.result?.let {
sortByLikelihood(it.placeLikelihoods)
emitter.onSuccess(it.placeLikelihoods.map { likelihood -> likelihood.place })
val placeList = sortByLikelihood(it.placeLikelihoods)
emitter.onSuccess(placeList.map { likelihood -> likelihood.place })
}
// Empty result
emitter.onSuccess(listOf())
Expand Down Expand Up @@ -93,7 +93,7 @@ class GoogleMapsRepository @Inject constructor(

return googleMapsAPI.findByLocation(paramLocation, PingPlacePicker.geoLocationApiKey)
.flatMap { result: GeocodeResult ->
if (("OK" == result.status) && !result.results.isEmpty()) {
if (("OK" == result.status) && result.results.isNotEmpty()) {
return@flatMap getPlaceById(result.results[0].placeId)
}
return@flatMap Single.just(null)
Expand Down Expand Up @@ -137,9 +137,12 @@ class GoogleMapsRepository @Inject constructor(
/**
* Sorts the list by Likelihood. The best ranked places come first.
*/
private fun sortByLikelihood(placeLikelihoods: MutableList<PlaceLikelihood>) {
private fun sortByLikelihood(placeLikelihoods: List<PlaceLikelihood>): List<PlaceLikelihood> {

placeLikelihoods.sortByDescending { it.likelihood }
val mutableList = placeLikelihoods.toMutableList()

mutableList.sortByDescending { it.likelihood }

return mutableList
}
}

0 comments on commit df1e846

Please sign in to comment.