mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(connections): Connecting state refactor (#3722)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
12ccb34553
commit
73d933fe14
22 changed files with 379 additions and 263 deletions
|
|
@ -17,17 +17,24 @@
|
|||
|
||||
package org.meshtastic.core.service
|
||||
|
||||
enum class ConnectionState {
|
||||
sealed class ConnectionState {
|
||||
/** We are disconnected from the device, and we should be trying to reconnect. */
|
||||
DISCONNECTED,
|
||||
data object Disconnected : ConnectionState()
|
||||
|
||||
/** We are currently attempting to connect to the device. */
|
||||
data object Connecting : ConnectionState()
|
||||
|
||||
/** We are connected to the device and communicating normally. */
|
||||
CONNECTED,
|
||||
data object Connected : ConnectionState()
|
||||
|
||||
/** The device is in a light sleep state, and we are waiting for it to wake up and reconnect to us. */
|
||||
DEVICE_SLEEP,
|
||||
data object DeviceSleep : ConnectionState()
|
||||
|
||||
;
|
||||
fun isConnected() = this == Connected
|
||||
|
||||
fun isConnected() = this != DISCONNECTED
|
||||
fun isConnecting() = this == Connecting
|
||||
|
||||
fun isDisconnected() = this == Disconnected
|
||||
|
||||
fun isDeviceSleep() = this == DeviceSleep
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class ServiceRepository @Inject constructor() {
|
|||
}
|
||||
|
||||
// Connection state to our radio device
|
||||
private val _connectionState = MutableStateFlow(ConnectionState.DISCONNECTED)
|
||||
private val _connectionState: MutableStateFlow<ConnectionState> = MutableStateFlow(ConnectionState.Disconnected)
|
||||
val connectionState: StateFlow<ConnectionState>
|
||||
get() = _connectionState
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class ServiceRepository @Inject constructor() {
|
|||
get() = _statusMessage
|
||||
|
||||
fun setStatusMessage(text: String) {
|
||||
if (connectionState.value != ConnectionState.CONNECTED) {
|
||||
if (connectionState.value != ConnectionState.Connected) {
|
||||
_statusMessage.value = text
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@
|
|||
<string name="connection_status">Current connections:</string>
|
||||
<string name="wifi_ip">Wifi IP:</string>
|
||||
<string name="ethernet_ip">Ethernet IP:</string>
|
||||
<string name="connecting">Connecting</string>
|
||||
<string name="not_connected">Not connected</string>
|
||||
<string name="connected_sleeping">Connected to radio, but it is sleeping</string>
|
||||
<string name="app_too_old">Application update required</string>
|
||||
|
|
@ -953,4 +954,5 @@
|
|||
<string name="unset">Unset - 0</string>
|
||||
<string name="relayed_by">Relayed by: %1$s</string>
|
||||
<string name="preserve_favorites">Preserve Favorites?</string>
|
||||
<string name="usb_devices">USB Devices</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue