mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-07 14:16:28 -04:00
Merge pull request #395 from meshtastic/refactor-protos
use locationShareDisabled boolean
This commit is contained in:
@@ -132,22 +132,13 @@ class UIViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
var locationShare: Boolean?
|
||||
get() {
|
||||
return radioConfig.value?.preferences?.locationShare == RadioConfigProtos.LocationSharing.LocEnabled
|
||||
|| radioConfig.value?.preferences?.locationShare == RadioConfigProtos.LocationSharing.LocUnset
|
||||
}
|
||||
set(value) {
|
||||
var locationShareDisabled: Boolean
|
||||
get() = radioConfig.value?.preferences?.locationShareDisabled ?: false
|
||||
set(value) {
|
||||
val config = radioConfig.value
|
||||
if (value != null && config != null) {
|
||||
if (config != null) {
|
||||
val builder = config.toBuilder()
|
||||
if (value == true) {
|
||||
builder.preferencesBuilder.locationShare =
|
||||
RadioConfigProtos.LocationSharing.LocUnset
|
||||
} else {
|
||||
builder.preferencesBuilder.locationShare =
|
||||
RadioConfigProtos.LocationSharing.LocDisabled
|
||||
}
|
||||
builder.preferencesBuilder.locationShareDisabled = value
|
||||
setRadioConfig(builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,7 +1017,7 @@ class MeshService : Service(), Logging {
|
||||
else
|
||||
broadcastSecs * 1000L
|
||||
|
||||
if (prefs.locationShare == RadioConfigProtos.LocationSharing.LocDisabled) {
|
||||
if (prefs.locationShareDisabled) {
|
||||
info("GPS location sharing is disabled")
|
||||
desiredInterval = 0
|
||||
}
|
||||
|
||||
@@ -37,24 +37,24 @@ 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.positionBroadcastPeriodView.isEnabled = model.locationShare ?: true
|
||||
binding.positionBroadcastSwitch.isChecked = model.locationShare ?: true
|
||||
binding.positionBroadcastPeriodView.isEnabled = !model.locationShareDisabled
|
||||
binding.positionBroadcastSwitch.isChecked = !model.locationShareDisabled
|
||||
binding.lsSleepView.isEnabled = model.isPowerSaving ?: false
|
||||
binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false
|
||||
binding.isAlwaysPoweredSwitch.isChecked = model.isAlwaysPowered ?: false
|
||||
})
|
||||
}
|
||||
|
||||
model.isConnected.observe(viewLifecycleOwner, { connectionState ->
|
||||
model.isConnected.observe(viewLifecycleOwner) { connectionState ->
|
||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||
binding.positionBroadcastPeriodView.isEnabled = connected && model.locationShare ?: true
|
||||
binding.positionBroadcastPeriodView.isEnabled = connected && !model.locationShareDisabled
|
||||
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) {
|
||||
val textEdit = binding.positionBroadcastPeriodEditText
|
||||
@@ -83,7 +83,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
||||
|
||||
binding.positionBroadcastSwitch.setOnCheckedChangeListener { view, isChecked ->
|
||||
if (view.isPressed) {
|
||||
model.locationShare = isChecked
|
||||
model.locationShareDisabled = !isChecked
|
||||
debug("User changed locationShare to $isChecked")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,8 +656,8 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||
|
||||
model.radioConfig.observe(viewLifecycleOwner) {
|
||||
binding.provideLocationCheckbox.isEnabled =
|
||||
isGooglePlayAvailable(requireContext()) && model.locationShare ?: true
|
||||
if (model.locationShare == false) {
|
||||
isGooglePlayAvailable(requireContext()) && !model.locationShareDisabled
|
||||
if (model.locationShareDisabled) {
|
||||
model.provideLocation.value = false
|
||||
binding.provideLocationCheckbox.isChecked = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user