mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-07 08:44:24 +01:00
Fix toolbar title
This commit is contained in:
@@ -32,10 +32,11 @@
|
||||
package no.nordicsemi.android.uart.data
|
||||
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus
|
||||
|
||||
internal data class UARTServiceData(
|
||||
val messages: List<UARTRecord> = emptyList(),
|
||||
val connectionState: GattConnectionState? = null,
|
||||
val connectionState: GattConnectionStateWithStatus? = null,
|
||||
val batteryLevel: Int? = null,
|
||||
val deviceName: String? = null
|
||||
) {
|
||||
|
||||
@@ -40,6 +40,7 @@ import kotlinx.coroutines.flow.map
|
||||
import no.nordicsemi.android.common.core.simpleSharedFlow
|
||||
import no.nordicsemi.android.kotlin.ble.core.ServerDevice
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus
|
||||
import no.nordicsemi.android.service.DisconnectAndStopEvent
|
||||
import no.nordicsemi.android.service.OpenLoggerEvent
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
@@ -72,7 +73,7 @@ class UARTRepository @Inject internal constructor(
|
||||
private val _loggerEvent = simpleSharedFlow<OpenLoggerEvent>()
|
||||
internal val loggerEvent = _loggerEvent.asSharedFlow()
|
||||
|
||||
val isRunning = data.map { it.connectionState == GattConnectionState.STATE_CONNECTED }
|
||||
val isRunning = data.map { it.connectionState?.state == GattConnectionState.STATE_CONNECTED }
|
||||
|
||||
val lastConfigurationName = configurationDataSource.lastConfigurationName
|
||||
|
||||
@@ -80,7 +81,7 @@ class UARTRepository @Inject internal constructor(
|
||||
serviceManager.startService(UARTService::class.java, device)
|
||||
}
|
||||
|
||||
fun onConnectionStateChanged(connectionState: GattConnectionState) {
|
||||
fun onConnectionStateChanged(connectionState: GattConnectionStateWithStatus?) {
|
||||
_data.value = _data.value.copy(connectionState = connectionState)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import no.nordicsemi.android.kotlin.ble.core.ServerDevice
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleWriteType
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.Mtu
|
||||
import no.nordicsemi.android.kotlin.ble.profile.battery.BatteryLevelParser
|
||||
import no.nordicsemi.android.service.DEVICE_DATA
|
||||
@@ -100,7 +101,7 @@ internal class UARTService : NotificationService() {
|
||||
.onEach { logger.launch() }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
client.connectionState
|
||||
client.connectionStateWithStatus
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
@@ -148,8 +149,8 @@ internal class UARTService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopIfDisconnected(connectionState: GattConnectionState) {
|
||||
if (connectionState == GattConnectionState.STATE_DISCONNECTED) {
|
||||
private fun stopIfDisconnected(connectionState: GattConnectionStateWithStatus) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ import no.nordicsemi.android.uart.viewmodel.UARTViewModel
|
||||
import no.nordicsemi.android.ui.view.BackIconAppBar
|
||||
import no.nordicsemi.android.ui.view.LoggerIconAppBar
|
||||
import no.nordicsemi.android.ui.view.NavigateUpButton
|
||||
import no.nordicsemi.android.ui.view.ProfileAppBar
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -70,12 +71,21 @@ fun UARTScreen() {
|
||||
val navigateUp = { viewModel.onEvent(NavigateUp) }
|
||||
|
||||
Scaffold(
|
||||
topBar = { AppBar(state, navigateUp, viewModel) }
|
||||
topBar = {
|
||||
ProfileAppBar(
|
||||
deviceName = state.uartManagerState.deviceName,
|
||||
connectionState = state.uartManagerState.connectionState,
|
||||
title = R.string.uart_title,
|
||||
navigateUp = navigateUp,
|
||||
disconnect = { viewModel.onEvent(DisconnectEvent) },
|
||||
openLogger = { viewModel.onEvent(OpenLogger) }
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(it)
|
||||
) {
|
||||
when (state.uartManagerState.connectionState) {
|
||||
when (state.uartManagerState.connectionState?.state) {
|
||||
null,
|
||||
GattConnectionState.STATE_CONNECTING -> PaddingBox { DeviceConnectingView { NavigateUpButton(navigateUp) } }
|
||||
GattConnectionState.STATE_DISCONNECTED,
|
||||
@@ -95,18 +105,6 @@ private fun PaddingBox(content: @Composable () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AppBar(state: UARTViewState, navigateUp: () -> Unit, viewModel: UARTViewModel) {
|
||||
if (state.uartManagerState.deviceName?.isNotBlank() == true) {
|
||||
LoggerIconAppBar(state.uartManagerState.deviceName, navigateUp, { viewModel.onEvent(DisconnectEvent) }) {
|
||||
viewModel.onEvent(OpenLogger)
|
||||
}
|
||||
} else {
|
||||
BackIconAppBar(stringResource(id = R.string.uart_title), navigateUp)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPagerApi::class)
|
||||
@Composable
|
||||
private fun SuccessScreen() {
|
||||
val input = stringResource(id = R.string.uart_input)
|
||||
@@ -141,10 +139,3 @@ private fun MacroView() {
|
||||
val state = viewModel.state.collectAsState().value
|
||||
MacroSection(state) { viewModel.onEvent(it) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Scroll(content: @Composable () -> Unit) {
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ internal class UARTViewModel @Inject constructor(
|
||||
repository.data.onEach {
|
||||
_state.value = _state.value.copy(uartManagerState = it)
|
||||
|
||||
if (it.connectionState == GattConnectionState.STATE_CONNECTED) {
|
||||
if (it.connectionState?.state == GattConnectionState.STATE_CONNECTED) {
|
||||
analytics.logEvent(ProfileConnectedEvent(Profile.UART))
|
||||
}
|
||||
}.launchIn(viewModelScope)
|
||||
|
||||
Reference in New Issue
Block a user