mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 15:34:26 +01:00
Fixed reconnection
This commit is contained in:
@@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onCompletion
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -135,17 +134,13 @@ internal class ProfileService : NotificationService() {
|
|||||||
StateReason(reason as ConnectionState.Disconnected.Reason)
|
StateReason(reason as ConnectionState.Disconnected.Reason)
|
||||||
)
|
)
|
||||||
_devices.update { it - peripheral.address }
|
_devices.update { it - peripheral.address }
|
||||||
|
handleDisconnection(peripheral.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// Handle connecting/disconnecting states if needed
|
// Handle connecting/disconnecting states if needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.onCompletion {
|
|
||||||
handleDisconnection(peripheral.address)
|
|
||||||
managedConnections[peripheral.address]?.cancel()
|
|
||||||
managedConnections.remove(peripheral.address)
|
|
||||||
stopServiceIfNoDevices()
|
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +210,9 @@ internal class ProfileService : NotificationService() {
|
|||||||
private fun handleDisconnection(address: String) {
|
private fun handleDisconnection(address: String) {
|
||||||
_devices.update { it - address }
|
_devices.update { it - address }
|
||||||
_isMissingServices.update { it - address }
|
_isMissingServices.update { it - address }
|
||||||
|
managedConnections[address]?.cancel()
|
||||||
|
managedConnections.remove(address)
|
||||||
|
stopServiceIfNoDevices()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopServiceIfNoDevices() {
|
private fun stopServiceIfNoDevices() {
|
||||||
|
|||||||
Reference in New Issue
Block a user