Commit 3d000c09 authored by Geoffrey Métais's avatar Geoffrey Métais

Update favorites on add/remove

parent c6976389
......@@ -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);
......
......@@ -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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment