mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 23:44:24 +01:00
Changed to stateflow
This commit is contained in:
@@ -8,6 +8,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
@@ -87,7 +88,7 @@ internal class ProfileService : NotificationService() {
|
||||
override val isMissingServices: Flow<Boolean>
|
||||
get() = _isMissingServices.asStateFlow()
|
||||
|
||||
override val disconnectionReason: Flow<DeviceDisconnectionReason?>
|
||||
override val disconnectionReason: StateFlow<DeviceDisconnectionReason?>
|
||||
get() = _disconnectionReason.asStateFlow()
|
||||
|
||||
override suspend fun getMaxWriteValue(address: String, writeType: WriteType): Int? {
|
||||
@@ -134,7 +135,7 @@ internal class ProfileService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun getConnectionState(address: String): Flow<ConnectionState>? {
|
||||
override fun getConnectionState(address: String): StateFlow<ConnectionState>? {
|
||||
val peripheral = getPeripheralById(address) ?: return null
|
||||
return peripheral.state.also { stateFlow ->
|
||||
connectionJobs[address]?.cancel()
|
||||
|
||||
@@ -19,7 +19,7 @@ sealed interface ProfileServiceManager {
|
||||
}
|
||||
|
||||
internal class ProfileServiceManagerImp @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
@param:ApplicationContext private val context: Context,
|
||||
) : ProfileServiceManager {
|
||||
private var serviceConnection: ServiceConnection? = null
|
||||
private var api: ServiceApi? = null
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package no.nordicsemi.android.service.profile
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import no.nordicsemi.android.toolbox.profile.manager.ServiceManager
|
||||
import no.nordicsemi.android.ui.view.internal.DisconnectReason
|
||||
import no.nordicsemi.kotlin.ble.client.android.Peripheral
|
||||
@@ -44,14 +45,14 @@ interface ServiceApi {
|
||||
*
|
||||
* @return the connection state flow.
|
||||
*/
|
||||
fun getConnectionState(address: String): Flow<ConnectionState>?
|
||||
fun getConnectionState(address: String): StateFlow<ConnectionState>?
|
||||
|
||||
/**
|
||||
* Get the disconnection reason of the device with the given address.
|
||||
*
|
||||
* @return the disconnection reason flow.
|
||||
*/
|
||||
val disconnectionReason: Flow<DeviceDisconnectionReason?>
|
||||
val disconnectionReason: StateFlow<DeviceDisconnectionReason?>
|
||||
|
||||
/**
|
||||
* Request maximum write value length.
|
||||
|
||||
@@ -140,6 +140,7 @@ internal class ProfileViewModel @Inject constructor(
|
||||
* Update the service data, including connection state and peripheral data.
|
||||
* @param api the service API.
|
||||
* @param deviceAddress the address of the connected device.
|
||||
* @param isAlreadyConnected true if the device is already connected, false otherwise.
|
||||
*/
|
||||
private fun updateConnectionState(
|
||||
api: ServiceApi,
|
||||
|
||||
Reference in New Issue
Block a user