Revert to keeping deviceName in Repository data to preserve reentering the screen

This commit is contained in:
Sylwester Zielinski
2023-04-27 16:38:42 +02:00
parent 6163e570f8
commit 6c0acbfba9
26 changed files with 26 additions and 51 deletions

View File

@@ -8,7 +8,8 @@ internal data class CGMServiceData(
val records: List<CGMRecordWithSequenceNumber> = emptyList(),
val batteryLevel: Int? = null,
val connectionState: GattConnectionStateWithStatus? = null,
val requestStatus: RequestStatus = RequestStatus.IDLE
val requestStatus: RequestStatus = RequestStatus.IDLE,
val deviceName: String? = null
)
data class CGMRecordWithSequenceNumber(

View File

@@ -91,6 +91,7 @@ class CGMRepository @Inject constructor(
private fun shouldClean() = !isOnScreen && !isServiceRunning
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(CGMService::class.java, device)
}

View File

@@ -55,14 +55,13 @@ import no.nordicsemi.android.ui.view.ProfileAppBar
fun CGMScreen() {
val viewModel: CGMViewModel = hiltViewModel()
val state = viewModel.state.collectAsState().value
val deviceName = viewModel.deviceName.collectAsState().value
val navigateUp = { viewModel.onEvent(NavigateUp) }
Scaffold(
topBar = {
ProfileAppBar(
deviceName = deviceName,
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.cgms_title,
navigateUp = navigateUp,

View File

@@ -35,8 +35,6 @@ import android.os.ParcelUuid
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@@ -68,9 +66,6 @@ internal class CGMViewModel @Inject constructor(
val state = repository.data
private val _deviceName = MutableStateFlow<String?>(null)
val deviceName = _deviceName.asStateFlow()
init {
repository.setOnScreen(true)
@@ -112,7 +107,6 @@ internal class CGMViewModel @Inject constructor(
}
private fun onDeviceSelected(device: ServerDevice) {
_deviceName.value = device.name
repository.launch(device)
}

View File

@@ -73,6 +73,7 @@ class CSCRepository @Inject constructor(
val isRunning = data.map { it.connectionState?.state == GattConnectionState.STATE_CONNECTED }
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(CSCService::class.java, device)
}

View File

@@ -39,7 +39,8 @@ internal data class HRSServiceData(
val bodySensorLocation: Int? = null,
val batteryLevel: Int? = null,
val connectionState: GattConnectionStateWithStatus? = null,
val zoomIn: Boolean = false
val zoomIn: Boolean = false,
val deviceName: String? = null
) {
val heartRates = data.map { it.heartRate }
}

View File

@@ -87,6 +87,7 @@ class HRSRepository @Inject constructor(
private fun shouldClean() = !isOnScreen && !isServiceRunning
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(HRSService::class.java, device)
}

View File

@@ -55,14 +55,13 @@ import no.nordicsemi.android.ui.view.ProfileAppBar
fun HRSScreen() {
val viewModel: HRSViewModel = hiltViewModel()
val state = viewModel.state.collectAsState().value
val deviceName = viewModel.deviceName.collectAsState().value
val navigateUp = { viewModel.onEvent(NavigateUpEvent) }
Scaffold(
topBar = {
ProfileAppBar(
deviceName = deviceName,
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.hrs_title,
navigateUp = navigateUp,

View File

@@ -35,8 +35,6 @@ import android.os.ParcelUuid
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@@ -67,9 +65,6 @@ internal class HRSViewModel @Inject constructor(
val state = repository.data
private val _deviceName = MutableStateFlow<String?>(null)
val deviceName = _deviceName.asStateFlow()
init {
repository.setOnScreen(true)
@@ -102,7 +97,6 @@ internal class HRSViewModel @Inject constructor(
}
private fun onDeviceSelected(device: ServerDevice) {
_deviceName.value = device.name
repository.launch(device)
}

View File

@@ -39,5 +39,6 @@ internal data class HTSServiceData(
val data: HTSData = HTSData(),
val batteryLevel: Int? = null,
val connectionState: GattConnectionStateWithStatus? = null,
val temperatureUnit: TemperatureUnit = TemperatureUnit.CELSIUS
val temperatureUnit: TemperatureUnit = TemperatureUnit.CELSIUS,
val deviceName: String? = null
)

View File

@@ -88,6 +88,7 @@ class HTSRepository @Inject constructor(
private fun shouldClean() = !isOnScreen && !isServiceRunning
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(HTSService::class.java, device)
}

View File

@@ -31,7 +31,6 @@
package no.nordicsemi.android.hts.view
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
@@ -56,14 +55,13 @@ import no.nordicsemi.android.ui.view.ProfileAppBar
fun HTSScreen() {
val viewModel: HTSViewModel = hiltViewModel()
val state = viewModel.state.collectAsState().value
val deviceName = viewModel.deviceName.collectAsState().value
val navigateUp = { viewModel.onEvent(NavigateUp) }
Scaffold(
topBar = {
ProfileAppBar(
deviceName = deviceName,
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.hts_title,
navigateUp = navigateUp,

View File

@@ -35,8 +35,6 @@ import android.os.ParcelUuid
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@@ -67,9 +65,6 @@ internal class HTSViewModel @Inject constructor(
val state = repository.data
private val _deviceName = MutableStateFlow<String?>(null)
val deviceName = _deviceName.asStateFlow()
init {
repository.setOnScreen(true)
@@ -102,7 +97,6 @@ internal class HTSViewModel @Inject constructor(
}
private fun onDeviceSelected(device: ServerDevice) {
_deviceName.value = device.name
repository.launch(device)
}

View File

@@ -10,7 +10,8 @@ data class PRXServiceData(
val batteryLevel: Int? = null,
val connectionState: GattConnectionStateWithStatus? = null,
val connectionStatus: BleGattConnectionStatus? = null,
val isRemoteAlarm: Boolean = false
val isRemoteAlarm: Boolean = false,
val deviceName: String? = null
) {
val isLinkLossDisconnected = connectionStatus?.isLinkLoss ?: false

View File

@@ -89,6 +89,7 @@ class PRXRepository @Inject internal constructor(
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(PRXService::class.java, device)
}

View File

@@ -55,14 +55,13 @@ import no.nordicsemi.android.ui.view.ProfileAppBar
fun PRXScreen() {
val viewModel: PRXViewModel = hiltViewModel()
val state = viewModel.state.collectAsState().value
val deviceName = viewModel.deviceName.collectAsState().value
val navigateUp = { viewModel.onEvent(NavigateUpEvent) }
Scaffold(
topBar = {
ProfileAppBar(
deviceName = deviceName,
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.prx_title,
navigateUp = navigateUp,

View File

@@ -35,8 +35,6 @@ import android.os.ParcelUuid
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
@@ -73,9 +71,6 @@ internal class PRXViewModel @Inject constructor(
val state = repository.data
private val _deviceName = MutableStateFlow<String?>(null)
val deviceName = _deviceName.asStateFlow()
init {
repository.setOnScreen(true)

View File

@@ -40,7 +40,8 @@ import no.nordicsemi.android.rscs.R
internal data class RSCSServiceData(
val data: RSCSData = RSCSData(),
val batteryLevel: Int? = null,
val connectionState: GattConnectionStateWithStatus? = null
val connectionState: GattConnectionStateWithStatus? = null,
val deviceName: String? = null
) {
@Composable
fun displayActivity(): String {

View File

@@ -87,6 +87,7 @@ class RSCSRepository @Inject constructor(
private fun shouldClean() = !isOnScreen && !isServiceRunning
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(RSCSService::class.java, device)
}

View File

@@ -55,14 +55,13 @@ import no.nordicsemi.android.ui.view.ProfileAppBar
fun RSCSScreen() {
val viewModel: RSCSViewModel = hiltViewModel()
val state = viewModel.state.collectAsState().value
val deviceName = viewModel.deviceName.collectAsState().value
val navigateUp = { viewModel.onEvent(NavigateUpEvent) }
Scaffold(
topBar = {
ProfileAppBar(
deviceName = deviceName,
deviceName = state.deviceName,
connectionState = state.connectionState,
title = R.string.rscs_title,
navigateUp = navigateUp,

View File

@@ -35,8 +35,6 @@ import android.os.ParcelUuid
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@@ -66,10 +64,6 @@ internal class RSCSViewModel @Inject constructor(
val state = repository.data
private val _deviceName = MutableStateFlow<String?>(null)
val deviceName = _deviceName.asStateFlow()
init {
viewModelScope.launch {
if (repository.isRunning.firstOrNull() == false) {
@@ -100,7 +94,6 @@ internal class RSCSViewModel @Inject constructor(
}
private fun onDeviceSelected(device: ServerDevice) {
_deviceName.value = device.name
repository.launch(device)
}

View File

@@ -36,7 +36,8 @@ import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionStateWithStatus
internal data class UARTServiceData(
val messages: List<UARTRecord> = emptyList(),
val connectionState: GattConnectionStateWithStatus? = null,
val batteryLevel: Int? = null
val batteryLevel: Int? = null,
val deviceName: String? = null
) {
val displayMessages = messages

View File

@@ -95,6 +95,7 @@ class UARTRepository @Inject internal constructor(
private fun shouldClean() = !isOnScreen && !isServiceRunning
fun launch(device: ServerDevice) {
_data.value = _data.value.copy(deviceName = device.name)
serviceManager.startService(UARTService::class.java, device)
}

View File

@@ -68,7 +68,7 @@ fun UARTScreen() {
Scaffold(
topBar = {
ProfileAppBar(
deviceName = state.deviceName,
deviceName = state.uartManagerState.deviceName,
connectionState = state.uartManagerState.connectionState,
title = R.string.uart_title,
navigateUp = navigateUp,

View File

@@ -41,8 +41,7 @@ internal data class UARTViewState(
val isConfigurationEdited: Boolean = false,
val configurations: List<UARTConfiguration> = emptyList(),
val uartManagerState: UARTServiceData = UARTServiceData(),
val isInputVisible: Boolean = true,
val deviceName: String? = null
val isInputVisible: Boolean = true
) {
val showEditDialog: Boolean = editedPosition != null

View File

@@ -134,7 +134,6 @@ internal class UARTViewModel @Inject constructor(
}
private fun onDeviceSelected(device: ServerDevice) {
_state.value = _state.value.copy(deviceName = device.name)
repository.launch(device)
}