[Android] Fix network favorites
Geoffrey Métais
git at videolan.org
Fri Apr 20 16:09:35 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr 20 16:09:18 2018 +0200| [c387248fc2efb5d24a4de5f78676d7f72b3de64c] | committer: Geoffrey Métais
Fix network favorites
> https://code.videolan.org/videolan/vlc-android/commit/c387248fc2efb5d24a4de5f78676d7f72b3de64c
---
vlc-android/res/layout/directory_browser.xml | 2 ++
.../vlc/gui/browser/BaseBrowserAdapter.java | 11 +++++++----
.../vlc/gui/browser/NetworkBrowserFragment.java | 21 ++++++++++++++++-----
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/vlc-android/res/layout/directory_browser.xml b/vlc-android/res/layout/directory_browser.xml
index cac32b1db..5afd4b654 100644
--- a/vlc-android/res/layout/directory_browser.xml
+++ b/vlc-android/res/layout/directory_browser.xml
@@ -38,6 +38,8 @@
android:id="@+id/favorites_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/favorites_title"
android:visibility="@{showFavorites ? View.VISIBLE : View.GONE}" />
<TextView
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 7fc648a6b..4a8bd9554 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -44,8 +44,6 @@ import org.videolan.vlc.databinding.BrowserItemSeparatorBinding;
import org.videolan.vlc.gui.DiffUtilAdapter;
import org.videolan.vlc.gui.helpers.SelectorViewHolder;
import org.videolan.vlc.util.AndroidDevices;
-import org.videolan.vlc.util.Util;
-import org.videolan.vlc.util.WorkersKt;
import java.util.ArrayList;
import java.util.List;
@@ -72,9 +70,13 @@ public class BaseBrowserAdapter extends DiffUtilAdapter<MediaLibraryItem, BaseBr
}
protected final BaseBrowserFragment fragment;
private int mMediaCount = 0, mSelectionCount = 0;
- private final boolean mNetworkRoot, mSpecialIcons;
+ private final boolean mNetworkRoot, mSpecialIcons, mFavorites;
BaseBrowserAdapter(BaseBrowserFragment fragment) {
+ this(fragment, false);
+ }
+
+ BaseBrowserAdapter(BaseBrowserFragment fragment, boolean favorites) {
this.fragment = fragment;
final boolean root = fragment.isRootDirectory();
final boolean fileBrowser = fragment instanceof FileBrowserFragment;
@@ -82,6 +84,7 @@ public class BaseBrowserAdapter extends DiffUtilAdapter<MediaLibraryItem, BaseBr
mNetworkRoot = root && fragment instanceof NetworkBrowserFragment;
final String mrl = fragment.mMrl;
mSpecialIcons = filesRoot || fileBrowser && mrl != null && mrl.endsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
+ mFavorites = favorites;
}
@Override
@@ -117,7 +120,7 @@ public class BaseBrowserAdapter extends DiffUtilAdapter<MediaLibraryItem, BaseBr
private void onBindMediaViewHolder(final MediaViewHolder vh, int position) {
final MediaWrapper media = (MediaWrapper) getItem(position);
vh.binding.setItem(media);
- vh.binding.setHasContextMenu(true);
+ vh.binding.setHasContextMenu(!mNetworkRoot || mFavorites);
if (mNetworkRoot) vh.binding.setProtocol(getProtocol(media));
vh.binding.setCover(getIcon(media, mSpecialIcons));
vh.selectView(media.hasStateFlags(FLAG_SELECTED));
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 868c16883..48a4f8654 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -37,6 +37,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.widget.LinearLayoutManager;
+import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -78,7 +79,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
@Override
public void onChanged(@Nullable List<MediaLibraryItem> mediaLibraryItems) {
mBinding.setShowFavorites(!Util.isListEmpty(mediaLibraryItems));
- favoritesAdapter.submitList(mediaLibraryItems);
+ favoritesAdapter.update(mediaLibraryItems);
}
});
ExternalMonitor.connected.observe(this, new Observer<Boolean>() {
@@ -89,12 +90,22 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
});
}
- private SimpleAdapter favoritesAdapter;
+ protected void setContextMenuItems(Menu menu, int position) {
+ if (mRoot) {
+ menu.findItem(R.id.directory_view_play_folder).setVisible(false);
+ menu.findItem(R.id.directory_view_delete).setVisible(false);
+ final MediaWrapper mw = (MediaWrapper) favoritesAdapter.get(position);
+ menu.findItem(R.id.network_remove_favorite).setVisible(true);
+ menu.findItem(R.id.network_edit_favorite).setVisible(!TextUtils.equals(mw.getUri().getScheme(), "upnp"));
+ } else super.setContextMenuItems(menu, position);
+ }
+
+ private BaseBrowserAdapter favoritesAdapter;
@Override
protected void initFavorites() {
if (!mRoot) return;
mBinding.favoritesList.setLayoutManager(new LinearLayoutManager(getActivity()));
- favoritesAdapter = new SimpleAdapter(this);
+ favoritesAdapter = new BaseBrowserAdapter(this, true);
mBinding.favoritesList.setAdapter(favoritesAdapter);
}
@@ -167,7 +178,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
protected boolean handleContextItemSelected(MenuItem item, final int position) {
int id = item.getItemId();
if (!(mAdapter.getItem(position) instanceof MediaWrapper)) return false;
- final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
+ final MediaWrapper mw = (MediaWrapper) (mRoot ? favoritesAdapter.getItem(position) : mAdapter.getItem(position));
switch (id){
case R.id.network_add_favorite:
MediaDatabase.getInstance().addNetworkFavItem(mw.getUri(), mw.getTitle(), mw.getArtworkURL());
@@ -175,7 +186,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements Simpl
return true;
case R.id.network_remove_favorite:
MediaDatabase.getInstance().deleteNetworkFav(mw.getUri());
- if (isRootDirectory()) ((NetworkProvider)getProvider()).updateFavs();
+ if (mRoot) ((NetworkProvider)getProvider()).updateFavs();
return true;
case R.id.network_edit_favorite:
showAddServerDialog(mw);
More information about the Android
mailing list