diff --git a/app/src/main/java/com/geeksville/mesh/model/UIState.kt b/app/src/main/java/com/geeksville/mesh/model/UIState.kt
index 66ea6ff1c..708251753 100644
--- a/app/src/main/java/com/geeksville/mesh/model/UIState.kt
+++ b/app/src/main/java/com/geeksville/mesh/model/UIState.kt
@@ -21,7 +21,6 @@ import com.geeksville.mesh.database.entity.Packet
import com.geeksville.mesh.service.MeshService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
-import kotlin.math.max
/// Given a human name, strip out the first letter of the first three words and return that as the initials for
/// that user. If the original name is only one word, strip vowels from the original name and if the result is
@@ -36,7 +35,7 @@ fun getInitials(nameIn: String): String {
val initials = when (words.size) {
in 0..minchars - 1 -> {
val nm = if (name.length >= 1)
- name.first() + name.drop(1).filterNot { c -> c.toLowerCase() in "aeiou" }
+ name.first() + name.drop(1).filterNot { c -> c.lowercase() in "aeiou" }
else
""
if (nm.length >= nchars) nm else name
@@ -98,7 +97,6 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
var positionBroadcastSecs: Int?
get() {
radioConfig.value?.preferences?.let {
- if (it.locationShare == RadioConfigProtos.LocationSharing.LocDisabled) return 0
if (it.positionBroadcastSecs > 0) return it.positionBroadcastSecs
// These default values are borrowed from the device code.
if (it.isRouter) return 60 * 60
@@ -110,17 +108,7 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
val config = radioConfig.value
if (value != null && config != null) {
val builder = config.toBuilder()
- if (value > 0) {
- builder.preferencesBuilder.positionBroadcastSecs = value
- builder.preferencesBuilder.gpsUpdateInterval = value
- builder.preferencesBuilder.sendOwnerInterval = max(1, 3600 / value).toInt()
- builder.preferencesBuilder.locationShare =
- RadioConfigProtos.LocationSharing.LocEnabled
- } else {
- builder.preferencesBuilder.positionBroadcastSecs = Int.MAX_VALUE
- builder.preferencesBuilder.locationShare =
- RadioConfigProtos.LocationSharing.LocDisabled
- }
+ builder.preferencesBuilder.positionBroadcastSecs = value
setRadioConfig(builder.build())
}
}
@@ -136,6 +124,36 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
}
}
+ var locationShare: Boolean?
+ get() {
+ return radioConfig.value?.preferences?.locationShare == RadioConfigProtos.LocationSharing.LocEnabled
+ }
+ set(value) {
+ val config = radioConfig.value
+ if (value != null && config != null) {
+ val builder = config.toBuilder()
+ if (value == true) {
+ builder.preferencesBuilder.locationShare =
+ RadioConfigProtos.LocationSharing.LocEnabled
+ } else {
+ builder.preferencesBuilder.locationShare =
+ RadioConfigProtos.LocationSharing.LocDisabled
+ }
+ setRadioConfig(builder.build())
+ }
+ }
+
+ var isPowerSaving: Boolean?
+ get() = radioConfig.value?.preferences?.isPowerSaving
+ set(value) {
+ val config = radioConfig.value
+ if (value != null && config != null) {
+ val builder = config.toBuilder()
+ builder.preferencesBuilder.isPowerSaving = value
+ setRadioConfig(builder.build())
+ }
+ }
+
var isAlwaysPowered: Boolean?
get() = radioConfig.value?.preferences?.isAlwaysPowered
set(value) {
diff --git a/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt
index f3485e999..16881c2e4 100644
--- a/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt
+++ b/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt
@@ -36,17 +36,22 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- model.radioConfig.observe(viewLifecycleOwner, { _ ->
+ model.radioConfig.observe(viewLifecycleOwner, {
binding.positionBroadcastPeriodEditText.setText(model.positionBroadcastSecs.toString())
binding.lsSleepEditText.setText(model.lsSleepSecs.toString())
- binding.isAlwaysPoweredCheckbox.isChecked = model.isAlwaysPowered?: false
+ binding.positionBroadcastSwitch.isChecked = model.locationShare ?: true
+ binding.lsSleepView.isEnabled = model.isPowerSaving ?: false
+ binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false
+ binding.isAlwaysPoweredSwitch.isChecked = model.isAlwaysPowered ?: false
})
- model.isConnected.observe(viewLifecycleOwner, Observer { connectionState ->
+ model.isConnected.observe(viewLifecycleOwner, { connectionState ->
val connected = connectionState == MeshService.ConnectionState.CONNECTED
binding.positionBroadcastPeriodView.isEnabled = connected
- binding.lsSleepView.isEnabled = connected
- binding.isAlwaysPoweredCheckbox.isEnabled = connected
+ binding.lsSleepView.isEnabled = connected && model.isPowerSaving ?: false
+ binding.positionBroadcastSwitch.isEnabled = connected
+ binding.lsSleepSwitch.isEnabled = connected
+ binding.isAlwaysPoweredSwitch.isEnabled = connected
})
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
@@ -74,6 +79,14 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
requireActivity().hideKeyboard()
}
+ binding.positionBroadcastSwitch.setOnCheckedChangeListener { view, isChecked ->
+ if (view.isPressed) {
+ model.locationShare = isChecked
+ debug("User changed locationShare to $isChecked")
+ }
+ }
+
+ // 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()
@@ -87,7 +100,14 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
requireActivity().hideKeyboard()
}
- binding.isAlwaysPoweredCheckbox.setOnCheckedChangeListener { view, isChecked ->
+ binding.lsSleepSwitch.setOnCheckedChangeListener { view, isChecked ->
+ if (view.isPressed) {
+ model.isPowerSaving = isChecked
+ debug("User changed isPowerSaving to $isChecked")
+ }
+ }
+
+ binding.isAlwaysPoweredSwitch.setOnCheckedChangeListener { view, isChecked ->
if (view.isPressed) {
model.isAlwaysPowered = isChecked
debug("User changed isAlwaysPowered to $isChecked")
diff --git a/app/src/main/res/layout/advanced_settings.xml b/app/src/main/res/layout/advanced_settings.xml
index 673625c9e..26ae6948e 100644
--- a/app/src/main/res/layout/advanced_settings.xml
+++ b/app/src/main/res/layout/advanced_settings.xml
@@ -27,6 +27,15 @@
android:singleLine="true" />
+
+
-
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index c57c57e63..84aaee0ff 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -75,7 +75,7 @@
tiempo de recepción del mensaje
estado de recepción de mensajes
Estado de entrega del mensaje
- Periodo de emisión de la posición (en segundos) 0 - deshabilitar
+ Periodo de emisión de la posición (en segundos)
Período de reposo del dispositivo (en segundos)
Notificaciones de mensajes
El periodo mínimo de emisión de este canal es %d
diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml
index 3e0e815c9..d785d78f3 100644
--- a/app/src/main/res/values-hu/strings.xml
+++ b/app/src/main/res/values-hu/strings.xml
@@ -78,7 +78,7 @@
üzenet fogadásának ideje
üzenet fogadásának állapota
Üzenet kézbesítésének állapota
- Pozíció hírdetésének gyakorisága (másodpercben), 0 - letiltva
+ Pozíció hírdetésének gyakorisága (másodpercben)
Eszköz alvásának gyakorisága (másodpercben)
Értesítések az üzenetekről
Minimum üzenet küldési gyakoriság ezen a csatornán %d
diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index ceba55d56..d8a523045 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -84,7 +84,7 @@
Czas odbioru wiadomości
Status odbioru wiadomości
Status dostarczenia wiadomości
- Rozgłaszanie pozycji co: (w sekundach), 0 - wyłączone
+ Rozgłaszanie pozycji co: (w sekundach)
Uśpienie urządzenia (w sekundach)
Powiadomienie o wiadomościach
Minimalny okres rozgłaszania dla tego kanału wynosi %d
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 8ea7664dd..539762d77 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -79,8 +79,8 @@
tempo de recebimento de mensagem
estado de recebimento de mensagem
Status de entrega de mensagem
- Intervalo de localização (segundos), 0 - desabilitar
- Intervalo de suspensão (sleep) (segundos)
+ Intervalo de localização (em segundos)
+ Intervalo de suspensão (sleep) (em segundos)
Notificações sobre mensagens
Período mínimo de transmissão para este canal é %d
Stress test do protocolo
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index 1bc24438d..8c020a567 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -79,7 +79,7 @@
tempo de recebimento de mensagem
estado de recebimento de mensagem
Status de entrega de mensagem
- Intervalo de localização (segundos), 0 - desabilitar
+ Intervalo de localização (segundos)
Intervalo de suspensão (sleep) (segundos)
Notificações sobre mensagens
Período mínimo de transmissão para este canal é %d
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 658bbe6d7..a1ac842ce 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -79,7 +79,7 @@
消息接收时间
消息接收状态
消息传递状态
- 广播周期(以秒为单位),0为禁用
+ 广播周期(以秒为单位)
设备休眠时间(以秒为单位)
关于消息的通知
此频道的最短广播时间为 %d
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0e6dc375c..0c7eefa92 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -83,7 +83,7 @@
message reception time
message reception state
Message delivery status
- Broadcast position period (in seconds), 0 - disable
+ Broadcast position period (in seconds)
Device sleep period (in seconds)
Notifications about messages
Minimum broadcast period for this channel is %d