Search in sources :

Example 76 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.

the class AudioBrowserFragment method handleContextItemSelected.

protected boolean handleContextItemSelected(final MenuItem item, final int position) {
    final int mode = mViewPager.getCurrentItem();
    final AudioBrowserAdapter adapter = mAdapters[mode];
    if (position < 0 && position >= adapter.getItemCount())
        return false;
    final int id = item.getItemId();
    final MediaLibraryItem mediaItem = adapter.getItem(position);
    if (id == R.id.audio_list_browser_delete) {
        final MediaLibraryItem previous = position > 0 ? adapter.getItem(position - 1) : null;
        final MediaLibraryItem next = position < adapter.getItemCount() - 1 ? adapter.getItem(position + 1) : null;
        final String message;
        final Runnable action;
        final Runnable cancel;
        final MediaLibraryItem separator = previous != null && previous.getItemType() == MediaLibraryItem.TYPE_DUMMY && (next == null || next.getItemType() == MediaLibraryItem.TYPE_DUMMY) ? previous : null;
        if (separator != null)
            adapter.remove(separator, mediaItem);
        else
            adapter.remove(mediaItem);
        if (mode == MODE_PLAYLIST) {
            cancel = null;
            message = getString(R.string.playlist_deleted);
            action = new Runnable() {

                @Override
                public void run() {
                    deletePlaylist((Playlist) mediaItem);
                }
            };
        } else if (mode == MODE_SONG) {
            message = getString(R.string.file_deleted);
            cancel = new Runnable() {

                @Override
                public void run() {
                    if (separator != null)
                        adapter.addItems(separator, mediaItem);
                    else
                        adapter.addItems(mediaItem);
                }
            };
            action = new Runnable() {

                @Override
                public void run() {
                    deleteMedia(mediaItem, true, cancel);
                }
            };
            if (!checkWritePermission((MediaWrapper) mediaItem, new Runnable() {

                @Override
                public void run() {
                    final View v = getView();
                    if (v != null)
                        UiTools.snackerWithCancel(getView(), message, action, cancel);
                }
            }))
                return false;
        } else
            return false;
        final View v = getView();
        if (v != null)
            UiTools.snackerWithCancel(getView(), message, action, cancel);
        return true;
    }
    if (id == R.id.audio_list_browser_set_song) {
        if (mSongsAdapter.getItemCount() <= position)
            return false;
        AudioUtil.setRingtone((MediaWrapper) mSongsAdapter.getItem(position), getActivity());
        return true;
    }
    if (id == R.id.audio_view_info) {
        showInfoDialog(mSongsAdapter.getItem(position));
        return true;
    }
    if (id == R.id.audio_view_add_playlist) {
        UiTools.addToPlaylist(getActivity(), mediaItem.getTracks(), SavePlaylistDialog.KEY_NEW_TRACKS);
        return true;
    }
    int startPosition;
    MediaWrapper[] medias;
    boolean useAllItems = id == R.id.audio_list_browser_play_all;
    boolean append = id == R.id.audio_list_browser_append;
    boolean insert_next = id == R.id.audio_list_browser_insert_next;
    // Play/Append
    if (useAllItems) {
        if (mSongsAdapter.getItemCount() <= position)
            return false;
        final List<MediaLibraryItem> mediaList = new ArrayList<>();
        startPosition = mSongsAdapter.getListWithPosition(mediaList, position);
        medias = Arrays.copyOf(mediaList.toArray(), mediaList.size(), MediaWrapper[].class);
    } else {
        startPosition = 0;
        if (position >= adapter.getItemCount())
            return false;
        medias = mediaItem.getTracks();
    }
    if (mService != null) {
        if (append)
            mService.append(medias);
        else if (insert_next)
            mService.insertNext(medias);
        else
            mService.load(medias, startPosition);
        return true;
    } else
        return false;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList) View(android.view.View) ContextMenuRecyclerView(org.videolan.vlc.gui.view.ContextMenuRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Playlist(org.videolan.medialibrary.media.Playlist)

Example 77 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.

the class BaseAudioBrowser method onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    List<MediaLibraryItem> list = getCurrentAdapter().getSelection();
    stopActionMode();
    if (!list.isEmpty()) {
        List<MediaWrapper> tracks = new ArrayList<>();
        for (MediaLibraryItem mediaItem : list) tracks.addAll(Arrays.asList(mediaItem.getTracks()));
        switch(item.getItemId()) {
            case R.id.action_mode_audio_play:
                mService.load(tracks, 0);
                break;
            case R.id.action_mode_audio_append:
                mService.append(tracks);
                break;
            case R.id.action_mode_audio_add_playlist:
                UiTools.addToPlaylist(getActivity(), tracks);
                break;
            case R.id.action_mode_audio_info:
                showInfoDialog(list.get(0));
                break;
            case R.id.action_mode_audio_set_song:
                AudioUtil.setRingtone((MediaWrapper) list.get(0), getActivity());
                break;
            default:
                return false;
        }
    }
    return true;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Example 78 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.

the class PlaylistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final Context ctx = holder.itemView.getContext();
    final MediaWrapper media = getItem(position);
    holder.binding.setMedia(media);
    holder.binding.setSubTitle(MediaUtils.getMediaSubtitle(media));
    holder.binding.setTitleColor(mOriginalDataSet == null && mCurrentIndex == position ? UiTools.getColorFromAttribute(ctx, R.attr.list_title_last) : UiTools.getColorFromAttribute(ctx, R.attr.list_title));
    holder.binding.executePendingBindings();
}
Also used : Context(android.content.Context) MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 79 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.

the class BaseBrowserAdapter method onBindMediaViewHolder.

private void onBindMediaViewHolder(final MediaViewHolder vh, int position) {
    final MediaWrapper media = (MediaWrapper) getItem(position);
    vh.binding.setItem(media);
    vh.binding.setHasContextMenu(true);
    if (mNetworkRoot)
        vh.binding.setProtocol(getProtocol(media));
    vh.binding.setCover(getIcon(media, mSpecialIcons));
    vh.selectView(media.hasStateFlags(FLAG_SELECTED));
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 80 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.

the class HistoryAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final MediaWrapper media = mMediaList.get(position);
    boolean isSelected = media.hasStateFlags(MediaLibraryItem.FLAG_SELECTED);
    holder.binding.setMedia(media);
    holder.selectView(isSelected);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

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