From c015d4d2f8598023ffe86302c9cecc069637ae44 Mon Sep 17 00:00:00 2001 From: Rafael Chagas Date: Thu, 21 May 2020 01:18:21 +0200 Subject: [PATCH] Add a name when a custom place doesn't have one Signed-off-by: Rafael Chagas --- .../repository/googlemaps/GoogleMapsRepository.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/rtchagas/pingplacepicker/repository/googlemaps/GoogleMapsRepository.kt b/library/src/main/java/com/rtchagas/pingplacepicker/repository/googlemaps/GoogleMapsRepository.kt index b7e2ee7..6efa4f7 100644 --- a/library/src/main/java/com/rtchagas/pingplacepicker/repository/googlemaps/GoogleMapsRepository.kt +++ b/library/src/main/java/com/rtchagas/pingplacepicker/repository/googlemaps/GoogleMapsRepository.kt @@ -154,11 +154,22 @@ class GoogleMapsRepository constructor( val latLng = LatLng(place.geometry.location.lat, place.geometry.location.lng) - val address = + val address: String = if (place.formattedAddress.isNotEmpty()) place.formattedAddress else place.vicinity - return CustomPlace(place.placeId, place.name, photoList, address, typeList, latLng) + val name: String = buildPlaceName(place.name, address) + + return CustomPlace(place.placeId, name, photoList, address, typeList, latLng) + } + + private fun buildPlaceName(originalName: String, address: String): String { + // We have a nice name, use it + if (originalName.isNotEmpty()) { + return originalName + } + // Return the first part of the address, usually the street + number + return address.split(",").first() } /**