Skip to content

Commit

Permalink
Fixed connecting to unnamed devices
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Sep 9, 2024
1 parent 0b60923 commit 4f6ea94
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ val ScannerDestination = defineDestination(ScannerDestinationId) {
}

class SelectedDevice(val device: ServerDevice, advertisedName: String?) {
val name: String = advertisedName ?: device.name ?: "Unknown"
val name: String? = advertisedName?.ifBlank { device.name }
}
23 changes: 4 additions & 19 deletions lib_ui/src/main/java/no/nordicsemi/android/ui/view/TopAppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

package no.nordicsemi.android.ui.view

import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -49,21 +48,12 @@ import no.nordicsemi.android.ui.R
@Composable
fun CloseIconAppBar(text: String, onClick: () -> Unit) {
NordicAppBar(
title = { Text(text, maxLines = 2) },
title = { Text(text) },
backButtonIcon = Icons.Default.Close,
onNavigationButtonClick = onClick,
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BackIconAppBar(text: String, onClick: () -> Unit) {
NordicAppBar(
title = { Text(text, maxLines = 2) },
onNavigationButtonClick = onClick,
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LoggerIconAppBar(
Expand All @@ -74,7 +64,7 @@ fun LoggerIconAppBar(
onLoggerClick: () -> Unit
) {
NordicAppBar(
title = { Text(text, maxLines = 2) },
title = { Text(text) },
onNavigationButtonClick = onClick,
actions = {
TextButton(
Expand All @@ -94,15 +84,10 @@ fun LoggerIconAppBar(
fun ProfileAppBar(
deviceName: String?,
connectionState: GattConnectionStateWithStatus?,
@StringRes title: Int,
navigateUp: () -> Unit,
disconnect: () -> Unit,
openLogger: () -> Unit
) {
if (deviceName?.isNotBlank() == true) {
val isConnected = connectionState?.state == GattConnectionState.STATE_CONNECTED
LoggerIconAppBar(deviceName, navigateUp, isConnected, disconnect, openLogger)
} else {
BackIconAppBar(stringResource(id = title), navigateUp)
}
val isConnected = connectionState?.state == GattConnectionState.STATE_CONNECTED
LoggerIconAppBar(deviceName ?: "No name", navigateUp, isConnected, disconnect, openLogger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.bps.R
import no.nordicsemi.android.bps.viewmodel.BPSViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
Expand All @@ -61,7 +60,6 @@ fun BPSScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.result.connectionState,
title = R.string.bps_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.cgms.R
import no.nordicsemi.android.cgms.viewmodel.CGMViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
Expand All @@ -62,7 +60,6 @@ fun CGMScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.cgms_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.csc.R
import no.nordicsemi.android.csc.viewmodel.CSCViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
Expand All @@ -62,7 +60,6 @@ fun CSCScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.csc_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(OnDisconnectButtonClick) },
openLogger = { viewModel.onEvent(OpenLogger) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.gls.R
import no.nordicsemi.android.gls.main.viewmodel.GLSViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
Expand All @@ -62,7 +60,6 @@ fun GLSScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.glsServiceData.connectionState,
title = R.string.gls_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.hrs.R
import no.nordicsemi.android.hrs.viewmodel.HRSViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
Expand All @@ -61,7 +60,6 @@ fun HRSScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.hrs_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.hts.R
import no.nordicsemi.android.hts.viewmodel.HTSViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
Expand All @@ -61,7 +60,6 @@ fun HTSScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.hts_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -45,7 +44,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceDisconnectedView
import no.nordicsemi.android.prx.R
import no.nordicsemi.android.prx.viewmodel.PRXViewModel
import no.nordicsemi.android.ui.view.NavigateUpButton
import no.nordicsemi.android.ui.view.ProfileAppBar
Expand All @@ -62,7 +60,6 @@ fun PRXScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.prx_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceConnectingView
import no.nordicsemi.android.kotlin.ble.ui.scanner.view.DeviceDisconnectedView
import no.nordicsemi.android.rscs.R
import no.nordicsemi.android.rscs.viewmodel.RSCSViewModel
import no.nordicsemi.android.ui.view.NavigateUpButton
import no.nordicsemi.android.ui.view.ProfileAppBar
Expand All @@ -61,7 +60,6 @@ fun RSCSScreen() {
ProfileAppBar(
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.rscs_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLoggerEvent) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ fun UARTScreen() {
ProfileAppBar(
deviceName = state.uartManagerState.deviceName,
connectionState = state.uartManagerState.connectionState,
title = R.string.uart_title,
navigateUp = navigateUp,
disconnect = { viewModel.onEvent(DisconnectEvent) },
openLogger = { viewModel.onEvent(OpenLogger) }
Expand Down

0 comments on commit 4f6ea94

Please sign in to comment.