rename isConnected --> connectionState

This commit is contained in:
andrekir 2022-04-24 12:12:13 -03:00
parent 5c75a54d46
commit 27c1817a59
6 changed files with 20 additions and 22 deletions

View file

@ -46,7 +46,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false
}
model.isConnected.observe(viewLifecycleOwner) { connectionState ->
model.connectionState.observe(viewLifecycleOwner) { connectionState ->
val connected = connectionState == MeshService.ConnectionState.CONNECTED
binding.positionBroadcastPeriodView.isEnabled = connected && !model.locationShareDisabled
binding.lsSleepView.isEnabled = connected && model.isPowerSaving ?: false

View file

@ -28,7 +28,6 @@ import com.geeksville.mesh.model.Channel
import com.geeksville.mesh.model.ChannelOption
import com.geeksville.mesh.model.ChannelSet
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.service.MeshService
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.protobuf.ByteString
@ -89,13 +88,13 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
private fun setGUIfromModel() {
val channels = model.channels.value
val channel = channels?.primaryChannel
val connected = model.isConnected.value == MeshService.ConnectionState.CONNECTED
val connected = model.isConnected()
// Only let buttons work if we are connected to the radio
binding.editableCheckbox.isChecked = false // start locked
onEditingChanged() // we just locked the gui
binding.shareButton.isEnabled = connected
binding.editableCheckbox.isChecked = false // start locked
if (channel != null) {
binding.qrView.visibility = View.VISIBLE
binding.channelNameEdit.visibility = View.VISIBLE
@ -123,7 +122,6 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
binding.editableCheckbox.isEnabled = false
}
onEditingChanged() // we just locked the gui
val modemConfigs = ChannelOption.values()
val modemConfigList = modemConfigs.map { getString(it.configRes) }
val adapter = ArrayAdapter(
@ -299,14 +297,14 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
shareChannel()
}
model.channels.observe(viewLifecycleOwner, {
model.channels.observe(viewLifecycleOwner) {
setGUIfromModel()
})
}
// If connection state changes, we might need to enable/disable buttons
model.isConnected.observe(viewLifecycleOwner, {
model.connectionState.observe(viewLifecycleOwner) {
setGUIfromModel()
})
}
}
private fun getModemConfig(selectedChannelOptionString: String): ChannelProtos.ChannelSettings.ModemConfig {

View file

@ -294,7 +294,7 @@ class MessagesFragment : Fragment(), Logging {
}
// If connection state _OR_ myID changes we have to fix our ability to edit outgoing messages
model.isConnected.observe(viewLifecycleOwner) { connectionState ->
model.connectionState.observe(viewLifecycleOwner) { connectionState ->
// If we don't know our node ID and we are offline don't let user try to send
val connected = connectionState == MeshService.ConnectionState.CONNECTED
binding.textInputLayout.isEnabled = connected

View file

@ -512,7 +512,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
debug("Reiniting the update button")
val info = model.myNodeInfo.value
val service = model.meshService
if (model.isConnected.value == MeshService.ConnectionState.CONNECTED && info != null && info.shouldUpdate && info.couldUpdate && service != null) {
if (model.isConnected() && info != null && info.shouldUpdate && info.couldUpdate && service != null) {
binding.updateFirmwareButton.visibility = View.VISIBLE
binding.updateFirmwareButton.text =
getString(R.string.update_to).format(getString(R.string.short_firmware_version))
@ -561,7 +561,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
* Pull the latest device info from the model and into the GUI
*/
private fun updateNodeInfo() {
val connected = model.isConnected.value
val connected = model.connectionState.value
val isConnected = connected == MeshService.ConnectionState.CONNECTED
binding.nodeSettings.visibility = if (isConnected) View.VISIBLE else View.GONE
@ -658,7 +658,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
}
// Only let user edit their name or set software update while connected to a radio
model.isConnected.observe(viewLifecycleOwner) {
model.connectionState.observe(viewLifecycleOwner) {
updateNodeInfo()
updateDevicesButtons(scanModel.devices.value)
}
@ -816,7 +816,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
)
addDeviceButton(
curDevice,
model.isConnected.value == MeshService.ConnectionState.CONNECTED
model.isConnected()
)
}
} else if (scanModel.selectedUSB != null) {