kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
commit
638b681b4b
|
@ -451,7 +451,7 @@ class MainActivity : BaseActivity(), Logging,
|
|||
tab.icon = ContextCompat.getDrawable(this, tabInfos[position].icon)
|
||||
}.attach()
|
||||
|
||||
model.isConnected.observe(this) { connected ->
|
||||
model.connectionState.observe(this) { connected ->
|
||||
updateConnectionStatusImage(connected)
|
||||
}
|
||||
|
||||
|
@ -516,7 +516,7 @@ class MainActivity : BaseActivity(), Logging,
|
|||
requestedChannelUrl = appLinkData
|
||||
|
||||
// if the device is connected already, process it now
|
||||
if (model.isConnected.value == MeshService.ConnectionState.CONNECTED)
|
||||
if (model.isConnected())
|
||||
perhapsChangeChannel()
|
||||
|
||||
// We now wait for the device to connect, once connected, we ask the user if they want to switch to the new channel
|
||||
|
@ -629,7 +629,7 @@ class MainActivity : BaseActivity(), Logging,
|
|||
|
||||
/// Called when we gain/lose a connection to our mesh radio
|
||||
private fun onMeshConnectionChanged(newConnection: MeshService.ConnectionState) {
|
||||
val oldConnection = model.isConnected.value!!
|
||||
val oldConnection = model.connectionState.value!!
|
||||
debug("connchange $oldConnection -> $newConnection")
|
||||
|
||||
if (newConnection == MeshService.ConnectionState.CONNECTED) {
|
||||
|
@ -889,7 +889,7 @@ class MainActivity : BaseActivity(), Logging,
|
|||
connectionJob = null
|
||||
}
|
||||
|
||||
debug("connected to mesh service, isConnected=${model.isConnected.value}")
|
||||
debug("connected to mesh service, isConnected=${model.connectionState.value}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -983,7 +983,7 @@ class MainActivity : BaseActivity(), Logging,
|
|||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
model.actionBarMenu = menu
|
||||
|
||||
updateConnectionStatusImage(model.isConnected.value!!)
|
||||
updateConnectionStatusImage(model.connectionState.value!!)
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -92,9 +92,9 @@ class UIViewModel @Inject constructor(
|
|||
|
||||
/// Connection state to our radio device
|
||||
private val _connectionState = MutableLiveData(MeshService.ConnectionState.DISCONNECTED)
|
||||
val isConnected: LiveData<MeshService.ConnectionState> get() = _connectionState
|
||||
val connectionState: LiveData<MeshService.ConnectionState> get() = _connectionState
|
||||
|
||||
// fun isConnected() = _connectionState.value == MeshService.ConnectionState.CONNECTED
|
||||
fun isConnected() = _connectionState.value == MeshService.ConnectionState.CONNECTED
|
||||
|
||||
fun setConnectionState(connectionState: MeshService.ConnectionState) {
|
||||
_connectionState.value = connectionState
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Ładowanie…
Reference in New Issue