Skip to content

Commit 9a7f83f

Browse files
authored
[NO ISSUE] Solved Maps initialization problem (#379)
* [NO ISSUE] Solved Maps initialization problem * removed unused import
1 parent 0b48005 commit 9a7f83f

File tree

9 files changed

+40
-43
lines changed

9 files changed

+40
-43
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ Include the dependency in your app `build.gradle`:
8181

8282
```groovy
8383
dependencies {
84-
implementation 'com.adevinta.android:leku:11.0.0'
84+
implementation 'com.adevinta.android:leku:11.1.0'
8585
}
8686
```
8787

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

9090
```groovy
91-
implementation ('com.adevinta.android:leku:11.0.0') {
91+
implementation ('com.adevinta.android:leku:11.1.0') {
9292
exclude group: 'com.google.android.gms'
9393
exclude group: 'androidx.appcompat'
9494
}
@@ -208,7 +208,7 @@ val lekuActivityResultLauncher =
208208
}
209209

210210
val activity = context as MainActivity
211-
val locationPickerIntent = LocationPickerActivity.Builder()
211+
val locationPickerIntent = LocationPickerActivity.Builder(applicationContext)
212212
.withLocation(41.4036299, 2.1743558)
213213
.withGeolocApiKey("<PUT API KEY HERE>")
214214
.withGooglePlacesApiKey("<PUT API KEY HERE>")
@@ -225,7 +225,7 @@ val locationPickerIntent = LocationPickerActivity.Builder()
225225
.withVoiceSearchHidden()
226226
.withUnnamedRoadHidden()
227227
.withSearchBarHidden()
228-
.build(applicationContext)
228+
.build()
229229

230230
activity.lekuActivityResultLauncher.launch(locationPickerIntent)
231231
```
@@ -242,7 +242,7 @@ Leku now supports Google Places queries using the search box. If you want to ena
242242
2. Add the key to the location picker builder
243243

244244
```kotlin
245-
val locationPickerIntent = LocationPickerActivity.Builder()
245+
val locationPickerIntent = LocationPickerActivity.Builder(context)
246246
.withGooglePlacesApiKey("<PUT API KEY HERE>")
247247
```
248248

@@ -342,7 +342,7 @@ intent.putExtra(LocationPickerActivity.LAYOUTS_TO_HIDE, "street|city|zipcode")
342342
If you want to use the old Leku layout design you need to add this line to the builder:
343343

344344
```kotlin
345-
val locationPickerIntent = LocationPickerActivity.Builder()
345+
val locationPickerIntent = LocationPickerActivity.Builder(context)
346346
.withLegacyLayout()
347347
```
348348

@@ -453,7 +453,7 @@ class CustomLocationsAdapter : SuggestSearchAdapter<SearchViewHolder>() {
453453
```
454454

455455
```kotlin
456-
val locationPickerIntent = LocationPickerActivity.Builder()
456+
val locationPickerIntent = LocationPickerActivity.Builder(context)
457457
...
458458
.withAdapter(CustomLocationsAdapter())
459459
.build(requireContext())
@@ -498,7 +498,7 @@ class LocationDataSource(val locationRepository: LocationRepository) : GeocoderD
498498
```
499499

500500
```kotlin
501-
val locationPickerIntent = LocationPickerActivity.Builder()
501+
val locationPickerIntent = LocationPickerActivity.Builder(context)
502502
...
503503
.withDataSource(LocationDataSource(myLocationRepository))
504504
.build(requireContext())

app/src/main/java/com/adevinta/mappicker/MainActivity.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class MainActivity : AppCompatActivity() {
142142

143143
private fun onLaunchMapPickerClicked(context: Context) {
144144
val activity = context as MainActivity
145-
val locationPickerIntent = LocationPickerActivity.Builder()
145+
val locationPickerIntent = LocationPickerActivity.Builder(activity)
146146
.withLocation(DEMO_LATITUDE, DEMO_LONGITUDE)
147147
// .withGeolocApiKey("<PUT API KEY HERE>")
148148
// .withGooglePlacesApiKey("<PUT API KEY HERE>")
@@ -160,7 +160,7 @@ private fun onLaunchMapPickerClicked(context: Context) {
160160
// .withVoiceSearchHidden()
161161
.withUnnamedRoadHidden()
162162
// .withSearchBarHidden()
163-
.build(activity)
163+
.build()
164164

165165
// this is optional if you want to return RESULT_OK if you don't set the
166166
// latitude/longitude and click back button
@@ -171,11 +171,11 @@ private fun onLaunchMapPickerClicked(context: Context) {
171171

172172
private fun onLegacyMapClicked(context: Context) {
173173
val activity = context as MainActivity
174-
val locationPickerIntent = LocationPickerActivity.Builder()
174+
val locationPickerIntent = LocationPickerActivity.Builder(activity)
175175
.withLocation(DEMO_LATITUDE, DEMO_LONGITUDE)
176176
.withUnnamedRoadHidden()
177177
.withLegacyLayout()
178-
.build(activity)
178+
.build()
179179
activity.lekuActivityResultLauncher.launch(locationPickerIntent)
180180
}
181181

@@ -201,20 +201,20 @@ private val lekuPois: List<LekuPoi>
201201

202202
private fun onMapPoisClicked(context: Context) {
203203
val activity = context as MainActivity
204-
val locationPickerIntent = LocationPickerActivity.Builder()
204+
val locationPickerIntent = LocationPickerActivity.Builder(activity)
205205
.withLocation(DEMO_LATITUDE, DEMO_LONGITUDE)
206206
.withPois(lekuPois)
207-
.build(activity)
207+
.build()
208208

209209
activity.mapPoisActivityResultLauncher.launch(locationPickerIntent)
210210
}
211211

212212
private fun onMapWithStylesClicked(context: Context) {
213213
val activity = context as MainActivity
214-
val locationPickerIntent = LocationPickerActivity.Builder()
214+
val locationPickerIntent = LocationPickerActivity.Builder(activity)
215215
.withLocation(DEMO_LATITUDE, DEMO_LONGITUDE)
216216
.withMapStyle(R.raw.map_style_retro)
217-
.build(activity)
217+
.build()
218218
activity.mapPoisActivityResultLauncher.launch(locationPickerIntent)
219219
}
220220

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package com.adevinta.mappicker
22

33
import androidx.multidex.MultiDexApplication
4-
import com.google.android.gms.maps.MapsInitializer
54

6-
class SampleApplication : MultiDexApplication() {
7-
override fun onCreate() {
8-
super.onCreate()
9-
MapsInitializer.initialize(this)
10-
}
11-
}
5+
class SampleApplication : MultiDexApplication()

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
<string name="launch_legacy_map_picker" translatable="false">LAUNCH LEGACY MAP LOCATION ACTIVITY</string>
66
<string name="launch_map_picker_with_pois" translatable="false">LAUNCH MAP WITH POIS</string>
77
<string name="launch_map_picker_with_style" translatable="false">LAUNCH MAP WITH STYLE</string>
8-
<string name="leku_lib_version" translatable="false">version 11.0.0</string>
8+
<string name="leku_lib_version" translatable="false">version 11.1.0</string>
99
</resources>

docs/customization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ intent.putExtra(LocationPickerActivity.LAYOUTS_TO_HIDE, "street|city|zipcode")
3636
If you want to use the old Leku layout design you need to add this line to the builder:
3737

3838
```kotlin
39-
val locationPickerIntent = LocationPickerActivity.Builder()
39+
val locationPickerIntent = LocationPickerActivity.Builder(context)
4040
.withLegacyLayout()
4141
```
4242

docs/extra.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ Leku now supports Google Places queries using the search box. If you want to ena
101101
3. Enable it when instantiating LocationPickerActivity by adding `.withGooglePlacesEnabled()`:
102102

103103
```kotlin
104-
val locationPickerIntent = LocationPickerActivity.Builder()
104+
val locationPickerIntent = LocationPickerActivity.Builder(context)
105105
**.withGooglePlacesEnabled()**
106-
.build(applicationContext)
106+
.build()
107107
```
108108

109109
And you are good to go. :)

docs/getting_started.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ Include the dependency in your app `build.gradle`:
1818

1919
```groovy
2020
dependencies {
21-
implementation 'com.adevinta.android:leku:11.0.0'
21+
implementation 'com.adevinta.android:leku:11.1.0'
2222
}
2323
```
2424

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

2727
```groovy
28-
implementation ('com.adevinta.android:leku:11.0.0') {
28+
implementation ('com.adevinta.android:leku:11.1.0') {
2929
exclude group: 'com.google.android.gms'
3030
exclude group: 'androidx.appcompat'
3131
}
@@ -144,8 +144,7 @@ val lekuActivityResultLauncher =
144144
}
145145
}
146146

147-
val activity = context as MainActivity
148-
val locationPickerIntent = LocationPickerActivity.Builder()
147+
val locationPickerIntent = LocationPickerActivity.Builder(context)
149148
.withLocation(41.4036299, 2.1743558)
150149
.withGeolocApiKey("<PUT API KEY HERE>")
151150
.withGooglePlacesApiKey("<PUT API KEY HERE>")
@@ -162,7 +161,7 @@ val locationPickerIntent = LocationPickerActivity.Builder()
162161
.withVoiceSearchHidden()
163162
.withUnnamedRoadHidden()
164163
.withSearchBarHidden()
165-
.build(applicationContext)
164+
.build()
166165

167166
activity.lekuActivityResultLauncher.launch(locationPickerIntent)
168167
```

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2048m
22
org.gradle.configureondemand=false
33
android.useAndroidX=true
44
libGroup=com.adevinta.android
5-
libVersion=11.0.0
5+
libVersion=11.1.0
66

77
android.defaults.buildfeatures.buildconfig=true
88
android.nonTransitiveRClass=false

leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import com.adevinta.leku.locale.SearchZoneRect
8080
import com.adevinta.leku.permissions.PermissionUtils
8181
import com.adevinta.leku.tracker.TrackEvents
8282
import com.adevinta.leku.utils.ReactiveLocationProvider
83+
import com.google.android.gms.maps.MapsInitializer
8384
import com.google.android.gms.maps.model.BitmapDescriptor
8485
import com.google.android.gms.maps.model.BitmapDescriptorFactory
8586
import com.google.android.gms.maps.model.LatLng
@@ -144,10 +145,8 @@ class LocationPickerActivity :
144145
companion object {
145146
var customDataSource: GeocoderDataSourceInterface? = null
146147
var customAdapter: LekuSearchAdapter<*, *>? = null
147-
var currentLocationBitmapMaker: BitmapDescriptor? =
148-
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)
149-
var otherLocationBitmapMaker: BitmapDescriptor? =
150-
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)
148+
var currentLocationBitmapMaker: BitmapDescriptor? = null
149+
var otherLocationBitmapMaker: BitmapDescriptor? = null
151150
}
152151

153152
private var map: GoogleMap? = null
@@ -376,6 +375,9 @@ class LocationPickerActivity :
376375
}
377376
searchEditLayout = findViewById(R.id.leku_search_touch_zone)
378377
searchFrameLayout = findViewById(R.id.search_frame_layout)
378+
379+
currentLocationBitmapMaker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)
380+
otherLocationBitmapMaker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)
379381
}
380382

381383
private fun setUpResultsList() {
@@ -1676,7 +1678,7 @@ class LocationPickerActivity :
16761678
.replace(UNNAMED_ROAD_WITH_HYPHEN, "")
16771679
}
16781680

1679-
class Builder {
1681+
class Builder(val context: Context) {
16801682
private var locationLatitude: Double? = null
16811683
private var locationLongitude: Double? = null
16821684
private var searchZoneLocale: String? = null
@@ -1697,10 +1699,12 @@ class LocationPickerActivity :
16971699
private var unnamedRoadVisible = true
16981700
private var isLegacyLayoutEnabled = false
16991701
private var isSearchBarHidden = false
1700-
private var currentLocationBitmapMaker: BitmapDescriptor =
1701-
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)
1702-
private var otherLocationBitmapMaker: BitmapDescriptor =
1703-
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)
1702+
private var currentLocationBitmapMaker: BitmapDescriptor? = null
1703+
private var otherLocationBitmapMaker: BitmapDescriptor? = null
1704+
1705+
init {
1706+
MapsInitializer.initialize(context)
1707+
}
17041708

17051709
fun setCurrentLocation(currentLocation: BitmapDescriptor): Builder {
17061710
this.currentLocationBitmapMaker = currentLocation
@@ -1828,7 +1832,7 @@ class LocationPickerActivity :
18281832
return this
18291833
}
18301834

1831-
fun build(context: Context): Intent {
1835+
fun build(): Intent {
18321836
val intent = Intent(context, LocationPickerActivity::class.java)
18331837

18341838
locationLatitude?.let {

0 commit comments

Comments
 (0)