use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class BaseBrowserFragment method onClick.
public void onClick(View v, int position, MediaLibraryItem item) {
MediaWrapper mediaWrapper = (MediaWrapper) item;
if (mActionMode != null) {
if (mediaWrapper.getType() == MediaWrapper.TYPE_AUDIO || mediaWrapper.getType() == MediaWrapper.TYPE_VIDEO || mediaWrapper.getType() == MediaWrapper.TYPE_DIR) {
item.toggleStateFlag(MediaLibraryItem.FLAG_SELECTED);
mAdapter.updateSelectionCount(mediaWrapper.hasStateFlags(MediaLibraryItem.FLAG_SELECTED));
mAdapter.notifyItemChanged(position, item);
invalidateActionMode();
}
} else {
mediaWrapper.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
if (mediaWrapper.getType() == MediaWrapper.TYPE_DIR)
browse(mediaWrapper, position, true);
else
MediaUtils.openMedia(v.getContext(), mediaWrapper);
}
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class BaseBrowserFragment method setContextMenuItems.
protected void setContextMenuItems(Menu menu, int position) {
final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
if (mw == null)
return;
final int type = mw.getType();
boolean canWrite = this instanceof FileBrowserFragment;
if (type == MediaWrapper.TYPE_DIR) {
final boolean isEmpty = Util.isListEmpty(mFoldersContentLists.get(mw));
// if (canWrite) {
// boolean nomedia = new File(mw.getLocation() + "/.nomedia").exists();
// menu.findItem(R.id.directory_view_hide_media).setVisible(!nomedia);
// menu.findItem(R.id.directory_view_show_media).setVisible(nomedia);
// } else {
// menu.findItem(R.id.directory_view_hide_media).setVisible(false);
// menu.findItem(R.id.directory_view_show_media).setVisible(false);
// }
menu.findItem(R.id.directory_view_play_folder).setVisible(!isEmpty);
menu.findItem(R.id.directory_view_delete).setVisible(!mRoot && canWrite);
if (this instanceof NetworkBrowserFragment) {
MediaDatabase db = MediaDatabase.getInstance();
if (db.networkFavExists(mw.getUri())) {
menu.findItem(R.id.network_remove_favorite).setVisible(true);
menu.findItem(R.id.network_edit_favorite).setVisible(!TextUtils.equals(mw.getUri().getScheme(), "upnp"));
} else
menu.findItem(R.id.network_add_favorite).setVisible(true);
}
} else {
boolean canPlayInList = mw.getType() == MediaWrapper.TYPE_AUDIO || (mw.getType() == MediaWrapper.TYPE_VIDEO && AndroidUtil.isHoneycombOrLater);
menu.findItem(R.id.directory_view_play_all).setVisible(canPlayInList);
menu.findItem(R.id.directory_view_append).setVisible(canPlayInList);
menu.findItem(R.id.directory_view_delete).setVisible(canWrite);
menu.findItem(R.id.directory_view_info).setVisible(type == MediaWrapper.TYPE_VIDEO || type == MediaWrapper.TYPE_AUDIO);
menu.findItem(R.id.directory_view_play_audio).setVisible(type != MediaWrapper.TYPE_AUDIO);
menu.findItem(R.id.directory_view_add_playlist).setVisible(type == MediaWrapper.TYPE_AUDIO);
menu.findItem(R.id.directory_subtitles_download).setVisible(type == MediaWrapper.TYPE_VIDEO);
}
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class BaseBrowserFragment method handleContextItemSelected.
protected boolean handleContextItemSelected(MenuItem item, final int position) {
int id = item.getItemId();
if (!(mAdapter.getItem(position) instanceof MediaWrapper))
return super.onContextItemSelected(item);
final Uri uri = ((MediaWrapper) mAdapter.getItem(position)).getUri();
MediaWrapper mwFromMl = "file".equals(uri.getScheme()) ? mMediaLibrary.getMedia(uri) : null;
final MediaWrapper mw = mwFromMl != null ? mwFromMl : (MediaWrapper) mAdapter.getItem(position);
switch(id) {
case R.id.directory_view_play_all:
mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
playAll(mw);
return true;
case R.id.directory_view_append:
{
if (mService != null)
mService.append(mw);
return true;
}
case R.id.directory_view_delete:
if (checkWritePermission(mw, new Runnable() {
@Override
public void run() {
removeMedia(mw);
}
}))
removeMedia(mw);
return true;
case R.id.directory_view_info:
showMediaInfo(mw);
return true;
case R.id.directory_view_play_audio:
if (mService != null) {
mw.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
mService.load(mw);
}
return true;
case R.id.directory_view_play_folder:
MediaUtils.openMedia(getActivity(), mw);
return true;
case R.id.directory_view_add_playlist:
FragmentManager fm = getActivity().getSupportFragmentManager();
SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
Bundle infoArgs = new Bundle();
infoArgs.putParcelableArray(SavePlaylistDialog.KEY_NEW_TRACKS, mw.getTracks());
savePlaylistDialog.setArguments(infoArgs);
savePlaylistDialog.show(fm, "fragment_add_to_playlist");
return true;
case R.id.directory_subtitles_download:
MediaUtils.getSubs(getActivity(), mw);
return true;
}
return false;
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class BaseBrowserFragment method onLongClick.
public boolean onLongClick(View v, int position, MediaLibraryItem item) {
if (mActionMode != null || item.getItemType() != MediaLibraryItem.TYPE_MEDIA)
return false;
final MediaWrapper mediaWrapper = (MediaWrapper) item;
if (mediaWrapper.getType() == MediaWrapper.TYPE_AUDIO || mediaWrapper.getType() == MediaWrapper.TYPE_VIDEO || mediaWrapper.getType() == MediaWrapper.TYPE_DIR) {
if (mActionMode != null)
return false;
item.setStateFlags(MediaLibraryItem.FLAG_SELECTED);
mAdapter.updateSelectionCount(mediaWrapper.hasStateFlags(MediaLibraryItem.FLAG_SELECTED));
mAdapter.notifyItemChanged(position, item);
startActionMode();
} else
mRecyclerView.openContextMenu(position);
return true;
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class BaseBrowserFragment method getMediaWrapper.
@NonNull
private MediaWrapper getMediaWrapper(MediaWrapper media) {
MediaWrapper mw = null;
final Uri uri = media.getUri();
if ((media.getType() == MediaWrapper.TYPE_AUDIO || media.getType() == MediaWrapper.TYPE_VIDEO) && "file".equals(uri.getScheme()))
mw = mMediaLibrary.getMedia(uri);
return mw != null ? mw : media;
}
Aggregations