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