[Android] Update favorites on add/remove

Geoffrey Métais git at videolan.org
Wed Apr 4 18:36:12 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 30 18:28:49 2018 +0200| [3d000c09c7200725e9568fb8dc4c689ed0a4fc92] | committer: Geoffrey Métais

Update favorites on add/remove

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

 .../videolan/vlc/gui/browser/NetworkBrowserFragment.java    | 13 ++++---------
 .../org/videolan/vlc/viewmodels/browser/NetworkProvider.kt  |  2 ++
 2 files changed, 6 insertions(+), 9 deletions(-)

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 39e06d08d..6ecf0cd77 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -168,19 +168,14 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
         int id = item.getItemId();
         if (!(mAdapter.getItem(position) instanceof MediaWrapper)) return false;
         final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
-                MediaDatabase db;
         switch (id){
             case R.id.network_add_favorite:
-                db = MediaDatabase.getInstance();
-                db.addNetworkFavItem(mw.getUri(), mw.getTitle(), mw.getArtworkURL());
-                if (isRootDirectory())
-                    //updateFavorites();
+                MediaDatabase.getInstance().addNetworkFavItem(mw.getUri(), mw.getTitle(), mw.getArtworkURL());
+                if (isRootDirectory()) ((NetworkProvider)getProvider()).updateFavs();
                 return true;
             case R.id.network_remove_favorite:
-                db = MediaDatabase.getInstance();
-                db.deleteNetworkFav(mw.getUri());
-                if (isRootDirectory())
-                    //updateFavorites();
+                MediaDatabase.getInstance().deleteNetworkFav(mw.getUri());
+                if (isRootDirectory()) ((NetworkProvider)getProvider()).updateFavs();
                 return true;
             case R.id.network_edit_favorite:
                 showAddServerDialog(mw);
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkProvider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkProvider.kt
index fe8de493e..c59a001a8 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkProvider.kt
@@ -26,6 +26,8 @@ class NetworkProvider(url: String? = null, showHiddenFiles: Boolean): BrowserPro
         }
     }
 
+    fun updateFavs() = launch(UI, CoroutineStart.UNDISPATCHED) { updateFavorites() }
+
     private suspend fun updateFavorites() {
         if (ExternalMonitor.connected?.value != true) favorites.value = mutableListOf()
         val favs: MutableList<MediaLibraryItem> = withContext(CommonPool) { MediaDatabase.getInstance().allNetworkFav }.toMutableList()



More information about the Android mailing list