mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-24 01:44:23 +01:00
Redesign manager approach
This commit is contained in:
@@ -45,9 +45,9 @@ private val UART_TX_CHARACTERISTIC_UUID = UUID.fromString("6E400003-B5A3-F393-E0
|
||||
|
||||
internal class UARTManager(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
scope: CoroutineScope,
|
||||
private val dataHolder: UARTRepository
|
||||
) : BatteryManager(context) {
|
||||
) : BatteryManager(context, scope) {
|
||||
|
||||
private var rxCharacteristic: BluetoothGattCharacteristic? = null
|
||||
private var txCharacteristic: BluetoothGattCharacteristic? = null
|
||||
|
||||
@@ -21,11 +21,11 @@ internal class UARTService : ForegroundBleService() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
status.onEach {
|
||||
val status = it.mapToSimpleManagerStatus()
|
||||
repository.setNewStatus(status)
|
||||
stopIfDisconnected(status)
|
||||
}.launchIn(scope)
|
||||
// status.onEach {
|
||||
// val status = it.mapToSimpleManagerStatus()
|
||||
// repository.setNewStatus(status)
|
||||
// stopIfDisconnected(status)
|
||||
// }.launchIn(scope)
|
||||
|
||||
repository.command.onEach {
|
||||
when (it) {
|
||||
|
||||
@@ -9,10 +9,8 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import no.nordicsemi.android.theme.view.BackIconAppBar
|
||||
import no.nordicsemi.android.theme.view.DeviceConnectingView
|
||||
import no.nordicsemi.android.uart.R
|
||||
import no.nordicsemi.android.uart.viewmodel.UARTViewModel
|
||||
import no.nordicsemi.android.utils.exhaustive
|
||||
|
||||
@Composable
|
||||
fun UARTScreen() {
|
||||
@@ -25,10 +23,10 @@ fun UARTScreen() {
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||
when (state) {
|
||||
is DisplayDataState -> UARTContentView(state.data) { viewModel.onEvent(it) }
|
||||
LoadingState -> DeviceConnectingView()
|
||||
}.exhaustive
|
||||
// when (state) {
|
||||
// is DisplayDataState -> UARTContentView(state.data) { viewModel.onEvent(it) }
|
||||
// LoadingState -> DeviceConnectingView()
|
||||
// }.exhaustive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ internal class UARTViewModel @Inject constructor(
|
||||
) : ViewModel() {
|
||||
|
||||
val state = repository.data.combine(repository.status) { data, status ->
|
||||
when (status) {
|
||||
BleManagerStatus.CONNECTING -> LoadingState
|
||||
BleManagerStatus.OK,
|
||||
BleManagerStatus.DISCONNECTED -> DisplayDataState(data)
|
||||
}
|
||||
// when (status) {
|
||||
// BleManagerStatus.CONNECTING -> LoadingState
|
||||
// BleManagerStatus.OK,
|
||||
// BleManagerStatus.DISCONNECTED -> DisplayDataState(data)
|
||||
// }
|
||||
}.stateIn(viewModelScope, SharingStarted.Lazily, LoadingState)
|
||||
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user