Search in sources :

Example 86 with MediaWrapper

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);
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 87 with 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);
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaDatabase(org.videolan.vlc.media.MediaDatabase)

Example 88 with MediaWrapper

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;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) FragmentManager(android.support.v4.app.FragmentManager) Bundle(android.os.Bundle) Uri(android.net.Uri) SavePlaylistDialog(org.videolan.vlc.gui.dialogs.SavePlaylistDialog)

Example 89 with MediaWrapper

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;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 90 with MediaWrapper

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;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Aggregations

MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)157 ArrayList (java.util.ArrayList)36 MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)23 Bitmap (android.graphics.Bitmap)18 Intent (android.content.Intent)16 Uri (android.net.Uri)15 List (java.util.List)11 Bundle (android.os.Bundle)10 Context (android.content.Context)9 MediaGroup (org.videolan.vlc.media.MediaGroup)9 PendingIntent (android.app.PendingIntent)8 View (android.view.View)8 TargetApi (android.annotation.TargetApi)6 Cursor (android.database.Cursor)6 FragmentManager (android.support.v4.app.FragmentManager)6 File (java.io.File)6 LinkedList (java.util.LinkedList)6 Medialibrary (org.videolan.medialibrary.Medialibrary)6 SavePlaylistDialog (org.videolan.vlc.gui.dialogs.SavePlaylistDialog)6 SharedPreferences (android.content.SharedPreferences)5