From 5deee080949b9e8cde8945e75a90220a53ab5e0c Mon Sep 17 00:00:00 2001 From: "arturo.jimenez" Date: Tue, 9 Jan 2024 14:14:57 +0100 Subject: [PATCH 1/5] SCMI-112253 When no location in the bundle, we are still doing a search and showing results --- .../adevinta/leku/LocationPickerActivity.kt | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt index 767720e6..6b6d0d8b 100644 --- a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt +++ b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt @@ -29,12 +29,12 @@ import android.widget.EditText import android.widget.FrameLayout import android.widget.ImageButton import android.widget.ImageView +import android.widget.LinearLayout import android.widget.ListView import android.widget.ProgressBar import android.widget.RelativeLayout import android.widget.TextView import android.widget.Toast -import android.widget.LinearLayout import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RawRes @@ -43,33 +43,18 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.adevinta.leku.geocoder.AndroidGeocoderDataSource import com.adevinta.leku.geocoder.GeocoderDataSourceInterface import com.adevinta.leku.geocoder.GeocoderPresenter +import com.adevinta.leku.geocoder.GeocoderRepository import com.adevinta.leku.geocoder.GeocoderViewInterface import com.adevinta.leku.geocoder.GoogleGeocoderDataSource -import com.adevinta.leku.geocoder.GeocoderRepository -import com.adevinta.leku.geocoder.AndroidGeocoderDataSource -import com.adevinta.leku.geocoder.adapters.DefaultSuggestionAdapter import com.adevinta.leku.geocoder.PlaceSuggestion import com.adevinta.leku.geocoder.adapters.DefaultAddressAdapter +import com.adevinta.leku.geocoder.adapters.DefaultSuggestionAdapter import com.adevinta.leku.geocoder.adapters.SearchViewHolder import com.adevinta.leku.geocoder.adapters.SuggestionViewHolder import com.adevinta.leku.geocoder.adapters.base.LekuSearchAdapter -import com.google.android.gms.common.ConnectionResult -import com.google.android.gms.common.GoogleApiAvailability -import com.google.android.gms.common.api.GoogleApiClient -import com.google.android.gms.location.LocationListener -import com.google.android.gms.location.LocationServices -import com.google.android.gms.maps.CameraUpdateFactory -import com.google.android.gms.maps.GoogleMap -import com.google.android.gms.maps.GoogleMap.MAP_TYPE_NORMAL -import com.google.android.gms.maps.GoogleMap.MAP_TYPE_SATELLITE -import com.google.android.gms.maps.OnMapReadyCallback -import com.google.android.gms.maps.SupportMapFragment -import com.google.android.libraries.places.api.Places -import com.google.android.material.appbar.MaterialToolbar -import com.google.android.material.floatingactionbutton.FloatingActionButton -import com.google.maps.GeoApiContext import com.adevinta.leku.geocoder.api.AddressBuilder import com.adevinta.leku.geocoder.api.NetworkClient import com.adevinta.leku.geocoder.api.SuggestionBuilder @@ -80,14 +65,29 @@ 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.common.ConnectionResult +import com.google.android.gms.common.GoogleApiAvailability +import com.google.android.gms.common.api.GoogleApiClient +import com.google.android.gms.location.LocationListener +import com.google.android.gms.location.LocationServices +import com.google.android.gms.maps.CameraUpdateFactory +import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.GoogleMap.MAP_TYPE_NORMAL +import com.google.android.gms.maps.GoogleMap.MAP_TYPE_SATELLITE import com.google.android.gms.maps.MapsInitializer +import com.google.android.gms.maps.OnMapReadyCallback +import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.model.BitmapDescriptor import com.google.android.gms.maps.model.BitmapDescriptorFactory -import com.google.android.gms.maps.model.LatLng -import com.google.android.gms.maps.model.Marker import com.google.android.gms.maps.model.CameraPosition +import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MapStyleOptions +import com.google.android.gms.maps.model.Marker import com.google.android.gms.maps.model.MarkerOptions +import com.google.android.libraries.places.api.Places +import com.google.android.material.appbar.MaterialToolbar +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.maps.GeoApiContext import java.util.Locale import java.util.TimeZone import kotlin.collections.set @@ -1110,6 +1110,8 @@ class LocationPickerActivity : transitionBundle.keySet().contains(LONGITUDE) ) { setLocationFromBundle(transitionBundle) + } else { + setDefaultLocation() } if (transitionBundle.keySet().contains(LAYOUTS_TO_HIDE)) { setLayoutVisibilityFromBundle(transitionBundle) @@ -1210,6 +1212,14 @@ class LocationPickerActivity : isLocationInformedFromBundle = true } + private fun setDefaultLocation() { + currentLocation = Location(getString(R.string.leku_network_resource)) + currentLocation?.latitude = 0.0 + currentLocation?.longitude = 0.0 + setCurrentPositionLocation() + isLocationInformedFromBundle = true + } + private fun startVoiceRecognitionActivity() { val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) intent.putExtra( From e137e28d53fdc7203d37fb5ec0ed19998ac8b257 Mon Sep 17 00:00:00 2001 From: "arturo.jimenez" Date: Wed, 10 Jan 2024 11:32:24 +0100 Subject: [PATCH 2/5] SCMI-112253 Only add the default location if permission not granted --- app/src/main/java/com/adevinta/mappicker/MainActivity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/adevinta/mappicker/MainActivity.kt b/app/src/main/java/com/adevinta/mappicker/MainActivity.kt index 79fb54ba..96871c57 100644 --- a/app/src/main/java/com/adevinta/mappicker/MainActivity.kt +++ b/app/src/main/java/com/adevinta/mappicker/MainActivity.kt @@ -143,7 +143,6 @@ class MainActivity : AppCompatActivity() { private fun onLaunchMapPickerClicked(context: Context) { val activity = context as MainActivity val locationPickerIntent = LocationPickerActivity.Builder(activity) - .withLocation(DEMO_LATITUDE, DEMO_LONGITUDE) // .withGeolocApiKey("") // .withGooglePlacesApiKey("") .withSearchZone("es_ES") From a5509b3de0931eeb8124def5acadd5d461c42cb3 Mon Sep 17 00:00:00 2001 From: "arturo.jimenez" Date: Wed, 10 Jan 2024 11:39:17 +0100 Subject: [PATCH 3/5] SCMI-112253 Only add the default location if permission not granted --- .../java/com/adevinta/mappicker/MainActivity.kt | 1 + .../com/adevinta/leku/LocationPickerActivity.kt | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/adevinta/mappicker/MainActivity.kt b/app/src/main/java/com/adevinta/mappicker/MainActivity.kt index 96871c57..79fb54ba 100644 --- a/app/src/main/java/com/adevinta/mappicker/MainActivity.kt +++ b/app/src/main/java/com/adevinta/mappicker/MainActivity.kt @@ -143,6 +143,7 @@ class MainActivity : AppCompatActivity() { private fun onLaunchMapPickerClicked(context: Context) { val activity = context as MainActivity val locationPickerIntent = LocationPickerActivity.Builder(activity) + .withLocation(DEMO_LATITUDE, DEMO_LONGITUDE) // .withGeolocApiKey("") // .withGooglePlacesApiKey("") .withSearchZone("es_ES") diff --git a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt index 6b6d0d8b..0db3338a 100644 --- a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt +++ b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt @@ -1,11 +1,13 @@ package com.adevinta.leku +import android.Manifest import android.annotation.SuppressLint import android.app.Activity import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.content.IntentSender +import android.content.pm.PackageManager import android.content.res.Resources import android.graphics.PorterDuff import android.location.Address @@ -39,6 +41,7 @@ import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RawRes import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager @@ -1213,11 +1216,13 @@ class LocationPickerActivity : } private fun setDefaultLocation() { - currentLocation = Location(getString(R.string.leku_network_resource)) - currentLocation?.latitude = 0.0 - currentLocation?.longitude = 0.0 - setCurrentPositionLocation() - isLocationInformedFromBundle = true + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + currentLocation = Location(getString(R.string.leku_network_resource)) + currentLocation?.latitude = 0.0 + currentLocation?.longitude = 0.0 + setCurrentPositionLocation() + isLocationInformedFromBundle = true + } } private fun startVoiceRecognitionActivity() { From 53f9ec2517e07b67d16bc5a78f8074be6efcb3bf Mon Sep 17 00:00:00 2001 From: "arturo.jimenez" Date: Wed, 10 Jan 2024 12:23:27 +0100 Subject: [PATCH 4/5] SCMI-112253 Use the exiting function --- .../main/java/com/adevinta/leku/LocationPickerActivity.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt index 0db3338a..22375f06 100644 --- a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt +++ b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt @@ -1,13 +1,11 @@ package com.adevinta.leku -import android.Manifest import android.annotation.SuppressLint import android.app.Activity import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.content.IntentSender -import android.content.pm.PackageManager import android.content.res.Resources import android.graphics.PorterDuff import android.location.Address @@ -41,7 +39,6 @@ import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RawRes import androidx.appcompat.app.AppCompatActivity -import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager @@ -1216,7 +1213,7 @@ class LocationPickerActivity : } private fun setDefaultLocation() { - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + if (PermissionUtils.isLocationPermissionGranted(applicationContext)) { currentLocation = Location(getString(R.string.leku_network_resource)) currentLocation?.latitude = 0.0 currentLocation?.longitude = 0.0 From 7051ca47ce0f4d4a6e647421113b33022aa540c0 Mon Sep 17 00:00:00 2001 From: "arturo.jimenez" Date: Wed, 10 Jan 2024 15:08:03 +0100 Subject: [PATCH 5/5] SCMI-112253 I just wrote the opposite of what I wanted --- leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt index 22375f06..10064c28 100644 --- a/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt +++ b/leku/src/main/java/com/adevinta/leku/LocationPickerActivity.kt @@ -1213,7 +1213,7 @@ class LocationPickerActivity : } private fun setDefaultLocation() { - if (PermissionUtils.isLocationPermissionGranted(applicationContext)) { + if (!PermissionUtils.isLocationPermissionGranted(applicationContext)) { currentLocation = Location(getString(R.string.leku_network_resource)) currentLocation?.latitude = 0.0 currentLocation?.longitude = 0.0