From 449a87dd92fae4410425515d8191d3be3e3b3938 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Wed, 20 Apr 2022 20:22:44 +0530 Subject: privacycentralapp: Restore location when view is created * Fix cordinates for chicago and madrid * Also allow negative cordinates since its possible ;) --- .../data/repositories/CityDataSource.kt | 4 ++-- .../features/location/FakeLocationFragment.kt | 26 +++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/CityDataSource.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/CityDataSource.kt index 5fab9b7..d6a6a19 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/CityDataSource.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/CityDataSource.kt @@ -26,9 +26,9 @@ object CityDataSource { private val PARIS = Pair(48.8566f, 2.3522f) private val LONDON = Pair(51.5074f, 0.1278f) private val SHANGHAI = Pair(31.2304f, 121.4737f) - private val MADRID = Pair(40.4168f, 3.7038f) + private val MADRID = Pair(40.4168f, -3.7038f) private val LAHORE = Pair(31.5204f, 74.3587f) - private val CHICAGO = Pair(41.8781f, 87.6298f) + private val CHICAGO = Pair(41.8781f, -87.6298f) val citiesLocationsList = listOf( BARCELONA, diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt index 6821a33..bc35521 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt @@ -63,7 +63,7 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location), MVIView { - private var isCameraMoved: Boolean = false + private var isFirstLaunch: Boolean = true private val dependencyContainer: DependencyContainer by lazy { (this.requireActivity().application as PrivacyCentralApplication).dependencyContainer @@ -96,8 +96,20 @@ class FakeLocationFragment : is FakeLocationFeature.SingleEvent.ErrorEvent -> { displayToast(event.error) } - is FakeLocationFeature.SingleEvent.LocationUpdatedEvent -> + is FakeLocationFeature.SingleEvent.LocationUpdatedEvent -> { + if (isFirstLaunch && mapboxMap != null) { + mapboxMap?.moveCamera( + CameraUpdateFactory.newLatLng( + LatLng( + event.location?.latitude ?: 0.0, + event.location?.longitude ?: 0.0 + ) + ) + ) + isFirstLaunch = false + } updateLocation(event.location) + } } } } @@ -121,7 +133,7 @@ class FakeLocationFragment : binding.mapView.setup(savedInstanceState) { mapboxMap -> this.mapboxMap = mapboxMap - mapboxMap.getUiSettings().isRotateGesturesEnabled = false + mapboxMap.uiSettings.isRotateGesturesEnabled = false mapboxMap.setStyle(Style.MAPBOX_STREETS) { style -> enableLocationPlugin(style) @@ -149,7 +161,7 @@ class FakeLocationFragment : isLat: Boolean ) = { editable: Editable? -> inputJob?.cancel() - if (editable != null && editable.length > 0 && editText.isEnabled) { + if (editable != null && editable.isNotEmpty() && editText.isEnabled) { inputJob = lifecycleScope.launch { delay(DEBOUNCE_PERIOD) ensureActive() @@ -238,7 +250,6 @@ class FakeLocationFragment : binding.mapView.isEnabled = (state.mode == LocationMode.SPECIFIC_LOCATION) if (state.mode != LocationMode.SPECIFIC_LOCATION) { - isCameraMoved = false binding.centeredMarker.isVisible = false } else { binding.mapLoader.isVisible = false @@ -247,7 +258,10 @@ class FakeLocationFragment : mapboxMap?.moveCamera( CameraUpdateFactory.newLatLng( - LatLng(state.specificLatitude?.toDouble() ?: 0.0, state.specificLongitude?.toDouble() ?: 0.0) + LatLng( + state.specificLatitude?.toDouble() ?: 0.0, + state.specificLongitude?.toDouble() ?: 0.0 + ) ) ) } -- cgit v1.2.1