[Android] Network: Create isConnected() util

Geoffrey Métais git at videolan.org
Fri Jun 29 15:31:35 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 29 15:30:59 2018 +0200| [45b78b2c93174a4b62cfb103c47d1be2b2e04ab1] | committer: Geoffrey Métais

Network: Create isConnected() util

> https://code.videolan.org/videolan/vlc-android/commit/45b78b2c93174a4b62cfb103c47d1be2b2e04ab1
---

 vlc-android/src/org/videolan/vlc/ExternalMonitor.java                | 5 +++++
 .../src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java     | 5 ++---
 vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt        | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/ExternalMonitor.java b/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
index 5637f94ae..1ea271a94 100644
--- a/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
+++ b/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
@@ -167,6 +167,11 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
         return mobile;
     }
 
+    public static boolean isConnected() {
+        final Boolean co = connected.getValue();
+        return co != null && co.booleanValue();
+    }
+
     public static boolean isLan() {
         final Boolean status = connected.getValue();
         return status != null && status && !mobile;
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
index baeff3fe3..a7bf8d4bc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -128,7 +128,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
 
     @Override
     public void refresh() {
-        refresh(ExternalMonitor.connected.getValue());
+        refresh(ExternalMonitor.isConnected());
     }
 
     public void refresh(boolean connected) {
@@ -212,8 +212,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
      */
     protected void updateEmptyView() {
         if (getBinding() == null) return;
-        final Boolean connected = ExternalMonitor.connected.getValue();
-        if (connected != null && connected.booleanValue()) {
+        if (ExternalMonitor.isConnected()) {
             if (Util.isListEmpty(getViewModel().getDataset().getValue())) {
                 if (mSwipeRefreshLayout == null || mSwipeRefreshLayout.isRefreshing()) {
                     getBinding().empty.setText(R.string.loading);
diff --git a/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt b/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt
index 4a391f790..8c4229ba3 100644
--- a/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt
@@ -36,7 +36,7 @@ class NetworkProvider(dataset: LiveDataset<MediaLibraryItem>, url: String? = nul
     }
 
     suspend fun updateFavorites() : MutableList<MediaLibraryItem> {
-        if (ExternalMonitor.connected?.value != true) return mutableListOf()
+        if (!ExternalMonitor.isConnected()) return mutableListOf()
         val favs: MutableList<MediaLibraryItem> = withContext(CommonPool) { MediaDatabase.getInstance().allNetworkFav }.toMutableList()
         if (!ExternalMonitor.allowLan()) {
             val schemes = Arrays.asList("ftp", "sftp", "ftps", "http", "https")



More information about the Android mailing list