Skip to content

Commit

Permalink
Corrected some general issues (#326)
Browse files Browse the repository at this point in the history
* Corrected nullability on markers

* improved code calls

* removed volley dependency and upgraded libs also corrected view issues

* updated content description

* corrected bottom card gradient

* changed search string hint on spanish

* changed the formatted address to be more meaningful

* corrected legacy layout issues

* removed unneeded guava workaround and upgraded play services to latest

* raised version to 9.1.0

* renamed variable
  • Loading branch information
ferranpons authored Nov 17, 2021
1 parent e1cfbfb commit 3370958
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 73 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Component library for Android that uses Google Maps and returns a latitude, long
### Prerequisites

minSdkVersion >= 21<br/>
Google Play Services = 17.0.1<br/>
Google Play Services = 18.0.0<br/>
AndroidX

### Download
Expand All @@ -81,14 +81,14 @@ Include the dependency in your app `build.gradle`:

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

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

```groovy
implementation ('com.adevinta.android:leku:9.0.0') {
implementation ('com.adevinta.android:leku:9.1.0') {
exclude group: 'com.google.android.gms'
exclude group: 'androidx.appcompat'
}
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.0.0</string>
<string name="leku_lib_version" translatable="false">version 9.1.0</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.0.0
libVersion=9.1.0
26 changes: 8 additions & 18 deletions leku/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ ext["PUBLISH_ARTIFACT_ID"] = "leku"
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

android {
compileSdkVersion 29
compileSdkVersion 31
resourcePrefix 'leku_'

defaultConfig {
minSdkVersion 21
//noinspection OldTargetApi
targetSdkVersion 29
targetSdkVersion 31
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'lib-proguard-rules.txt'
Expand Down Expand Up @@ -65,36 +64,27 @@ ktlint {
}
}

configurations.all {
// This is a workaround for the issue (remove when androidx exits alpha libraries):
// https://stackoverflow.com/questions/37347326/errorconflict-with-dependency-com-google-code-findbugsjsr305
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'com.google.guava', module: 'listenablefuture'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.google.android.material:material:1.5.0-alpha02"
implementation "com.google.android.material:material:1.5.0-beta01"
implementation 'androidx.fragment:fragment-ktx:1.3.6'

def playServicesVersion = '17.0.1'
def playServicesVersion = '18.0.0'
implementation ("com.google.android.gms:play-services-maps:$playServicesVersion") {
exclude group: "com.android.support"
}
implementation ("com.google.android.gms:play-services-location:18.0.0") {
exclude group: "com.android.support"
}

// This must be removed when places library version is >2.4.0
implementation ("com.android.volley:volley:1.2.1")

implementation ("com.google.android.libraries.places:places:2.4.0") {
implementation ("com.google.android.libraries.places:places:2.5.0") {
exclude group: "com.android.support"
}

implementation "com.google.maps:google-maps-services:0.2.9"

implementation 'io.reactivex.rxjava3:rxjava:3.1.1'
implementation 'io.reactivex.rxjava3:rxjava:3.1.2'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'nl.littlerobots.rxlint:rxlint:1.7.7'

Expand All @@ -107,7 +97,7 @@ dependencies {
androidTestImplementation "androidx.test:runner:$supportTestVersion"
androidTestImplementation "androidx.test:rules:$supportTestVersion"
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'org.mockito:mockito-core:3.6.28'
androidTestImplementation 'org.mockito:mockito-core:4.0.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
55 changes: 36 additions & 19 deletions leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class LocationPickerActivity : AppCompatActivity(),
private var lekuPoisMarkersMap: MutableMap<String, LekuPoi>? = null
private var currentMarker: Marker? = null
private var textWatcher: TextWatcher? = null
private var apiInteractor: GoogleGeocoderDataSource? = null
private var googleGeocoderDataSource: GoogleGeocoderDataSource? = null
private var isVoiceSearchEnabled = true
private var isUnnamedRoadVisible = true
private var mapStyle: Int? = null
Expand All @@ -196,9 +196,7 @@ class LocationPickerActivity : AppCompatActivity(),
it.notifyDataSetChanged()
}
} else {
searchAdapter?.let {
it.notifyDataSetChanged()
}
searchAdapter?.notifyDataSetChanged()
}
showLocationInfoLayout()
clearSearchButton?.visibility = View.INVISIBLE
Expand Down Expand Up @@ -326,10 +324,10 @@ class LocationPickerActivity : AppCompatActivity(),
placesDataSource = GooglePlacesDataSource(Places.createClient(this))
}
val geocoder = Geocoder(this, Locale.getDefault())
if (apiInteractor == null) {
apiInteractor = GoogleGeocoderDataSource(NetworkClient(), AddressBuilder())
if (googleGeocoderDataSource == null) {
googleGeocoderDataSource = GoogleGeocoderDataSource(NetworkClient(), AddressBuilder())
}
val geocoderRepository = GeocoderRepository(AndroidGeocoderDataSource(geocoder), apiInteractor!!)
val geocoderRepository = GeocoderRepository(AndroidGeocoderDataSource(geocoder), googleGeocoderDataSource!!)
val timeZoneDataSource = GoogleTimeZoneDataSource(
GeoApiContext.Builder().apiKey(GoogleTimeZoneDataSource.getApiKey(this)).build())
geocoderPresenter = GeocoderPresenter(
Expand Down Expand Up @@ -556,7 +554,9 @@ class LocationPickerActivity : AppCompatActivity(),
REQUEST_PLACE_PICKER -> if (resultCode == Activity.RESULT_OK && data != null) {
val matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
searchView = findViewById(R.id.leku_search)
retrieveLocationFrom(matches[0])
matches?.let {
retrieveLocationFrom(it[0])
}
}
else -> {
}
Expand Down Expand Up @@ -874,8 +874,8 @@ class LocationPickerActivity : AppCompatActivity(),
setLayoutVisibilityFromBundle(savedInstanceState)
}
if (savedInstanceState.keySet().contains(GEOLOC_API_KEY)) {
apiInteractor = GoogleGeocoderDataSource(NetworkClient(), AddressBuilder())
apiInteractor?.setApiKey(savedInstanceState.getString(GEOLOC_API_KEY, ""))
googleGeocoderDataSource = GoogleGeocoderDataSource(NetworkClient(), AddressBuilder())
googleGeocoderDataSource?.setApiKey(savedInstanceState.getString(GEOLOC_API_KEY, ""))
}
if (savedInstanceState.keySet().contains(PLACES_API_KEY)) {
googlePlacesApiKey = savedInstanceState.getString(PLACES_API_KEY, "")
Expand Down Expand Up @@ -947,7 +947,7 @@ class LocationPickerActivity : AppCompatActivity(),
}
if (transitionBundle.keySet().contains(GEOLOC_API_KEY)) {

apiInteractor?.setApiKey(transitionBundle.getString(GEOLOC_API_KEY, ""))
googleGeocoderDataSource?.setApiKey(transitionBundle.getString(GEOLOC_API_KEY, ""))
}
if (transitionBundle.keySet().contains(PLACES_API_KEY)) {
googlePlacesApiKey = transitionBundle.getString(PLACES_API_KEY, "")
Expand Down Expand Up @@ -1014,7 +1014,7 @@ class LocationPickerActivity : AppCompatActivity(),
val result = googleAPI.isGooglePlayServicesAvailable(applicationContext)
if (result != ConnectionResult.SUCCESS) {
if (googleAPI.isUserResolvableError(result)) {
googleAPI.getErrorDialog(this, result, CONNECTION_FAILURE_RESOLUTION_REQUEST).show()
googleAPI.getErrorDialog(this, result, CONNECTION_FAILURE_RESOLUTION_REQUEST)?.show()
}
return false
}
Expand All @@ -1035,17 +1035,26 @@ class LocationPickerActivity : AppCompatActivity(),

private fun setLocationInfo(address: Address) {
street?.let {
val formattedAddress = getFormattedAddress(address)
if (isUnnamedRoadVisible) {
it.text = address.getAddressLine(0)
it.text = formattedAddress
} else {
it.text = removeUnnamedRoad(address.getAddressLine(0))
it.text = removeUnnamedRoad(formattedAddress)
}
}
city?.text = if (isStreetEqualsCity(address)) "" else address.locality
zipCode?.text = address.postalCode
showAddressLayout()
}

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

private fun setLocationInfo(poi: LekuPoi) {
this.currentLekuPoi = poi
street?.text = poi.title
Expand Down Expand Up @@ -1293,7 +1302,9 @@ class LocationPickerActivity : AppCompatActivity(),
val marker = addPoiMarker(LatLng(location.latitude, location.longitude),
lekuPoi.title, lekuPoi.address)
lekuPoisMarkersMap?.let {
it[marker.id] = lekuPoi
marker?.let { marker ->
it[marker.id] = lekuPoi
}
}
}

Expand Down Expand Up @@ -1333,15 +1344,21 @@ class LocationPickerActivity : AppCompatActivity(),
googleApiClient?.connect()
}

private fun addMarker(latLng: LatLng): Marker {
return map!!.addMarker(MarkerOptions().position(latLng).draggable(true))
private fun addMarker(latLng: LatLng): Marker? {
map?.let {
return it.addMarker(MarkerOptions().position(latLng).draggable(true))
}
return null
}

private fun addPoiMarker(latLng: LatLng, title: String, address: String): Marker {
return map!!.addMarker(MarkerOptions().position(latLng)
private fun addPoiMarker(latLng: LatLng, title: String, address: String): Marker? {
map?.let {
return it.addMarker(MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
.title(title)
.snippet(address))
}
return null
}

private fun setNewLocation(address: Address) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:dither="true"
android:startColor="#FFFFFFFF"
android:endColor="#00FFFFFF"
android:startColor="#4D000000" />
android:angle="270"
android:dither="true"
/>
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:orientation="vertical"
>

<fragment android:layout_width="match_parent"
<androidx.fragment.app.FragmentContainerView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.adevinta.leku.LocationPickerActivity"
Expand All @@ -22,7 +22,6 @@
android:gravity="top|start"
android:layout_marginTop="80dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:visibility="gone"
/>

Expand Down Expand Up @@ -60,14 +59,14 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:srcCompat="@drawable/leku_ic_satellite_on_legacy"
app:fabSize="normal"
app:tint="?colorPrimary"
app:backgroundTint="@color/leku_white"
app:rippleColor="@color/leku_soft_grey"
app:elevation="2dp"
tools:background="@color/leku_white"
android:contentDescription="@string/leku_accessibility_satellite_button_description"
/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
Expand All @@ -76,14 +75,14 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="@drawable/leku_ic_gps_lime_legacy"
app:fabSize="normal"
app:tint="?colorPrimary"
app:backgroundTint="@color/leku_white"
app:rippleColor="@color/leku_soft_grey"
app:elevation="2dp"
tools:background="@color/leku_white"
android:contentDescription="@string/leku_accessibility_my_location_button_description"
/>

<FrameLayout
Expand Down Expand Up @@ -115,7 +114,6 @@
android:paddingTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
>

<include layout="@layout/leku_layout_coordinates" />
Expand All @@ -134,6 +132,7 @@
app:rippleColor="?colorPrimaryDark"
app:elevation="2dp"
tools:background="?colorPrimary"
android:contentDescription="@string/leku_use_this_location"
/>

</LinearLayout>
Expand Down
Loading

0 comments on commit 3370958

Please sign in to comment.