Skip to content

Commit

Permalink
Solved issues with Address parser and search address list (#330)
Browse files Browse the repository at this point in the history
* Solved issue with address formatted raised null exception

* Added "No search results" when searching and not finding anything

* raised version

* corrected typo
  • Loading branch information
ferranpons authored Nov 22, 2021
1 parent 3370958 commit 2d468f5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ Include the dependency in your app `build.gradle`:

```groovy
dependencies {
implementation 'com.adevinta.android:leku:9.1.0'
implementation 'com.adevinta.android:leku:9.1.1'
}
```

Alternatively, if you are using a different version of Google Play Services and AndroidX use this instead:

```groovy
implementation ('com.adevinta.android:leku:9.1.0') {
implementation ('com.adevinta.android:leku:9.1.1') {
exclude group: 'com.google.android.gms'
exclude group: 'androidx.appcompat'
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adevinta/mappicker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MainActivity : AppCompatActivity() {
.withLocation(DEMO_LATITUDE, DEMO_LONGITUDE)
// .withGeolocApiKey("<PUT API KEY HERE>")
// .withGooglePlacesApiKey("<PUT API KEY HERE>")
// .withSearchZone("es_ES")
.withSearchZone("es_ES")
// .withSearchZone(SearchZoneRect(LatLng(26.525467, -18.910366), LatLng(43.906271, 5.394197)))
.withDefaultLocaleSearchZone()
// .shouldReturnOkOnBackPressed()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<string name="launch_legacy_map_picker" translatable="false">LAUNCH LEGACY MAP LOCATION ACTIVITY</string>
<string name="launch_map_picker_with_pois" translatable="false">LAUNCH MAP WITH POIS</string>
<string name="launch_map_picker_with_style" translatable="false">LAUNCH MAP WITH STYLE</string>
<string name="leku_lib_version" translatable="false">version 9.1.0</string>
<string name="leku_lib_version" translatable="false">version 9.1.1</string>
</resources>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx2048m
org.gradle.configureondemand=false
android.useAndroidX=true
libGroup=com.adevinta.android
libVersion=9.1.0
libVersion=9.1.1
4 changes: 2 additions & 2 deletions leku/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.leku_searchableable"
android:resource="@leku_searchableable" />
<meta-data android:name="android.leku_searchable"
android:resource="@leku_searchable" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
Expand Down
52 changes: 36 additions & 16 deletions leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,25 @@ class LocationPickerActivity : AppCompatActivity(),
adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, locationNameList)
listResult?.let {
it.adapter = adapter
it.setOnItemClickListener { _, _, i, _ ->
setNewLocation(locationList[i])
changeListResultVisibility(View.GONE)
closeKeyboard()
it.setOnItemClickListener { _, _, position, _ ->
if (locationList[position].hasLatitude() && locationList[position].hasLongitude()) {
setNewLocation(locationList[position])
changeListResultVisibility(View.GONE)
closeKeyboard()
}
}
}
} else {
linearLayoutManager = LinearLayoutManager(this)
searchAdapter = LocationSearchAdapter(
locationNameList, object : LocationSearchAdapter.SearchItemClickListener {
override fun onItemClick(position: Int) {
setNewLocation(locationList[position])
changeListResultVisibility(View.GONE)
closeKeyboard()
hideSearchLayout()
if (locationList[position].hasLatitude() && locationList[position].hasLongitude()) {
setNewLocation(locationList[position])
changeListResultVisibility(View.GONE)
closeKeyboard()
hideSearchLayout()
}
}
}
)
Expand Down Expand Up @@ -731,14 +735,24 @@ class LocationPickerActivity : AppCompatActivity(),
fillLocationList(addresses)
if (addresses.isNotEmpty()) {
updateLocationNameList(addresses)
if (isLegacyLayoutEnabled) {
adapter?.notifyDataSetChanged()
} else {
searchAdapter?.notifyDataSetChanged()
}
} else {
setNoSearchResultsOnList()
}

if (isLegacyLayoutEnabled) {
adapter?.notifyDataSetChanged()
} else {
searchAdapter?.notifyDataSetChanged()
}
}

private fun setNoSearchResultsOnList() {
val noResultsAddress = Address(Locale.getDefault())
locationList.add(noResultsAddress)
locationNameList.clear()
locationNameList.add(getString(R.string.leku_no_search_results))
}

override fun didLoadLocation() {
progressBar?.visibility = View.GONE

Expand Down Expand Up @@ -1048,10 +1062,16 @@ class LocationPickerActivity : AppCompatActivity(),
}

private fun getFormattedAddress(address: Address): String {
return if (address.subThoroughfare.isNullOrEmpty()) {
address.thoroughfare
} else {
return if (!address.thoroughfare.isNullOrEmpty() && !address.subThoroughfare.isNullOrEmpty()) {
getString(R.string.leku_formatted_address, address.thoroughfare, address.subThoroughfare)
} else {
if (address.subThoroughfare.isNullOrEmpty() && !address.thoroughfare.isNullOrEmpty()) {
address.thoroughfare
} else if (address.thoroughfare.isNullOrEmpty() && !address.subThoroughfare.isNullOrEmpty()) {
address.subThoroughfare
} else {
address.getAddressLine(0)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion leku/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<string name="leku_title_activity_location_picker">Location Picker</string>
<string name="leku_no_geocoder_available">Servicio no disponible</string>
<string name="leku_load_location_error">Algo ha ido mal. Por favor inténtelo de nuevo.</string>
<string name="leku_no_search_results">No hay resultados para su búsqueda</string>
<string name="leku_no_search_results">No se han encontrado resultados</string>
<string name="leku_network_resource">network</string>
<string name="leku_unknown_location">ubicación desconocida</string>
<string name="leku_voice_search_promp">Búsqueda por voz…</string>
Expand Down
2 changes: 1 addition & 1 deletion leku/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<string name="leku_title_activity_location_picker" tools:ignore="UnusedResources">Location Picker</string>
<string name="leku_no_geocoder_available">Service not available</string>
<string name="leku_load_location_error">Something went wrong. Please try again.</string>
<string name="leku_no_search_results">There are no results for your search</string>
<string name="leku_no_search_results">There are no search results</string>
<string name="leku_network_resource">network</string>
<string name="leku_unknown_location">unknown location</string>
<string name="leku_voice_search_promp">Search by voice…</string>
Expand Down

0 comments on commit 2d468f5

Please sign in to comment.