mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-10 02:04:26 +01:00
Unlock UI if device disconnects after connection
This commit is contained in:
@@ -144,6 +144,7 @@ internal class CGMService : NotificationService() {
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
.onEach { unlockUiIfDisconnected(it, device) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
@@ -312,6 +313,12 @@ internal class CGMService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
repository.onInitComplete(device)
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ internal class CSCService : NotificationService() {
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
.onEach { unlockUiIfDisconnected(it, device) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
@@ -139,6 +140,12 @@ internal class CSCService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
repository.onInitComplete(device)
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ internal class HRSService : NotificationService() {
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
.onEach { unlockUiIfDisconnected(it, device) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
@@ -144,6 +145,12 @@ internal class HRSService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
repository.onInitComplete(device)
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ internal class HTSService : NotificationService() {
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
.onEach { unlockUiIfDisconnected(it, device) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
@@ -138,6 +139,12 @@ internal class HTSService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
repository.onInitComplete(device)
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ internal class RSCSService : NotificationService() {
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
.onEach { unlockUiIfDisconnected(it, device) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
@@ -138,6 +139,12 @@ internal class RSCSService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
repository.onInitComplete(device)
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ internal class UARTService : NotificationService() {
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it) }
|
||||
.onEach { unlockUiIfDisconnected(it, device) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
@@ -160,6 +161,12 @@ internal class UARTService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||
repository.onInitComplete(device)
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user