summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorTheScarastic <warabhishek@e.email>2022-04-20 20:22:44 +0530
committerTheScarastic <warabhishek@e.email>2022-04-21 12:09:37 +0530
commit449a87dd92fae4410425515d8191d3be3e3b3938 (patch)
tree636a42d876f6115836ea05bb45e2708f73528147 /app/src/main
parent5658347ab0099c4f512e19a3807d38758396114a (diff)
privacycentralapp: Restore location when view is created
* Fix cordinates for chicago and madrid * Also allow negative cordinates since its possible ;)
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/data/repositories/CityDataSource.kt4
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt26
-rw-r--r--app/src/main/res/layout/fragment_fake_location.xml4
3 files changed, 24 insertions, 10 deletions
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<FakeLocationFeature.State, Action> {
- 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
+ )
)
)
}
diff --git a/app/src/main/res/layout/fragment_fake_location.xml b/app/src/main/res/layout/fragment_fake_location.xml
index 065d222..64432cb 100644
--- a/app/src/main/res/layout/fragment_fake_location.xml
+++ b/app/src/main/res/layout/fragment_fake_location.xml
@@ -117,7 +117,7 @@
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edittext_longitude"
- android:inputType="numberDecimal"
+ android:inputType="numberDecimal|numberSigned"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
@@ -136,7 +136,7 @@
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edittext_latitude"
- android:inputType="numberDecimal"
+ android:inputType="numberDecimal|numberSigned"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>