Skip to content

Instantly share code, notes, and snippets.

@aleksandra-majchrzak
Created May 10, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleksandra-majchrzak/39f99e6e75ea67f6ca285106a4178163 to your computer and use it in GitHub Desktop.
Save aleksandra-majchrzak/39f99e6e75ea67f6ca285106a4178163 to your computer and use it in GitHub Desktop.
Example 4 for Kotlin Shared Flow article
class BleManager : BleConnectionObserver {
private val _bleConnectionStateFlow = MutableStateFlow(ConnectionState.Disconnected)
val bleConnectionStateFlow: StateFlow<ConnectionState> = _bleConnectionStateFlow
override fun onDeviceConnected(device: BluetoothDevice) {
/* ... */
_bleConnectionStateFlow.value = ConnectionState.Connected
}
override fun onDeviceDisconnected() {
/* ... */
_bleConnectionStateFlow.value = ConnectionState.Disconnected
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment