diff --git a/README.md b/README.md index 1d86ebdd..24d7d06d 100644 --- a/README.md +++ b/README.md @@ -81,14 +81,14 @@ Include the dependency in your app `build.gradle`: ```groovy dependencies { - implementation 'com.adevinta.android:leku:11.0.0' + implementation 'com.adevinta.android:leku:11.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:11.0.0') { +implementation ('com.adevinta.android:leku:11.1.0') { exclude group: 'com.google.android.gms' exclude group: 'androidx.appcompat' } @@ -208,7 +208,7 @@ val lekuActivityResultLauncher = } val activity = context as MainActivity -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(applicationContext) .withLocation(41.4036299, 2.1743558) .withGeolocApiKey("") .withGooglePlacesApiKey("") @@ -225,7 +225,7 @@ val locationPickerIntent = LocationPickerActivity.Builder() .withVoiceSearchHidden() .withUnnamedRoadHidden() .withSearchBarHidden() - .build(applicationContext) + .build() activity.lekuActivityResultLauncher.launch(locationPickerIntent) ``` @@ -242,7 +242,7 @@ Leku now supports Google Places queries using the search box. If you want to ena 2. Add the key to the location picker builder ```kotlin -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) .withGooglePlacesApiKey("") ``` @@ -342,7 +342,7 @@ intent.putExtra(LocationPickerActivity.LAYOUTS_TO_HIDE, "street|city|zipcode") If you want to use the old Leku layout design you need to add this line to the builder: ```kotlin -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) .withLegacyLayout() ``` @@ -453,7 +453,7 @@ class CustomLocationsAdapter : SuggestSearchAdapter() { ``` ```kotlin -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) ... .withAdapter(CustomLocationsAdapter()) .build(requireContext()) @@ -498,7 +498,7 @@ class LocationDataSource(val locationRepository: LocationRepository) : GeocoderD ``` ```kotlin -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) ... .withDataSource(LocationDataSource(myLocationRepository)) .build(requireContext()) diff --git a/app/src/main/java/com/adevinta/mappicker/MainActivity.kt b/app/src/main/java/com/adevinta/mappicker/MainActivity.kt index f66f3dc1..79fb54ba 100644 --- a/app/src/main/java/com/adevinta/mappicker/MainActivity.kt +++ b/app/src/main/java/com/adevinta/mappicker/MainActivity.kt @@ -142,7 +142,7 @@ class MainActivity : AppCompatActivity() { private fun onLaunchMapPickerClicked(context: Context) { val activity = context as MainActivity - val locationPickerIntent = LocationPickerActivity.Builder() + val locationPickerIntent = LocationPickerActivity.Builder(activity) .withLocation(DEMO_LATITUDE, DEMO_LONGITUDE) // .withGeolocApiKey("") // .withGooglePlacesApiKey("") @@ -160,7 +160,7 @@ private fun onLaunchMapPickerClicked(context: Context) { // .withVoiceSearchHidden() .withUnnamedRoadHidden() // .withSearchBarHidden() - .build(activity) + .build() // this is optional if you want to return RESULT_OK if you don't set the // latitude/longitude and click back button @@ -171,11 +171,11 @@ private fun onLaunchMapPickerClicked(context: Context) { private fun onLegacyMapClicked(context: Context) { val activity = context as MainActivity - val locationPickerIntent = LocationPickerActivity.Builder() + val locationPickerIntent = LocationPickerActivity.Builder(activity) .withLocation(DEMO_LATITUDE, DEMO_LONGITUDE) .withUnnamedRoadHidden() .withLegacyLayout() - .build(activity) + .build() activity.lekuActivityResultLauncher.launch(locationPickerIntent) } @@ -201,20 +201,20 @@ private val lekuPois: List private fun onMapPoisClicked(context: Context) { val activity = context as MainActivity - val locationPickerIntent = LocationPickerActivity.Builder() + val locationPickerIntent = LocationPickerActivity.Builder(activity) .withLocation(DEMO_LATITUDE, DEMO_LONGITUDE) .withPois(lekuPois) - .build(activity) + .build() activity.mapPoisActivityResultLauncher.launch(locationPickerIntent) } private fun onMapWithStylesClicked(context: Context) { val activity = context as MainActivity - val locationPickerIntent = LocationPickerActivity.Builder() + val locationPickerIntent = LocationPickerActivity.Builder(activity) .withLocation(DEMO_LATITUDE, DEMO_LONGITUDE) .withMapStyle(R.raw.map_style_retro) - .build(activity) + .build() activity.mapPoisActivityResultLauncher.launch(locationPickerIntent) } diff --git a/app/src/main/java/com/adevinta/mappicker/SampleApplication.kt b/app/src/main/java/com/adevinta/mappicker/SampleApplication.kt index ace16780..c6d1b63b 100644 --- a/app/src/main/java/com/adevinta/mappicker/SampleApplication.kt +++ b/app/src/main/java/com/adevinta/mappicker/SampleApplication.kt @@ -1,11 +1,5 @@ package com.adevinta.mappicker import androidx.multidex.MultiDexApplication -import com.google.android.gms.maps.MapsInitializer -class SampleApplication : MultiDexApplication() { - override fun onCreate() { - super.onCreate() - MapsInitializer.initialize(this) - } -} +class SampleApplication : MultiDexApplication() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4c40aea5..0941ddd2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,5 +5,5 @@ LAUNCH LEGACY MAP LOCATION ACTIVITY LAUNCH MAP WITH POIS LAUNCH MAP WITH STYLE - version 11.0.0 + version 11.1.0 diff --git a/docs/customization.md b/docs/customization.md index 36cd3c7a..10bf66c2 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -36,7 +36,7 @@ intent.putExtra(LocationPickerActivity.LAYOUTS_TO_HIDE, "street|city|zipcode") If you want to use the old Leku layout design you need to add this line to the builder: ```kotlin -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) .withLegacyLayout() ``` diff --git a/docs/extra.md b/docs/extra.md index f78c0830..938f19b3 100644 --- a/docs/extra.md +++ b/docs/extra.md @@ -101,9 +101,9 @@ Leku now supports Google Places queries using the search box. If you want to ena 3. Enable it when instantiating LocationPickerActivity by adding `.withGooglePlacesEnabled()`: ```kotlin -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) **.withGooglePlacesEnabled()** - .build(applicationContext) + .build() ``` And you are good to go. :) diff --git a/docs/getting_started.md b/docs/getting_started.md index 64870d3c..840c6ea5 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -18,14 +18,14 @@ Include the dependency in your app `build.gradle`: ```groovy dependencies { - implementation 'com.adevinta.android:leku:11.0.0' + implementation 'com.adevinta.android:leku:11.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:11.0.0') { +implementation ('com.adevinta.android:leku:11.1.0') { exclude group: 'com.google.android.gms' exclude group: 'androidx.appcompat' } @@ -144,8 +144,7 @@ val lekuActivityResultLauncher = } } -val activity = context as MainActivity -val locationPickerIntent = LocationPickerActivity.Builder() +val locationPickerIntent = LocationPickerActivity.Builder(context) .withLocation(41.4036299, 2.1743558) .withGeolocApiKey("") .withGooglePlacesApiKey("") @@ -162,7 +161,7 @@ val locationPickerIntent = LocationPickerActivity.Builder() .withVoiceSearchHidden() .withUnnamedRoadHidden() .withSearchBarHidden() - .build(applicationContext) + .build() activity.lekuActivityResultLauncher.launch(locationPickerIntent) ``` diff --git a/gradle.properties b/gradle.properties index 4469f847..ac8d110a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2048m org.gradle.configureondemand=false android.useAndroidX=true libGroup=com.adevinta.android -libVersion=11.0.0 +libVersion=11.1.0 android.defaults.buildfeatures.buildconfig=true android.nonTransitiveRClass=false diff --git a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt index 2225a2f1..767720e6 100644 --- a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt +++ b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt @@ -80,6 +80,7 @@ import com.adevinta.leku.locale.SearchZoneRect import com.adevinta.leku.permissions.PermissionUtils import com.adevinta.leku.tracker.TrackEvents import com.adevinta.leku.utils.ReactiveLocationProvider +import com.google.android.gms.maps.MapsInitializer import com.google.android.gms.maps.model.BitmapDescriptor import com.google.android.gms.maps.model.BitmapDescriptorFactory import com.google.android.gms.maps.model.LatLng @@ -144,10 +145,8 @@ class LocationPickerActivity : companion object { var customDataSource: GeocoderDataSourceInterface? = null var customAdapter: LekuSearchAdapter<*, *>? = null - var currentLocationBitmapMaker: BitmapDescriptor? = - BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED) - var otherLocationBitmapMaker: BitmapDescriptor? = - BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE) + var currentLocationBitmapMaker: BitmapDescriptor? = null + var otherLocationBitmapMaker: BitmapDescriptor? = null } private var map: GoogleMap? = null @@ -376,6 +375,9 @@ class LocationPickerActivity : } searchEditLayout = findViewById(R.id.leku_search_touch_zone) searchFrameLayout = findViewById(R.id.search_frame_layout) + + currentLocationBitmapMaker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED) + otherLocationBitmapMaker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE) } private fun setUpResultsList() { @@ -1676,7 +1678,7 @@ class LocationPickerActivity : .replace(UNNAMED_ROAD_WITH_HYPHEN, "") } - class Builder { + class Builder(val context: Context) { private var locationLatitude: Double? = null private var locationLongitude: Double? = null private var searchZoneLocale: String? = null @@ -1697,10 +1699,12 @@ class LocationPickerActivity : private var unnamedRoadVisible = true private var isLegacyLayoutEnabled = false private var isSearchBarHidden = false - private var currentLocationBitmapMaker: BitmapDescriptor = - BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED) - private var otherLocationBitmapMaker: BitmapDescriptor = - BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE) + private var currentLocationBitmapMaker: BitmapDescriptor? = null + private var otherLocationBitmapMaker: BitmapDescriptor? = null + + init { + MapsInitializer.initialize(context) + } fun setCurrentLocation(currentLocation: BitmapDescriptor): Builder { this.currentLocationBitmapMaker = currentLocation @@ -1828,7 +1832,7 @@ class LocationPickerActivity : return this } - fun build(context: Context): Intent { + fun build(): Intent { val intent = Intent(context, LocationPickerActivity::class.java) locationLatitude?.let {