Skip to content

Commit

Permalink
[NO ISSUE] Solved Maps initialization problem (#379)
Browse files Browse the repository at this point in the history
* [NO ISSUE] Solved Maps initialization problem

* removed unused import
  • Loading branch information
ferranpons authored Sep 27, 2023
1 parent 0b48005 commit 9a7f83f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 43 deletions.
16 changes: 8 additions & 8 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: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'
}
Expand Down Expand Up @@ -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("<PUT API KEY HERE>")
.withGooglePlacesApiKey("<PUT API KEY HERE>")
Expand All @@ -225,7 +225,7 @@ val locationPickerIntent = LocationPickerActivity.Builder()
.withVoiceSearchHidden()
.withUnnamedRoadHidden()
.withSearchBarHidden()
.build(applicationContext)
.build()

activity.lekuActivityResultLauncher.launch(locationPickerIntent)
```
Expand All @@ -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("<PUT API KEY HERE>")
```

Expand Down Expand Up @@ -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()
```

Expand Down Expand Up @@ -453,7 +453,7 @@ class CustomLocationsAdapter : SuggestSearchAdapter<SearchViewHolder>() {
```

```kotlin
val locationPickerIntent = LocationPickerActivity.Builder()
val locationPickerIntent = LocationPickerActivity.Builder(context)
...
.withAdapter(CustomLocationsAdapter())
.build(requireContext())
Expand Down Expand Up @@ -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())
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/adevinta/mappicker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("<PUT API KEY HERE>")
// .withGooglePlacesApiKey("<PUT API KEY HERE>")
Expand All @@ -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
Expand All @@ -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)
}

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

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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
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 11.0.0</string>
<string name="leku_lib_version" translatable="false">version 11.1.0</string>
</resources>
2 changes: 1 addition & 1 deletion docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```

Expand Down
4 changes: 2 additions & 2 deletions docs/extra.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. :)
Expand Down
9 changes: 4 additions & 5 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -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("<PUT API KEY HERE>")
.withGooglePlacesApiKey("<PUT API KEY HERE>")
Expand All @@ -162,7 +161,7 @@ val locationPickerIntent = LocationPickerActivity.Builder()
.withVoiceSearchHidden()
.withUnnamedRoadHidden()
.withSearchBarHidden()
.build(applicationContext)
.build()

activity.lekuActivityResultLauncher.launch(locationPickerIntent)
```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9a7f83f

Please sign in to comment.