Commit c387248f authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Fix network favorites

parent 0da6f148
......@@ -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
......
......@@ -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));
......
......@@ -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);
......
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