Clean up Connections UI, fix some friction with Bluetooth (#2807)

This commit is contained in:
Phil Oliver 2025-08-22 14:33:11 -04:00 committed by GitHub
parent 268be3e4f9
commit 2d5e73c410
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 981 additions and 678 deletions

View file

@ -92,8 +92,6 @@ sealed class DeviceListEntry(open val name: String, open val fullAddress: String
data class Tcp(override val name: String, override val fullAddress: String) :
DeviceListEntry(name, fullAddress, true)
data class Disconnect(override val name: String) : DeviceListEntry(name, NO_DEVICE_SELECTED, true)
data class Mock(override val name: String) : DeviceListEntry(name, "m", true)
}
@ -168,18 +166,10 @@ constructor(
.map { usb -> usb.map { (_, d) -> DeviceListEntry.Usb(radioInterfaceService, usbManagerLazy.get(), d) } }
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
val disconnectDevice = DeviceListEntry.Disconnect(context.getString(R.string.none))
val mockDevice = DeviceListEntry.Mock("Demo Mode")
val bleDevicesForUi: StateFlow<List<DeviceListEntry>> =
bleDevicesFlow
.map { devices -> listOf(disconnectDevice) + devices }
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(SHARING_STARTED_TIMEOUT_MS),
listOf(disconnectDevice),
)
bleDevicesFlow.stateIn(viewModelScope, SharingStarted.WhileSubscribed(SHARING_STARTED_TIMEOUT_MS), emptyList())
/** UI StateFlow for discovered TCP devices. */
val discoveredTcpDevicesForUi: StateFlow<List<DeviceListEntry>> =
@ -199,12 +189,12 @@ constructor(
val usbDevicesForUi: StateFlow<List<DeviceListEntry>> =
combine(usbDevicesFlow, showMockInterface) { usb, showMock ->
listOf(disconnectDevice) + usb + if (showMock) listOf(mockDevice) else emptyList()
usb + if (showMock) listOf(mockDevice) else emptyList()
}
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(SHARING_STARTED_TIMEOUT_MS),
listOf(disconnectDevice),
if (showMockInterface.value) listOf(mockDevice) else emptyList(),
)
init {
@ -379,15 +369,17 @@ constructor(
true
}
is DeviceListEntry.Disconnect,
is DeviceListEntry.Mock,
-> {
is DeviceListEntry.Mock -> {
changeDeviceAddress(it.fullAddress)
true
}
}
}
fun disconnect() {
changeDeviceAddress(NO_DEVICE_SELECTED)
}
private val _spinner = MutableStateFlow(false)
val spinner: StateFlow<Boolean>
get() = _spinner.asStateFlow()