mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-04 22:23:47 -04:00
Merge pull request #352 from meshtastic/advanced
add is_power_saving to advanced settings
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user