[Android] Prevent NPE in browsers

Geoffrey Métais git at videolan.org
Wed Sep 20 16:56:12 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep 20 16:53:28 2017 +0200| [8dd8e40d706424831447b83e52c06c04b775d27d] | committer: Geoffrey Métais

Prevent NPE in browsers

> https://code.videolan.org/videolan/vlc-android/commit/8dd8e40d706424831447b83e52c06c04b775d27d
---

 .../org/videolan/vlc/gui/browser/BaseBrowserFragment.java    | 12 +++++++-----
 .../org/videolan/vlc/gui/browser/NetworkBrowserFragment.java |  4 ++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 6c3a9d672..61cda0d01 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -444,20 +444,22 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
         }
         @Override
         public void handleMessage(Message msg) {
-            BaseBrowserFragment fragment = getOwner();
+            final BaseBrowserFragment fragment = getOwner();
             if (fragment == null)
                 return;
             switch (msg.what){
                 case MSG_SHOW_LOADING:
-                    fragment.mSwipeRefreshLayout.setRefreshing(true);
+                    if (fragment.mSwipeRefreshLayout != null)
+                        fragment.mSwipeRefreshLayout.setRefreshing(true);
                     break;
                 case MSG_HIDE_LOADING:
                     removeMessages(MSG_SHOW_LOADING);
-                    fragment.mSwipeRefreshLayout.setRefreshing(false);
+                    if (fragment.mSwipeRefreshLayout != null)
+                        fragment.mSwipeRefreshLayout.setRefreshing(false);
                     break;
                 case MSG_REFRESH:
-                    if (getOwner() != null && !getOwner().isDetached())
-                        getOwner().refresh();
+                    if (fragment != null && !fragment.isDetached())
+                        fragment.refresh();
             }
         }
     }
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 b16bfd9c4..9b0497d92 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -255,7 +255,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
     protected void updateEmptyView() {
         if (ExternalMonitor.isConnected()) {
             if (mAdapter.isEmpty()) {
-                if (mSwipeRefreshLayout.isRefreshing()) {
+                if (mSwipeRefreshLayout == null || mSwipeRefreshLayout.isRefreshing()) {
                     mEmptyView.setText(R.string.loading);
                     mEmptyView.setVisibility(View.VISIBLE);
                     mRecyclerView.setVisibility(View.GONE);
@@ -266,7 +266,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
                         mEmptyView.setText(R.string.network_empty);
                     mEmptyView.setVisibility(View.VISIBLE);
                     mRecyclerView.setVisibility(View.GONE);
-                    mSwipeRefreshLayout.setRefreshing(false);
+                    mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
                 }
             } else if (mEmptyView.getVisibility() == View.VISIBLE) {
                     mEmptyView.setVisibility(View.GONE);



More information about the Android mailing list