Skip to content

Instantly share code, notes, and snippets.

@aleksandra-majchrzak
Created May 10, 2021 21:18
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/7c1b4cb935ea43e999441ed236d51af7 to your computer and use it in GitHub Desktop.
Save aleksandra-majchrzak/7c1b4cb935ea43e999441ed236d51af7 to your computer and use it in GitHub Desktop.
Example 3 for Kotlin Shared Flow article
class BleManager : BleConnectionObserver {
private val _bleConnectionStateSubject = BehaviorSubject.createDefault(ConnectionState.Disconnected)
val bleConnectionStateObservable: Observable<ConnectionState> = _bleConnectionStateSubject.hide()
val currentConnectionState: ConnectionState
get() = _bleConnectionStateSubject.value
override fun onDeviceConnected(device: BluetoothDevice) {
/* ... */
_bleConnectionStateSubject.onNext(ConnectionState.Connected)
}
override fun onDeviceDisconnected() {
/* ... */
_bleConnectionStateSubject.onNext(ConnectionState.Disconnected)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment