[Android] Finer empty view management in browsers

Geoffrey Métais git at videolan.org
Thu Feb 18 14:50:57 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 18 14:49:10 2016 +0100| [d2e40bd0acfc0b917f553a71527aa520fd40fcc4] | committer: Geoffrey Métais

Finer empty view management in browsers

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

 vlc-android/res/layout/directory_browser.xml       |  2 +-
 .../vlc/gui/browser/BaseBrowserFragment.java       | 22 ++++++++++++++++------
 .../vlc/gui/browser/FileBrowserFragment.java       |  1 -
 .../vlc/gui/browser/NetworkBrowserFragment.java    | 22 ++++++++++++----------
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/vlc-android/res/layout/directory_browser.xml b/vlc-android/res/layout/directory_browser.xml
index 0eb9ddd..f2053a5 100644
--- a/vlc-android/res/layout/directory_browser.xml
+++ b/vlc-android/res/layout/directory_browser.xml
@@ -21,7 +21,7 @@
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:gravity="center"
-                android:text="@string/network_connection_needed"/>
+                android:text="@string/directory_empty"/>
         </FrameLayout>
     </org.videolan.vlc.gui.view.SwipeRefreshLayout>
 
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 6bf085e..aeba943 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -221,10 +221,11 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
 
     @Override
     public void onMediaAdded(int index, Media media) {
+        boolean empty = mAdapter.isEmpty();
         mAdapter.addItem(media, mReadyToDisplay && mRoot, mRoot);
-        if (mReadyToDisplay)
+        if (empty && mReadyToDisplay)
             updateEmptyView();
-        if (mRoot)
+        if (mRoot && mSwipeRefreshLayout.isRefreshing())
             mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
     }
 
@@ -266,13 +267,20 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
      */
     protected void updateEmptyView(){
         if (mAdapter.isEmpty()){
-            mEmptyView.setVisibility(View.VISIBLE);
-            mRecyclerView.setVisibility(View.GONE);
-            mSwipeRefreshLayout.setEnabled(false);
+            if (mSwipeRefreshLayout.isRefreshing()) {
+                mEmptyView.setText(R.string.loading);
+                mEmptyView.setVisibility(View.VISIBLE);
+                mRecyclerView.setVisibility(View.GONE);
+            } else {
+                mEmptyView.setText(R.string.directory_empty);
+                mEmptyView.setVisibility(View.VISIBLE);
+                mRecyclerView.setVisibility(View.GONE);
+                mSwipeRefreshLayout.setRefreshing(false);
+            }
         } else if (mEmptyView.getVisibility() == View.VISIBLE) {
             mEmptyView.setVisibility(View.GONE);
             mRecyclerView.setVisibility(View.VISIBLE);
-            mSwipeRefreshLayout.setEnabled(true);
+            mSwipeRefreshLayout.setRefreshing(false);
         }
     }
 
@@ -344,10 +352,12 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             switch (msg.what){
                 case MSG_SHOW_LOADING:
                     fragment.mSwipeRefreshLayout.setRefreshing(true);
+                    fragment.updateEmptyView();
                     break;
                 case MSG_HIDE_LOADING:
                     removeMessages(MSG_SHOW_LOADING);
                     fragment.mSwipeRefreshLayout.setRefreshing(false);
+                    fragment.updateEmptyView();
                     break;
                 case MSG_REFRESH:
                     if (getOwner() != null && !getOwner().isDetached())
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
index d5e9ab2..222f2cc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -67,7 +67,6 @@ public class FileBrowserFragment extends BaseBrowserFragment {
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        mEmptyView.setText(getString(R.string.directory_empty));
     }
 
     @Override
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 5636916..489be68 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -23,7 +23,6 @@
 
 package org.videolan.vlc.gui.browser;
 
-import android.app.DialogFragment;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -52,8 +51,6 @@ import java.util.List;
 
 public class NetworkBrowserFragment extends BaseBrowserFragment implements View.OnClickListener {
 
-    private DialogFragment mDialog;
-
     public NetworkBrowserFragment() {
         ROOT = "smb";
         mHandler = new BrowserFragmentHandler(this);
@@ -212,14 +209,20 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
     protected void updateEmptyView() {
         if (AndroidDevices.hasConnection()) {
             if (mAdapter.isEmpty()) {
-                mEmptyView.setText(mRoot ? R.string.network_shares_discovery : R.string.network_empty);
-                mEmptyView.setVisibility(View.VISIBLE);
-                mRecyclerView.setVisibility(View.GONE);
-            } else {
-                if (mEmptyView.getVisibility() == View.VISIBLE) {
+                if (mSwipeRefreshLayout.isRefreshing()) {
+                    mEmptyView.setText(R.string.loading);
+                    mEmptyView.setVisibility(View.VISIBLE);
+                    mRecyclerView.setVisibility(View.GONE);
+                } else {
+                    mEmptyView.setText(mRoot ? R.string.network_shares_discovery : R.string.network_empty);
+                    mEmptyView.setVisibility(View.VISIBLE);
+                    mRecyclerView.setVisibility(View.GONE);
+                    mSwipeRefreshLayout.setRefreshing(false);
+                }
+            } else if (mEmptyView.getVisibility() == View.VISIBLE) {
                     mEmptyView.setVisibility(View.GONE);
                     mRecyclerView.setVisibility(View.VISIBLE);
-                }
+                    mSwipeRefreshLayout.setRefreshing(false);
             }
         } else {
             if (mEmptyView.getVisibility() == View.GONE) {
@@ -228,7 +231,6 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
                 mRecyclerView.setVisibility(View.GONE);
             }
         }
-        mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
     }
 
     @Override



More information about the Android mailing list