[Android] Fix loading&empty views in browser

Geoffrey Métais git at videolan.org
Fri Feb 26 15:00:00 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Feb 26 14:58:50 2016 +0100| [9ba55fe9e9f3038e8673d882d28d7ed610df5608] | committer: Geoffrey Métais

Fix loading&empty views in browser

> https://code.videolan.org/videolan/vlc-android/commit/9ba55fe9e9f3038e8673d882d28d7ed610df5608
---

 .../vlc/gui/browser/BaseBrowserFragment.java       |  8 +-------
 .../vlc/gui/browser/FilePickerFragment.java        |  3 +++
 .../vlc/gui/browser/NetworkBrowserFragment.java    | 23 +++++++++++-----------
 3 files changed, 16 insertions(+), 18 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 b2799dd..daa2f61 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -147,12 +147,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         return v;
     }
 
-    @Override
-    public void onStart() {
-        super.onStart();
-        mMediaBrowser = new MediaBrowser(VLCInstance.get(), this);
-    }
-
     public void onStop(){
         super.onStop();
         releaseBrowser();
@@ -313,6 +307,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
 
     @Override
     public void refresh() {
+        mHandler.sendEmptyMessageDelayed(BrowserFragmentHandler.MSG_SHOW_LOADING, 300);
         mAdapter.clear();
         mFoldersContentLists.clear();
         if (mMediaBrowser == null)
@@ -324,7 +319,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             browseRoot();
         else
             mMediaBrowser.browse(mCurrentMedia != null ? mCurrentMedia.getUri() : Uri.parse(mMrl), true);
-        mHandler.sendEmptyMessageDelayed(BrowserFragmentHandler.MSG_SHOW_LOADING, 300);
     }
 
     private void deleteMedia(final MediaWrapper mw) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java
index 24fa9fe..12a1596 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java
@@ -31,10 +31,12 @@ import android.support.v4.app.Fragment;
 import android.text.TextUtils;
 import android.view.View;
 
+import org.videolan.libvlc.util.MediaBrowser;
 import org.videolan.vlc.R;
 import org.videolan.vlc.media.MediaWrapper;
 import org.videolan.vlc.util.FileUtils;
 import org.videolan.vlc.util.Strings;
+import org.videolan.vlc.util.VLCInstance;
 
 public class FilePickerFragment extends FileBrowserFragment {
 
@@ -60,6 +62,7 @@ public class FilePickerFragment extends FileBrowserFragment {
     @Override
     public void onStart() {
         super.onStart();
+        mMediaBrowser = new MediaBrowser(VLCInstance.get(), this);
         mMediaBrowser.setIgnoreFileTypes("db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv");
         getActivity().setTitle(getTitle());
     }
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 120f731..f426f39 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -133,10 +133,11 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
         mAdapter.setTop(mAdapter.getItemCount());
         if (AndroidDevices.hasLANConnection())
             mMediaBrowser.discoverNetworkShares();
-        else if (!mAdapter.isEmpty())
-            mAdapter.removeItem(mAdapter.getItemCount()-1, true);
-        if (!AndroidDevices.hasConnection())
-            updateEmptyView();
+        else {
+            if (!mAdapter.isEmpty())
+                mAdapter.removeItem(mAdapter.getItemCount() - 1, true);
+            mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
+        }
     }
 
     @Override
@@ -194,7 +195,10 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
             mAdapter.notifyItemRangeChanged(0, newSize+1);
         }
         mFavorites = newSize; //update count
-        updateEmptyView();
+        if (newSize != 0)
+            mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
+        else
+           updateEmptyView();
     }
 
     public void toggleFavorite() {
@@ -225,14 +229,11 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
             } else if (mEmptyView.getVisibility() == View.VISIBLE) {
                     mEmptyView.setVisibility(View.GONE);
                     mRecyclerView.setVisibility(View.VISIBLE);
-                    mSwipeRefreshLayout.setRefreshing(false);
             }
         } else {
-            if (mEmptyView.getVisibility() == View.GONE) {
-                mEmptyView.setText(R.string.network_connection_needed);
-                mEmptyView.setVisibility(View.VISIBLE);
-                mRecyclerView.setVisibility(View.GONE);
-            }
+            mEmptyView.setText(R.string.network_connection_needed);
+            mEmptyView.setVisibility(View.VISIBLE);
+            mRecyclerView.setVisibility(View.GONE);
         }
     }
 



More information about the Android mailing list