Updated on 2026-08-14
This commit is contained in:
parent
ee21ead663
commit
8fbc4951c1
4 changed files with 54 additions and 12 deletions
|
|
@ -15,6 +15,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
|
@ -35,12 +36,13 @@ internal class AndroidNetworkConnectionManager @Inject constructor(
|
|||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : NetworkConnectionManager {
|
||||
|
||||
override val isOnline: Boolean get() = _isOnline.value
|
||||
|
||||
private val _isOnline = MutableStateFlow(value = false)
|
||||
private val callbacks = NetworkConnectionManagerCallbacks()
|
||||
private val receiver = NetworkConnectionBroadcastReceiver()
|
||||
|
||||
override val isOnline: Boolean get() = _isOnline.value
|
||||
override val isOnlineFlow: StateFlow<Boolean> = _isOnline
|
||||
|
||||
init {
|
||||
(context as? Application)?.registerActivityLifecycleCallbacks(callbacks)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
package com.tangem.datasource.connection
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/** Network connection manager */
|
||||
interface NetworkConnectionManager {
|
||||
|
||||
/** Connection status */
|
||||
val isOnline: Boolean
|
||||
|
||||
/** Connection status flow */
|
||||
val isOnlineFlow: StateFlow<Boolean>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue