disable sleep prefs for non-ESP32 devices

This commit is contained in:
andrekir
2022-06-10 19:22:34 -03:00
parent bc6aae394b
commit 4784e8d14b
2 changed files with 15 additions and 8 deletions

View File

@@ -123,10 +123,9 @@ class UIViewModel @Inject constructor(
var positionBroadcastSecs: Int?
get() {
_deviceConfig.value?.position?.let {
if (it.positionBroadcastSecs > 0) return it.positionBroadcastSecs
_deviceConfig.value?.position?.positionBroadcastSecs?.let {
// These default values are borrowed from the device code.
return 15 * 60
return if (it > 0) it else 15 * 60 // default 900 sec
}
return null
}
@@ -140,7 +139,13 @@ class UIViewModel @Inject constructor(
}
var lsSleepSecs: Int?
get() = _deviceConfig.value?.power?.lsSecs
get() {
_deviceConfig.value?.power?.lsSecs?.let {
// These default values are borrowed from the device code.
return if (it > 0) return it else 5 * 60 // default 300 sec
}
return null
}
set(value) {
val config = _deviceConfig.value
if (value != null && config != null) {
@@ -179,6 +184,9 @@ class UIViewModel @Inject constructor(
meshService?.region = value.number
}
// We consider hasWifi = ESP32
var isESP32: Boolean = _deviceConfig.value?.hasWifi() == true
/// hardware info about our local device (can be null)
private val _myNodeInfo = MutableLiveData<MyNodeInfo?>()
val myNodeInfo: LiveData<MyNodeInfo?> get() = _myNodeInfo

View File

@@ -43,8 +43,8 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
binding.lsSleepEditText.setText(model.lsSleepSecs.toString())
binding.positionBroadcastPeriodView.isEnabled = !model.gpsDisabled
binding.positionBroadcastSwitch.isChecked = !model.gpsDisabled
binding.lsSleepView.isEnabled = model.isPowerSaving ?: false
binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false
binding.lsSleepView.isEnabled = model.isPowerSaving ?: false && model.isESP32
binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false && model.isESP32
}
model.connectionState.observe(viewLifecycleOwner) { connectionState ->
@@ -52,7 +52,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
binding.positionBroadcastPeriodView.isEnabled = connected && !model.gpsDisabled
binding.lsSleepView.isEnabled = connected && model.isPowerSaving ?: false
binding.positionBroadcastSwitch.isEnabled = connected
binding.lsSleepSwitch.isEnabled = connected
binding.lsSleepSwitch.isEnabled = connected && model.isESP32
binding.shutdownButton.isEnabled = connected
binding.rebootButton.isEnabled = connected
}
@@ -89,7 +89,6 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
}
}
// TODO - disable all sleep settings for non-ESP32 devices
binding.lsSleepEditText.on(EditorInfo.IME_ACTION_DONE) {
val str = binding.lsSleepEditText.text.toString()
val n = str.toIntOrNull()