Fix #55 - warn user if they have location disabled

pull/56/head
geeksville 2020-06-16 10:30:10 -07:00
rodzic 3cf7d97dcf
commit 03af1f1de7
2 zmienionych plików z 26 dodań i 6 usunięć

Wyświetl plik

@ -14,6 +14,7 @@ import android.companion.CompanionDeviceManager
import android.content.* import android.content.*
import android.hardware.usb.UsbDevice import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbManager import android.hardware.usb.UsbManager
import android.location.LocationManager
import android.os.Bundle import android.os.Bundle
import android.os.ParcelUuid import android.os.ParcelUuid
import android.view.LayoutInflater import android.view.LayoutInflater
@ -751,6 +752,15 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
scanModel.stopScan() scanModel.stopScan()
} }
/**
* Has the user _turned on_ the system setting for current location access.
*/
private fun isLocationEnabled(): Boolean {
val locManager =
requireContext().getSystemService(Context.LOCATION_SERVICE) as LocationManager
return locManager.isLocationEnabled
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (!hasCompanionDeviceApi) if (!hasCompanionDeviceApi)
@ -758,12 +768,21 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
// Keep reminding user BLE is still off // Keep reminding user BLE is still off
val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true
if (scanModel.bluetoothAdapter?.isEnabled != true && !hasUSB) { if (!hasUSB) {
Toast.makeText( // Warn user if BLE is disabled
requireContext(), if (scanModel.bluetoothAdapter?.isEnabled != true) {
R.string.error_bluetooth, Toast.makeText(
Toast.LENGTH_SHORT requireContext(),
).show() R.string.error_bluetooth,
Toast.LENGTH_SHORT
).show()
} else if (!isLocationEnabled()) {
Toast.makeText(
requireContext(),
getString(R.string.location_disabled_warning),
Toast.LENGTH_SHORT
).show()
}
} }
} }
} }

Wyświetl plik

@ -69,4 +69,5 @@
<string name="modem_config_very_long">Very long range (but slow)</string> <string name="modem_config_very_long">Very long range (but slow)</string>
<string name="modem_config_unrecognized">UNRECOGNIZED</string> <string name="modem_config_unrecognized">UNRECOGNIZED</string>
<string name="meshtastic_service_notifications">Meshtastic Service Notifications</string> <string name="meshtastic_service_notifications">Meshtastic Service Notifications</string>
<string name="location_disabled_warning">You must turn on location services in Android Settings</string>
</resources> </resources>