[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] branch master updated: [wallet] some fixes for Net
From: |
gnunet |
Subject: |
[taler-taler-android] branch master updated: [wallet] some fixes for NetworkManager |
Date: |
Tue, 19 Sep 2023 17:55:30 +0200 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository taler-android.
The following commit(s) were added to refs/heads/master by this push:
new 9bfc8b7 [wallet] some fixes for NetworkManager
9bfc8b7 is described below
commit 9bfc8b7a4e0cca3cfb052750385f2005c7bc31d7
Author: Torsten Grote <t@grobox.de>
AuthorDate: Tue Sep 19 17:55:24 2023 +0200
[wallet] some fixes for NetworkManager
---
wallet/src/main/java/net/taler/wallet/NetworkManager.kt | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/NetworkManager.kt
b/wallet/src/main/java/net/taler/wallet/NetworkManager.kt
index 7d803fc..064135b 100644
--- a/wallet/src/main/java/net/taler/wallet/NetworkManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/NetworkManager.kt
@@ -30,12 +30,14 @@ import androidx.lifecycle.MutableLiveData
class NetworkManager(context: Context) : ConnectivityManager.NetworkCallback()
{
private val connectivityManager: ConnectivityManager
- private val _networkStatus = MutableLiveData(true)
- val networkStatus: LiveData<Boolean> = _networkStatus
+ private val _networkStatus: MutableLiveData<Boolean>
+ val networkStatus: LiveData<Boolean>
init {
connectivityManager = context.getSystemService(CONNECTIVITY_SERVICE)
as ConnectivityManager
connectivityManager.registerDefaultNetworkCallback(this)
+ _networkStatus = MutableLiveData(getCurrentStatus())
+ networkStatus = _networkStatus
}
@UiThread
@@ -46,7 +48,13 @@ class NetworkManager(context: Context) :
ConnectivityManager.NetworkCallback() {
override fun onLost(network: Network) {
super.onLost(network)
- _networkStatus.postValue(null)
+ _networkStatus.postValue(getCurrentStatus())
+ }
+
+ private fun getCurrentStatus(): Boolean {
+ return connectivityManager.activeNetwork?.let { network ->
+ connectivityManager.getNetworkCapabilities(network)?.isOnline()
+ } ?: false
}
private fun NetworkCapabilities.isOnline(): Boolean {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-android] branch master updated: [wallet] some fixes for NetworkManager,
gnunet <=