[Android] Fix duplicated network favorites

Geoffrey Métais git at videolan.org
Wed Feb 21 11:32:03 CET 2018


vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 21 10:05:09 2018 +0100| [bbcfed1de1e52d8703873f72820527a74fdce08e] | committer: Geoffrey Métais

Fix duplicated network favorites

(cherry picked from commit d9d4b9b2c0fab6b77b6f90d68de2ec9723fa05e8)

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

 .../vlc/gui/browser/BaseBrowserFragment.java       |  1 +
 .../vlc/gui/browser/NetworkBrowserFragment.java    | 41 ++++++++++------------
 2 files changed, 19 insertions(+), 23 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 734752854..b2023b447 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -471,6 +471,7 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
                         fragment.mSwipeRefreshLayout.setRefreshing(false);
                     break;
                 case MSG_REFRESH:
+                    removeMessages(MSG_REFRESH);
                     if (!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 282b36239..b13bd7ea2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -156,8 +156,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
 
     @Override
     protected void browseRoot() {
-        if (!isAdded())
-            return;
+        if (!isAdded()) return;
         updateFavorites();
         mAdapter.setTop(mAdapter.getItemCount());
         if (allowLAN())
@@ -219,9 +218,10 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
                 return;
             }
         }
-        if (mFavorites != 0 && !mAdapter.isEmpty())
-            for (int i = 1 ; i <= mFavorites ; ++i) //remove former favorites
+        if (mFavorites != 0 && !mAdapter.getAll().isEmpty())
+            for (int i = 1 ; i <= mFavorites ; ++i) {//remove former favorites
                 mAdapter.removeItem(1);
+            }
 
         if (newSize == 0 && !mAdapter.isEmpty()) {
             mAdapter.removeItem(0); //also remove separator if no more fav
@@ -230,8 +230,9 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
             boolean isEmpty =  mAdapter.isEmpty();
             if (mFavorites == 0 || isEmpty)
                 mAdapter.addItem(new DummyItem(getString(R.string.network_favorites)), false,0); //add header if needed
-            for (int i = 0 ; i < newSize ; )
+            for (int i = 0 ; i < newSize ; ) {
                 mAdapter.addItem(favs.get(i), false, ++i); //add new favorites
+            }
             if (mFavorites == 0 || isEmpty)
                 mAdapter.addItem(new DummyItem(getString(R.string.network_shared_folders)), false, newSize + 1); //add header if needed
         }
@@ -242,7 +243,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
     }
 
     public void toggleFavorite() {
-        MediaDatabase db = MediaDatabase.getInstance();
+        final MediaDatabase db = MediaDatabase.getInstance();
         if (db.networkFavExists(mCurrentMedia.getUri()))
             db.deleteNetworkFav(mCurrentMedia.getUri());
         else
@@ -254,8 +255,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
      * Update views visibility and emptiness info
      */
     protected void updateEmptyView() {
-        if (mEmptyView == null)
-            return;
+        if (mEmptyView == null) return;
         if (ExternalMonitor.isConnected()) {
             if (mAdapter.isEmpty()) {
                 if (mSwipeRefreshLayout == null || mSwipeRefreshLayout.isRefreshing()) {
@@ -284,17 +284,14 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
 
     @Override
     public void onClick(View v) {
-        if (!isRootDirectory())
-            super.onClick(v);
-        else if (v.getId() == R.id.fab)
-            showAddServerDialog(null);
+        if (!isRootDirectory()) super.onClick(v);
+        else if (v.getId() == R.id.fab) showAddServerDialog(null);
     }
 
     public void showAddServerDialog(MediaWrapper mw) {
-        FragmentManager fm = getFragmentManager();
-        NetworkServerDialog dialog = new NetworkServerDialog();
-        if (mw != null)
-            dialog.setServer(mw);
+        final FragmentManager fm = getFragmentManager();
+        final NetworkServerDialog dialog = new NetworkServerDialog();
+        if (mw != null) dialog.setServer(mw);
         dialog.show(fm, "fragment_add_server");
     }
 
@@ -305,18 +302,16 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Exter
     private BroadcastReceiver mLocalReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            if (isResumed())
-                goBack();
-            else
-                goBack = true;
+            if (isResumed()) goBack();
+            else goBack = true;
         }
     };
 
     @Override
     public void onNetworkConnectionChanged(boolean connected) {
         final boolean isEmpty = mAdapter.isEmpty();
-        refresh();
-        if (!connected && isEmpty) //update() will trigger updateEmptyView
-            updateEmptyView();
+        mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_REFRESH);
+        //update() will trigger updateEmptyView
+        if (!connected && isEmpty) updateEmptyView();
     }
 }



More information about the Android mailing list