diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt index 5e9a7e06..c8281337 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt @@ -2,8 +2,6 @@ package io.horizontalsystems.ethereumkit.core import android.app.Application import android.content.Context -import android.os.Handler -import android.os.Looper import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import io.horizontalsystems.ethereumkit.api.core.* @@ -123,6 +121,7 @@ class EthereumKit( started = false blockchain.stop() state.clear() + connectionManager.stop() } fun refresh() { @@ -130,17 +129,6 @@ class EthereumKit( transactionSyncManager.sync() } - fun onEnterForeground() { - connectionManager.onEnterForeground() - Handler(Looper.getMainLooper()).postDelayed({ - blockchain.refresh() - }, 1000) - } - - fun onEnterBackground() { - connectionManager.onEnterBackground() - } - fun getFullTransactionsFlowable(tags: List>): Flowable> { return transactionManager.getFullTransactionsFlowable(tags) } diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/network/ConnectionManager.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/network/ConnectionManager.kt index d87d57aa..d5f4904e 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/network/ConnectionManager.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/network/ConnectionManager.kt @@ -15,37 +15,15 @@ class ConnectionManager(context: Context) { private val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager var listener: Listener? = null - var isConnected = false + var isConnected = getInitialConnectionStatus() private var hasValidInternet = false private var hasConnection = false private var callback = ConnectionStatusCallback() init { - onEnterForeground() - } - - fun onEnterForeground() { - setInitialValues() - try { - connectivityManager.unregisterNetworkCallback(callback) - } catch (e: Exception) { - //was not registered, or already unregistered - } connectivityManager.registerNetworkCallback(NetworkRequest.Builder().build(), callback) } - fun onEnterBackground() { - try { - connectivityManager.unregisterNetworkCallback(callback) - } catch (e: Exception) { - //already unregistered - } - } - - private fun setInitialValues() { - isConnected = getInitialConnectionStatus() - } - private fun getInitialConnectionStatus(): Boolean { val network = connectivityManager.activeNetwork ?: return false @@ -93,4 +71,12 @@ class ConnectionManager(context: Context) { listener?.onConnectionChange() } } + + fun stop() { + try { + connectivityManager.unregisterNetworkCallback(callback) + } catch (e: Exception) { + //already unregistered + } + } }