From aa2b4bec5a808e1d252f3b17c9b1da8ddae60b10 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 5 Jun 2023 17:07:36 +0500 Subject: [PATCH] Updated on 2026-08-14 --- core/datasource/build.gradle.kts | 2 +- .../connection/RealInternetConnectionManager.kt | 11 ++++++++++- gradle/dependencies.toml | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/datasource/build.gradle.kts b/core/datasource/build.gradle.kts index 3350c7930f..de4006b63a 100644 --- a/core/datasource/build.gradle.kts +++ b/core/datasource/build.gradle.kts @@ -22,7 +22,7 @@ dependencies { /** Coroutines */ implementation(deps.kotlin.coroutines) - implementation(deps.kotlin.coroutines.reactive) + implementation(deps.kotlin.coroutines.rx2) /** Logging */ implementation(deps.timber) diff --git a/core/datasource/src/main/java/com/tangem/datasource/connection/RealInternetConnectionManager.kt b/core/datasource/src/main/java/com/tangem/datasource/connection/RealInternetConnectionManager.kt index 2560245330..8ca86a2587 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/connection/RealInternetConnectionManager.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/connection/RealInternetConnectionManager.kt @@ -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 = 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 diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index 8534bab9fa..d82a5ce419 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -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" }