|
|
|
@ -36,11 +36,13 @@ import javax.inject.Inject
|
|
|
|
|
class ConnectivityManagerNetworkMonitor @Inject constructor(
|
|
|
|
|
@ApplicationContext private val context: Context,
|
|
|
|
|
) : NetworkMonitor {
|
|
|
|
|
override val isOnline: Flow<Boolean> {
|
|
|
|
|
override val isOnline: Flow<Boolean> = callbackFlow {
|
|
|
|
|
val connectivityManager = context.getSystemService<ConnectivityManager>()
|
|
|
|
|
?: return flowOf(false)
|
|
|
|
|
|
|
|
|
|
return callbackFlow {
|
|
|
|
|
?: run {
|
|
|
|
|
channel.trySend(false)
|
|
|
|
|
channel.close()
|
|
|
|
|
return@callbackFlow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The callback's methods are invoked on changes to *any* network, not just the active
|
|
|
|
|