Skip to content

Commit

Permalink
Upgraded to api 33 and updated documentation (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranpons committed Feb 8, 2023
1 parent c83fc45 commit 070277e
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 120 deletions.
92 changes: 40 additions & 52 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 = 18.0.0<br/>
Google Play Services = 18.1.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.1.4'
implementation 'com.adevinta.android:leku:10.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.1.4') {
implementation ('com.adevinta.android:leku:10.1.0') {
exclude group: 'com.google.android.gms'
exclude group: 'androidx.appcompat'
}
Expand Down Expand Up @@ -171,11 +171,43 @@ To use the LocationPickerActivity first you need to add these lines to your Andr
</activity>
```

Then you have setup the call to start this activity wherever you like, always as startActivityForResult.
Then you have setup the call to start this activity wherever you like, always as a ActivityResultLauncher.
You can set a default location, search zone and other customizable parameters to load when you start the activity.
You only need to use the Builder setters like:

```kotlin
val lekuActivityResultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
Log.d("RESULT****", "OK")
val latitude = data?.getDoubleExtra(LATITUDE, 0.0)
Log.d("LATITUDE****", latitude.toString())
val longitude = data?.getDoubleExtra(LONGITUDE, 0.0)
Log.d("LONGITUDE****", longitude.toString())
val address = data?.getStringExtra(LOCATION_ADDRESS)
Log.d("ADDRESS****", address.toString())
val postalcode = data?.getStringExtra(ZIPCODE)
Log.d("POSTALCODE****", postalcode.toString())
val bundle = data?.getBundleExtra(TRANSITION_BUNDLE)
Log.d("BUNDLE TEXT****", bundle?.getString("test").toString())
val fullAddress = data?.getParcelableExtra<Address>(ADDRESS)
if (fullAddress != null) {
Log.d("FULL ADDRESS****", fullAddress.toString())
}
val timeZoneId = data?.getStringExtra(TIME_ZONE_ID)
if (timeZoneId != null) {
Log.d("TIME ZONE ID****", timeZoneId)
}
val timeZoneDisplayName = data?.getStringExtra(TIME_ZONE_DISPLAY_NAME)
if (timeZoneDisplayName != null) {
Log.d("TIME ZONE NAME****", timeZoneDisplayName)
}
} else {
Log.d("RESULT****", "CANCELLED")
}
}

val activity = context as MainActivity
val locationPickerIntent = LocationPickerActivity.Builder()
.withLocation(41.4036299, 2.1743558)
.withGeolocApiKey("<PUT API KEY HERE>")
Expand All @@ -195,49 +227,7 @@ val locationPickerIntent = LocationPickerActivity.Builder()
.withSearchBarHidden()
.build(applicationContext)

startActivityForResult(locationPickerIntent, MAP_BUTTON_REQUEST_CODE)
```

And add the response code from that activity:

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && data != null) {
Log.d("RESULT****", "OK")
if (requestCode == 1) {
val latitude = data.getDoubleExtra(LATITUDE, 0.0)
Log.d("LATITUDE****", latitude.toString())
val longitude = data.getDoubleExtra(LONGITUDE, 0.0)
Log.d("LONGITUDE****", longitude.toString())
val address = data.getStringExtra(LOCATION_ADDRESS)
Log.d("ADDRESS****", address.toString())
val postalcode = data.getStringExtra(ZIPCODE)
Log.d("POSTALCODE****", postalcode.toString())
val bundle = data.getBundleExtra(TRANSITION_BUNDLE)
Log.d("BUNDLE TEXT****", bundle.getString("test"))
val fullAddress = data.getParcelableExtra<Address>(ADDRESS)
if (fullAddress != null) {
Log.d("FULL ADDRESS****", fullAddress.toString())
}
val timeZoneId = data.getStringExtra(TIME_ZONE_ID)
Log.d("TIME ZONE ID****", timeZoneId)
val timeZoneDisplayName = data.getStringExtra(TIME_ZONE_DISPLAY_NAME)
Log.d("TIME ZONE NAME****", timeZoneDisplayName)
} else if (requestCode == 2) {
val latitude = data.getDoubleExtra(LATITUDE, 0.0)
Log.d("LATITUDE****", latitude.toString())
val longitude = data.getDoubleExtra(LONGITUDE, 0.0)
Log.d("LONGITUDE****", longitude.toString())
val address = data.getStringExtra(LOCATION_ADDRESS)
Log.d("ADDRESS****", address.toString())
val lekuPoi = data.getParcelableExtra<LekuPoi>(LEKU_POI)
Log.d("LekuPoi****", lekuPoi.toString())
}
}
if (resultCode == Activity.RESULT_CANCELED) {
Log.d("RESULT****", "CANCELLED")
}
}
activity.lekuActivityResultLauncher.launch(locationPickerIntent)
```

That's all folks!
Expand Down Expand Up @@ -291,9 +281,7 @@ If you need to send and receive a param through the LocationPickerActivity you c
You only need to add an "Extra" param to the intent like:

```kotlin
val locationPickerIntent = LocationPickerActivity.Builder().build(applicationContext)
locationPickerIntent.putExtra("test", "this is a test")
startActivityForResult(locationPickerIntent, MAP_BUTTON_REQUEST_CODE)
```

And parse it on onActivityResult callback:
Expand Down Expand Up @@ -592,7 +580,7 @@ override fun onCreate(savedInstanceState: Bundle?) {
GeoApiContext.Builder().apiKey(GoogleTimeZoneDataSource.getApiKey(this)).build())
geocoderPresenter = GeocoderPresenter(
ReactiveLocationProvider(applicationContext), geocoderRepository, placesDataSource, timeZoneDataSource)
geocoderPresenter!!.setUI(this)
geocoderPresenter?.setUI(this)
***
}
```
Expand All @@ -602,11 +590,11 @@ And besides filling the interface methods you have to add some things to your ac
```kotlin
override fun onStart() {
super.onStart()
geocoderPresenter!!.setUI(this)
geocoderPresenter?.setUI(this)
}

override fun onStop() {
geocoderPresenter!!.stop()
geocoderPresenter?.stop()
super.onStop()
}
```
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "io.gitlab.arturbosch.detekt"

android {
compileSdkVersion 32
compileSdkVersion 33

defaultConfig {
applicationId "com.schibsted.mappicker"
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 33
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -70,7 +70,7 @@ dependencies {
implementation "com.google.android.material:material:1.7.0-beta01"
implementation "com.google.android.gms:play-services-maps:18.1.0"

implementation 'androidx.activity:activity-compose:1.5.1'
implementation 'androidx.activity:activity-compose:1.6.0'
implementation 'androidx.compose.material:material:1.2.1'
implementation 'androidx.compose.animation:animation:1.2.1'
implementation 'androidx.compose.ui:ui-tooling:1.2.1'
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.4</string>
<string name="leku_lib_version" translatable="false">version 10.1.0</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:7.3.0'

// Remove comment when the library is on mavenCentral
//classpath 'com.ferranpons:twitter-gradle-plugin:1.1.0'
Expand Down
8 changes: 3 additions & 5 deletions docs/extra.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ override fun onCreate(savedInstanceState: Bundle?) {
GeoApiContext.Builder().apiKey(GoogleTimeZoneDataSource.getApiKey(this)).build())
geocoderPresenter = GeocoderPresenter(
ReactiveLocationProvider(applicationContext), geocoderRepository, placesDataSource, timeZoneDataSource)
geocoderPresenter!!.setUI(this)
geocoderPresenter?.setUI(this)
***
}
```
Expand All @@ -52,11 +52,11 @@ And besides filling the interface methods you have to add some things to your ac
```kotlin
override fun onStart() {
super.onStart()
geocoderPresenter!!.setUI(this)
geocoderPresenter?.setUI(this)
}

override fun onStop() {
geocoderPresenter!!.stop()
geocoderPresenter?.stop()
super.onStop()
}
```
Expand All @@ -67,9 +67,7 @@ If you need to send and receive a param through the LocationPickerActivity you c
You only need to add an "Extra" param to the intent like:

```kotlin
val locationPickerIntent = LocationPickerActivity.Builder().build(applicationContext)
locationPickerIntent.putExtra("test", "this is a test")
startActivityForResult(locationPickerIntent, MAP_BUTTON_REQUEST_CODE)
```

And parse it on onActivityResult callback:
Expand Down
83 changes: 37 additions & 46 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:9.1.4'
implementation 'com.adevinta.android:leku:10.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.1.4') {
implementation ('com.adevinta.android:leku:10.1.0') {
exclude group: 'com.google.android.gms'
exclude group: 'androidx.appcompat'
}
Expand Down Expand Up @@ -108,14 +108,47 @@ To use the LocationPickerActivity first you need to add these lines to your Andr
</activity>
```

Then you have setup the call to start this activity wherever you like, always as startActivityForResult.
Then you have setup the call to start this activity wherever you like, always as a ActivityResultLauncher.
You can set a default location, search zone and other customizable parameters to load when you start the activity.
You only need to use the Builder setters like:

```kotlin
val lekuActivityResultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
Log.d("RESULT****", "OK")
val latitude = data?.getDoubleExtra(LATITUDE, 0.0)
Log.d("LATITUDE****", latitude.toString())
val longitude = data?.getDoubleExtra(LONGITUDE, 0.0)
Log.d("LONGITUDE****", longitude.toString())
val address = data?.getStringExtra(LOCATION_ADDRESS)
Log.d("ADDRESS****", address.toString())
val postalcode = data?.getStringExtra(ZIPCODE)
Log.d("POSTALCODE****", postalcode.toString())
val bundle = data?.getBundleExtra(TRANSITION_BUNDLE)
Log.d("BUNDLE TEXT****", bundle?.getString("test").toString())
val fullAddress = data?.getParcelableExtra<Address>(ADDRESS)
if (fullAddress != null) {
Log.d("FULL ADDRESS****", fullAddress.toString())
}
val timeZoneId = data?.getStringExtra(TIME_ZONE_ID)
if (timeZoneId != null) {
Log.d("TIME ZONE ID****", timeZoneId)
}
val timeZoneDisplayName = data?.getStringExtra(TIME_ZONE_DISPLAY_NAME)
if (timeZoneDisplayName != null) {
Log.d("TIME ZONE NAME****", timeZoneDisplayName)
}
} else {
Log.d("RESULT****", "CANCELLED")
}
}

