Unlock UI if device disconnects after connection

This commit is contained in:
Sylwester Zielinski
2023-04-25 16:50:10 +02:00
parent 43c04fc79a
commit 52f4e26665
6 changed files with 42 additions and 0 deletions

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
}