summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt26
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt45
-rw-r--r--app/src/main/res/layout/fragment_fake_location.xml108
3 files changed, 87 insertions, 92 deletions
diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt
index 2a69b3a..581df09 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt
@@ -60,7 +60,7 @@ class FakeLocationStateUseCase(
init {
coroutineScope.launch {
localStateRepository.fakeLocationEnabled.collect {
- applySettings(it, localStateRepository.fakeLocation)
+ applySettings(it, it)
}
}
}
@@ -73,12 +73,16 @@ class FakeLocationStateUseCase(
permissionsModule.toggleDangerousPermission(appDesc, android.Manifest.permission.ACCESS_FINE_LOCATION, true)
}
- private fun applySettings(isEnabled: Boolean, fakeLocation: Pair<Float, Float>, isSpecificLocation: Boolean = false) {
- _configuredLocationMode.value = computeLocationMode(isEnabled, fakeLocation, isSpecificLocation)
+ private fun applySettings(isEnabled: Boolean, isSpecificLocation: Boolean = false) {
+ _configuredLocationMode.value = computeLocationMode(isEnabled, localStateRepository.fakeAltitude, localStateRepository.fakeSpeed, localStateRepository.fakeJitter, localStateRepository.fakeLocation, isSpecificLocation)
if (isEnabled && hasAcquireMockLocationPermission()) {
fakeLocationModule.startFakeLocation()
- fakeLocationModule.setFakeLocation(localStateRepository.fakeAltitude.toDouble(), localStateRepository.fakeSpeed, localStateRepository.fakeJitter, fakeLocation.first.toDouble(), fakeLocation.second.toDouble())
+ fakeLocationModule.setFakeLocation(localStateRepository.fakeAltitude.toDouble(),
+ localStateRepository.fakeSpeed,
+ localStateRepository.fakeJitter,
+ localStateRepository.fakeLocation.first.toDouble(),
+ localStateRepository.fakeLocation.second.toDouble())
localStateRepository.locationMode.value = configuredLocationMode.value.mode
} else {
fakeLocationModule.stopFakeLocation()
@@ -95,6 +99,7 @@ class FakeLocationStateUseCase(
localStateRepository.fakeAltitude = altitude
localStateRepository.fakeSpeed = speed
localStateRepository.fakeJitter = jitter
+ applySettings(localStateRepository.fakeLocationEnabled.value, localStateRepository.fakeLocationEnabled.value)
}
fun setSpecificLocation(latitude: Float, longitude: Float) {
@@ -111,16 +116,19 @@ class FakeLocationStateUseCase(
private fun setFakeLocation(location: Pair<Float, Float>, isSpecificLocation: Boolean = false) {
localStateRepository.fakeLocation = location
localStateRepository.setFakeLocationEnabled(true)
- applySettings(true, location, isSpecificLocation)
+ applySettings(true, isSpecificLocation)
}
fun stopFakeLocation() {
localStateRepository.setFakeLocationEnabled(false)
- applySettings(false, localStateRepository.fakeLocation)
+ applySettings(false, false)
}
private fun computeLocationMode(
isFakeLocationEnabled: Boolean,
+ altitude: Float,
+ speed: Float,
+ jitter: Float,
fakeLocation: Pair<Float, Float>,
isSpecificLocation: Boolean = false,
): FakeLocationState {
@@ -132,9 +140,9 @@ class FakeLocationStateUseCase(
else -> LocationMode.SPECIFIC_LOCATION
},
null,
- null,
- null,
- null,
+ altitude,
+ speed,
+ jitter,
false,
fakeLocation.first,
fakeLocation.second,
diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt
index 2ba8613..e31f21d 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/features/location/FakeLocationFragment.kt
@@ -246,13 +246,17 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location)
}
private fun updateMockLocationParameters() {
- viewModel.submitAction(
- Action.UpdateMockLocationParameters(
- binding.altitude.text.toString().toFloat(),
- binding.speed.text.toString().toFloat(),
- binding.jitter.text.toString().toFloat(),
+ try {
+ viewModel.submitAction(
+ Action.UpdateMockLocationParameters(
+ binding.edittextAltitude.text.toString().toFloat(),
+ binding.edittextSpeed.text.toString().toFloat(),
+ binding.edittextJitter.text.toString().toFloat(),
+ )
)
- )
+ } catch (e: NumberFormatException) {
+ Timber.e("Unfiltered wrong altitude/speed/jitter format")
+ }
}
@Suppress("UNUSED_PARAMETER")
@@ -292,7 +296,7 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location)
private val latLonOnFocusChangeListener = object : View.OnFocusChangeListener {
override fun onFocusChange(v: View?, hasFocus: Boolean) {
- if (!isEditingLatLon) {
+ if (!isEditingLatLon && !binding.edittextAltitude.isFocused && !binding.edittextSpeed.isFocused && !binding.edittextJitter.isFocused) {
(context?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager)?.hideSoftInputFromWindow(
v?.windowToken,
0
@@ -317,11 +321,14 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location)
}
}
- binding.altitude.addTextChangedListener(afterTextChanged = ::onAltitudeTextChanged)
- binding.speed.addTextChangedListener(afterTextChanged = ::onSpeedTextChanged)
- binding.jitter.addTextChangedListener(afterTextChanged = ::onJitterTextChanged)
+ binding.edittextAltitude.addTextChangedListener(afterTextChanged = ::onAltitudeTextChanged)
+ binding.edittextSpeed.addTextChangedListener(afterTextChanged = ::onSpeedTextChanged)
+ binding.edittextJitter.addTextChangedListener(afterTextChanged = ::onJitterTextChanged)
binding.edittextLatitude.addTextChangedListener(afterTextChanged = ::onLatTextChanged)
binding.edittextLongitude.addTextChangedListener(afterTextChanged = ::onLonTextChanged)
+ binding.edittextAltitude.onFocusChangeListener = latLonOnFocusChangeListener
+ binding.edittextSpeed.onFocusChangeListener = latLonOnFocusChangeListener
+ binding.edittextJitter.onFocusChangeListener = latLonOnFocusChangeListener
binding.edittextLatitude.onFocusChangeListener = latLonOnFocusChangeListener
binding.edittextLongitude.onFocusChangeListener = latLonOnFocusChangeListener
}
@@ -336,18 +343,18 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location)
binding.mapView.isEnabled = (state.mode == LocationMode.SPECIFIC_LOCATION)
- binding.altitude.isEnabled = state.mode == LocationMode.SPECIFIC_LOCATION
- binding.speed.isEnabled = state.mode == LocationMode.SPECIFIC_LOCATION
- binding.jitter.isEnabled = state.mode == LocationMode.SPECIFIC_LOCATION
+ binding.textlayoutAltitude.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION
+ binding.textlayoutSpeed.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION
+ binding.textlayoutJitter.isVisible = state.mode == LocationMode.SPECIFIC_LOCATION
- if(!binding.altitude.isFocused)
- binding.altitude.setText(state.altitude?.toString())
+ if(!binding.edittextAltitude.isFocused)
+ binding.edittextAltitude.setText(state.altitude?.toString())
- if(!binding.speed.isFocused)
- binding.speed.setText(state.speed?.toString())
+ if(!binding.edittextSpeed.isFocused)
+ binding.edittextSpeed.setText(state.speed?.toString())
- if(!binding.jitter.isFocused)
- binding.jitter.setText(state.jitter?.toString())
+ if(!binding.edittextJitter.isFocused)
+ binding.edittextJitter.setText(state.jitter?.toString())
if (state.mode == LocationMode.REAL_LOCATION) {
binding.centeredMarker.isVisible = false
diff --git a/app/src/main/res/layout/fragment_fake_location.xml b/app/src/main/res/layout/fragment_fake_location.xml
index 5483bc2..7890edc 100644
--- a/app/src/main/res/layout/fragment_fake_location.xml
+++ b/app/src/main/res/layout/fragment_fake_location.xml
@@ -84,84 +84,63 @@
/>
</RadioGroup>
- <LinearLayout
- android:layout_height="match_parent"
- android:padding="16dp"
+ <com.google.android.material.textfield.TextInputLayout
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+ android:id="@+id/textlayout_altitude"
+ android:hint="@string/location_altitude"
+ android:layout_height="wrap_content"
android:layout_width="match_parent"
- android:orientation="horizontal"
- tools:context=".main.MainActivity"
+ android:layout_marginTop="16dp"
+ app:endIconDrawable="@drawable/ic_valid"
+ app:endIconMode="custom"
+ app:endIconTint="@color/green_valid"
>
-
- <TextView
- android:id="@+id/fake_location_info_altitude"
- android:layout_gravity="center_horizontal"
- android:layout_height="wrap_content"
- android:layout_width="0dp"
- android:text="@string/location_altitude"
- android:lineSpacingExtra="5sp"
- />
-
- <EditText
- android:id="@+id/altitude"
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/edittext_altitude"
android:inputType="numberDecimal"
- android:layout_width="wrap_content"
- android:layout_height="24dp"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
/>
+ </com.google.android.material.textfield.TextInputLayout>
- </LinearLayout>
-
- <LinearLayout
- android:layout_height="match_parent"
- android:padding="16dp"
+ <com.google.android.material.textfield.TextInputLayout
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+ android:id="@+id/textlayout_speed"
+ android:hint="@string/location_speed"
+ android:layout_height="wrap_content"
android:layout_width="match_parent"
- android:orientation="horizontal"
- tools:context=".main.MainActivity"
+ android:layout_marginTop="16dp"
+ app:endIconDrawable="@drawable/ic_valid"
+ app:endIconMode="custom"
+ app:endIconTint="@color/green_valid"
>
-
- <TextView
- android:id="@+id/fake_location_info_speed"
- android:layout_gravity="center_horizontal"
- android:layout_height="wrap_content"
- android:layout_width="0dp"
- android:text="@string/location_speed"
- android:lineSpacingExtra="5sp"
- />
-
- <EditText
- android:id="@+id/speed"
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/edittext_speed"
android:inputType="numberDecimal"
- android:layout_width="wrap_content"
- android:layout_height="24dp"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
/>
+ </com.google.android.material.textfield.TextInputLayout>
- </LinearLayout>
-
- <LinearLayout
- android:layout_height="match_parent"
- android:padding="16dp"
+ <com.google.android.material.textfield.TextInputLayout
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+ android:id="@+id/textlayout_jitter"
+ android:hint="@string/location_jitter"
+ android:layout_height="wrap_content"
android:layout_width="match_parent"
- android:orientation="horizontal"
- tools:context=".main.MainActivity"
+ android:layout_marginTop="16dp"
+ app:endIconDrawable="@drawable/ic_valid"
+ app:endIconMode="custom"
+ app:endIconTint="@color/green_valid"
>
-
- <TextView
- android:id="@+id/fake_location_info_jitter"
- android:layout_gravity="center_horizontal"
- android:layout_height="wrap_content"
- android:layout_width="0dp"
- android:text="@string/location_jitter"
- android:lineSpacingExtra="5sp"
- />
-
- <EditText
- android:id="@+id/jitter"
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/edittext_jitter"
android:inputType="numberDecimal"
- android:layout_width="wrap_content"
- android:layout_height="24dp"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
/>
-
- </LinearLayout>
-
+ </com.google.android.material.textfield.TextInputLayout>
+<!--
<LinearLayout
android:layout_height="match_parent"
android:padding="16dp"
@@ -187,6 +166,7 @@
/>
</LinearLayout>
+-->
<FrameLayout
android:layout_marginTop="16dp"