Updated on 2026-08-14
This commit is contained in:
parent
c2e95c92ae
commit
aa2b4bec5a
3 changed files with 12 additions and 3 deletions
|
|
@ -22,7 +22,7 @@ dependencies {
|
|||
|
||||
/** Coroutines */
|
||||
implementation(deps.kotlin.coroutines)
|
||||
implementation(deps.kotlin.coroutines.reactive)
|
||||
implementation(deps.kotlin.coroutines.rx2)
|
||||
|
||||
/** Logging */
|
||||
implementation(deps.timber)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
|||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import com.tangem.utils.coroutines.FeatureCoroutineExceptionHandler
|
||||
import io.reactivex.BackpressureStrategy
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
|
@ -21,6 +22,14 @@ internal class RealInternetConnectionManager : NetworkConnectionManager {
|
|||
SupervisorJob() + Dispatchers.IO + FeatureCoroutineExceptionHandler.create("RealInternetConnectionManager"),
|
||||
)
|
||||
|
||||
private val initialNetworkResult: Boolean by lazy {
|
||||
ReactiveNetwork
|
||||
.checkInternetConnectivity()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.blockingGet()
|
||||
}
|
||||
|
||||
override val isOnlineFlow: StateFlow<Boolean> = ReactiveNetwork
|
||||
.observeInternetConnectivity(
|
||||
InternetObservingSettings.builder()
|
||||
|
|
@ -29,7 +38,7 @@ internal class RealInternetConnectionManager : NetworkConnectionManager {
|
|||
)
|
||||
.toFlowable(BackpressureStrategy.LATEST)
|
||||
.asFlow()
|
||||
.stateIn(scope, SharingStarted.Lazily, initialValue = false)
|
||||
.stateIn(scope, SharingStarted.Lazily, initialValue = initialNetworkResult)
|
||||
|
||||
override val isOnline: Boolean
|
||||
get() = isOnlineFlow.value
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ appsflyer = { module = "com.appsflyer:af-android-sdk", version.ref = "appsflyer"
|
|||
armadillo = { module = "at.favre.lib:armadillo", version.ref = "armadillo" }
|
||||
coil = { module = "io.coil-kt:coil", version.ref = "coil" }
|
||||
kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutine" }
|
||||
kotlin-coroutines-reactive = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive", version.ref = "coroutine" }
|
||||
kotlin-coroutines-rx2 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2", version.ref = "coroutine" }
|
||||
kotlin-immutable-collections = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlin-immutable-collections" }
|
||||
desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugarJdkLibs" }
|
||||
googlePlay-core = { module = "com.google.android.play:core", version.ref = "googlePlayCore" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue