[Android] Show network favorites on top

Geoffrey Métais git at videolan.org
Wed Feb 3 19:01:20 CET 2016


vlc-android | branch: dialog | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb  3 16:22:24 2016 +0100| [ef6dbddc55c3199887327ae41e0ad8171f59b8dd] | committer: Geoffrey Métais

Show network favorites on top

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

 .../vlc/gui/browser/BaseBrowserAdapter.java        |  7 ++++-
 .../vlc/gui/browser/NetworkBrowserFragment.java    | 32 +++++++++++-----------
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index b1935c5..6718bf0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -64,6 +64,7 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
     LinkedList<String> mMediaDirsLocation;
     List<String> mCustomDirsLocation;
     String mEmptyDirectoryString;
+    private int mTop = 0;
 
     public BaseBrowserAdapter(BaseBrowserFragment fragment){
         this.fragment = fragment;
@@ -236,7 +237,7 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
         if (positionTo != -1)
             position = positionTo;
         else
-            position = top ? 0 : mMediaList.size();
+            position = top ? mTop : mMediaList.size();
 
         if (item instanceof Media)
             item = new MediaWrapper((Media) item);
@@ -249,6 +250,10 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             notifyItemInserted(position);
     }
 
+    public void setTop (int top) {
+        mTop = top;
+    }
+
     public void setDescription(int position, String description){
         Object item = getItem(position);
         if (item instanceof MediaWrapper)
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 4b9559c..0c0a19a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -112,13 +112,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
     @Override
     protected void browseRoot() {
         ArrayList<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
-        if (!favs.isEmpty()) {
-            mFavorites = favs.size();
-            for (MediaWrapper fav : favs) {
-                mAdapter.addItem(fav, false, true);
-            }
-            mAdapter.addItem("Network favorites", false, true);
-        }
+        updateFavorites();
         mMediaBrowser.discoverNetworkShares(Util.NETWORK_DISCOVER_LIST);
     }
 
@@ -133,16 +127,22 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
 
         if (newSize == 0 && mFavorites == 0)
             return;
-        for (int i = 1 ; i <= mFavorites ; ++i){ //remove former favorites
-            mAdapter.removeItem(totalSize-i, mReadyToDisplay);
-        }
-        if (newSize == 0)
-            mAdapter.removeItem(totalSize-mFavorites-1, mReadyToDisplay); //also remove separator if no more fav
-        else {
+        if (mFavorites != 0)
+            for (int i = 1 ; i <= mFavorites ; ++i) //remove former favorites
+                mAdapter.removeItem(i, mReadyToDisplay);
+
+        if (newSize == 0) {
+            mAdapter.removeItem(0, mReadyToDisplay); //also remove separator if no more fav
+            mAdapter.removeItem(0, mReadyToDisplay); //also remove separator if no more fav
+        } else {
+            if (mFavorites == 0)
+                mAdapter.addItem("Network favorites", false, false,0); //add header if needed
+            for (int i = 0 ; i < newSize ; ++i)
+                mAdapter.addItem(favs.get(i), false, false, i+1); //add new favorites
             if (mFavorites == 0)
-                mAdapter.addItem("Network favorites", false, false); //add header if needed
-            for (MediaWrapper fav : favs)
-                mAdapter.addItem(fav, false, false); //add new favorites
+                mAdapter.addItem("Shared folders", false, false, newSize + 1); //add header if needed
+            mAdapter.setTop(newSize + 2);
+            mAdapter.notifyItemRangeChanged(0, newSize + 1);
         }
         mFavorites = newSize; //update count
     }



More information about the Android mailing list