kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
add location only logic
rodzic
bb40672401
commit
e21f3fdf93
|
@ -41,6 +41,7 @@ import com.geeksville.android.GeeksvilleApplication
|
||||||
import com.geeksville.android.Logging
|
import com.geeksville.android.Logging
|
||||||
import com.geeksville.android.ServiceClient
|
import com.geeksville.android.ServiceClient
|
||||||
import com.geeksville.concurrent.handledLaunch
|
import com.geeksville.concurrent.handledLaunch
|
||||||
|
import com.geeksville.mesh.android.getLocationPermissions
|
||||||
import com.geeksville.mesh.android.getBackgroundPermissions
|
import com.geeksville.mesh.android.getBackgroundPermissions
|
||||||
import com.geeksville.mesh.android.getCameraPermissions
|
import com.geeksville.mesh.android.getCameraPermissions
|
||||||
import com.geeksville.mesh.android.getMissingPermissions
|
import com.geeksville.mesh.android.getMissingPermissions
|
||||||
|
@ -251,6 +252,9 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
/** Ask the user to grant camera permission */
|
/** Ask the user to grant camera permission */
|
||||||
fun requestCameraPermission() = requestPermission(getCameraPermissions(), false)
|
fun requestCameraPermission() = requestPermission(getCameraPermissions(), false)
|
||||||
|
|
||||||
|
/** Ask the user to grant foreground location permission */
|
||||||
|
fun requestLocationPermission() = requestPermission(getLocationPermissions(), false)
|
||||||
|
|
||||||
/** Ask the user to grant background location permission */
|
/** Ask the user to grant background location permission */
|
||||||
fun requestBackgroundPermission() = requestPermission(getBackgroundPermissions(), false)
|
fun requestBackgroundPermission() = requestPermission(getBackgroundPermissions(), false)
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,18 @@ fun Context.getCameraPermissions(): List<String> {
|
||||||
/** @return true if the user already has camera permission */
|
/** @return true if the user already has camera permission */
|
||||||
fun Context.hasCameraPermission() = getCameraPermissions().isEmpty()
|
fun Context.hasCameraPermission() = getCameraPermissions().isEmpty()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera permission (or empty if we already have what we need)
|
||||||
|
*/
|
||||||
|
fun Context.getLocationPermissions(): List<String> {
|
||||||
|
val perms = mutableListOf(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
|
|
||||||
|
return getMissingPermissions(perms)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return true if the user already has camera permission */
|
||||||
|
fun Context.hasLocationPermission() = getLocationPermissions().isEmpty()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of missing background location permissions (or empty if we already have what we need)
|
* A list of missing background location permissions (or empty if we already have what we need)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,6 +35,7 @@ import com.geeksville.mesh.MainActivity
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.RadioConfigProtos
|
import com.geeksville.mesh.RadioConfigProtos
|
||||||
import com.geeksville.mesh.android.bluetoothManager
|
import com.geeksville.mesh.android.bluetoothManager
|
||||||
|
import com.geeksville.mesh.android.hasLocationPermission
|
||||||
import com.geeksville.mesh.android.hasBackgroundPermission
|
import com.geeksville.mesh.android.hasBackgroundPermission
|
||||||
import com.geeksville.mesh.android.usbManager
|
import com.geeksville.mesh.android.usbManager
|
||||||
import com.geeksville.mesh.databinding.SettingsFragmentBinding
|
import com.geeksville.mesh.databinding.SettingsFragmentBinding
|
||||||
|
@ -656,14 +657,20 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
|
|
||||||
if (view.isPressed && isChecked) { // We want to ignore changes caused by code (as opposed to the user)
|
if (view.isPressed && isChecked) { // We want to ignore changes caused by code (as opposed to the user)
|
||||||
debug("User changed location tracking to $isChecked")
|
debug("User changed location tracking to $isChecked")
|
||||||
view.isChecked =
|
val hasLocationPermission = myActivity.hasLocationPermission()
|
||||||
myActivity.hasBackgroundPermission() // Don't check the box until the system setting changes
|
val hasBackgroundPermission = myActivity.hasBackgroundPermission()
|
||||||
if (!view.isChecked)
|
|
||||||
|
// Don't check the box until the system setting changes
|
||||||
|
view.isChecked = hasLocationPermission && hasBackgroundPermission
|
||||||
|
|
||||||
|
if (!hasLocationPermission) // Make sure we have location permission (prerequisite)
|
||||||
|
myActivity.requestLocationPermission()
|
||||||
|
if (hasLocationPermission && !hasBackgroundPermission)
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.background_required)
|
.setTitle(R.string.background_required)
|
||||||
.setMessage(R.string.why_background_required)
|
.setMessage(R.string.why_background_required)
|
||||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||||
debug("Decided not to report a bug")
|
debug("User denied background permission")
|
||||||
}
|
}
|
||||||
.setPositiveButton(getString(R.string.accept)) { _, _ ->
|
.setPositiveButton(getString(R.string.accept)) { _, _ ->
|
||||||
myActivity.requestBackgroundPermission()
|
myActivity.requestBackgroundPermission()
|
||||||
|
|
Ładowanie…
Reference in New Issue