val activity = context as MainActivity
val locationPickerIntent = LocationPickerActivity.Builder()
.withLocation(41.4036299, 2.1743558)
.withGeolocApiKey("<PUT API KEY HERE>")
.withGooglePlacesApiKey("<PUT API KEY HERE>")
.withSearchZone("es_ES")
.withSearchZone(SearchZoneRect(LatLng(26.525467, -18.910366), LatLng(43.906271, 5.394197)))
.withDefaultLocaleSearchZone()
Expand All @@ -131,49 +164,7 @@ val locationPickerIntent = LocationPickerActivity.Builder()
.withSearchBarHidden()
.build(applicationContext)

startActivityForResult(locationPickerIntent, MAP_BUTTON_REQUEST_CODE)
```

And add the response code from that activity:

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && data != null) {
Log.d("RESULT****", "OK")
if (requestCode == 1) {
val latitude = data.getDoubleExtra(LATITUDE, 0.0)
Log.d("LATITUDE****", latitude.toString())
val longitude = data.getDoubleExtra(LONGITUDE, 0.0)
Log.d("LONGITUDE****", longitude.toString())
val address = data.getStringExtra(LOCATION_ADDRESS)
Log.d("ADDRESS****", address.toString())
val postalcode = data.getStringExtra(ZIPCODE)
Log.d("POSTALCODE****", postalcode.toString())
val bundle = data.getBundleExtra(TRANSITION_BUNDLE)
Log.d("BUNDLE TEXT****", bundle.getString("test"))
val fullAddress = data.getParcelableExtra<Address>(ADDRESS)
if (fullAddress != null) {
Log.d("FULL ADDRESS****", fullAddress.toString())
}
val timeZoneId = data.getStringExtra(TIME_ZONE_ID)
Log.d("TIME ZONE ID****", timeZoneId)
val timeZoneDisplayName = data.getStringExtra(TIME_ZONE_DISPLAY_NAME)
Log.d("TIME ZONE NAME****", timeZoneDisplayName)
} else if (requestCode == 2) {
val latitude = data.getDoubleExtra(LATITUDE, 0.0)
Log.d("LATITUDE****", latitude.toString())
val longitude = data.getDoubleExtra(LONGITUDE, 0.0)
Log.d("LONGITUDE****", longitude.toString())
val address = data.getStringExtra(LOCATION_ADDRESS)
Log.d("ADDRESS****", address.toString())
val lekuPoi = data.getParcelableExtra<LekuPoi>(LEKU_POI)
Log.d("LekuPoi****", lekuPoi.toString())
}
}
if (resultCode == Activity.RESULT_CANCELED) {
Log.d("RESULT****", "CANCELLED")
}
}
activity.lekuActivityResultLauncher.launch(locationPickerIntent)
```

That's all folks!
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=10.0.3
libVersion=10.1.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 15 13:33:01 CET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
8 changes: 4 additions & 4 deletions leku/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ ext["PUBLISH_ARTIFACT_ID"] = "leku"
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

android {
compileSdkVersion 32
compileSdkVersion 33
resourcePrefix 'leku_'

defaultConfig {
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 33
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'lib-proguard-rules.txt'
Expand Down Expand Up @@ -71,7 +71,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.google.android.material:material:1.7.0-beta01"
implementation 'androidx.fragment:fragment-ktx:1.5.2'
implementation 'androidx.fragment:fragment-ktx:1.5.3'

def playServicesVersion = '18.1.0'
implementation ("com.google.android.gms:play-services-maps:$playServicesVersion") {
Expand All @@ -95,7 +95,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:4.0.0'
androidTestImplementation 'org.mockito:mockito-core:4.2.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Loading

0 comments on commit 070277e

Please sign in to comment.