Search in sources :

Example 26 with MediaLibraryItem

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

the class CardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item, List<Object> payloads) {
    if (payloads.isEmpty())
        onBindViewHolder(viewHolder, item);
    else {
        final ViewHolder holder = ((ViewHolder) viewHolder);
        final MediaLibraryItem media = (MediaLibraryItem) item;
        for (Object data : payloads) {
            switch((int) data) {
                case Constants.UPDATE_DESCRIPTION:
                    holder.mCardView.setContentText(media.getDescription());
                    break;
                case Constants.UPDATE_THUMB:
                    AsyncImageLoader.loadPicture(holder.mCardView, media);
                    break;
                case Constants.UPDATE_TIME:
                    final MediaWrapper mediaWrapper = (MediaWrapper) item;
                    Tools.setMediaDescription(mediaWrapper);
                    holder.mCardView.setContentText(mediaWrapper.getDescription());
                    // update seen check if time is reset to 0
                    if (mediaWrapper.getTime() > 0)
                        break;
                case Constants.UPDATE_SEEN:
                    final MediaWrapper mw = (MediaWrapper) item;
                    if (mIsSeenMediaMarkerVisible && mw.getType() == MediaWrapper.TYPE_VIDEO && mw.getSeen() > 0L)
                        holder.mCardView.setBadgeImage(ContextCompat.getDrawable(mContext, R.drawable.ic_seen_tv_normal));
                    break;
            }
        }
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 27 with MediaLibraryItem

use of org.videolan.medialibrary.media.MediaLibraryItem 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 28 with MediaLibraryItem

use of org.videolan.medialibrary.media.MediaLibraryItem 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 29 with MediaLibraryItem

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

the class InfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBinding = DataBindingUtil.setContentView(this, R.layout.info_activity);
    initAudioPlayerContainerActivity();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mItem = (MediaLibraryItem) (savedInstanceState != null ? savedInstanceState.getParcelable(TAG_ITEM) : getIntent().getParcelableExtra(TAG_ITEM));
    if (mItem == null) {
        finish();
        return;
    }
    if (mItem.getId() == 0L) {
        MediaLibraryItem libraryItem = VLCApplication.getMLInstance().getMedia(((MediaWrapper) mItem).getUri());
        if (libraryItem != null)
            mItem = libraryItem;
    }
    mBinding.setItem(mItem);
    final int fabVisibility = savedInstanceState != null ? savedInstanceState.getInt(TAG_FAB_VISIBILITY) : -1;
    if (!TextUtils.isEmpty(mItem.getArtworkMrl())) {
        VLCApplication.runBackground(new Runnable() {

            @Override
            public void run() {
                final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(mItem.getArtworkMrl()), 0);
                if (cover != null) {
                    mBinding.setCover(new BitmapDrawable(InfoActivity.this.getResources(), cover));
                    VLCApplication.runOnMainThread(new Runnable() {

                        @Override
                        public void run() {
                            ViewCompat.setNestedScrollingEnabled(mBinding.container, true);
                            mBinding.appbar.setExpanded(true, true);
                            if (fabVisibility != -1)
                                mBinding.fab.setVisibility(fabVisibility);
                        }
                    });
                } else
                    noCoverFallback();
            }
        });
    } else
        noCoverFallback();
    mBinding.fab.setOnClickListener(this);
    if (mItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
        mAdapter = new MediaInfoAdapter();
        mBinding.list.setLayoutManager(new LinearLayoutManager(mBinding.getRoot().getContext()));
        mBinding.list.setAdapter(mAdapter);
        mCheckFileTask = (CheckFileTask) new CheckFileTask().execute();
        mParseTracksTask = (ParseTracksTask) new ParseTracksTask().execute();
    }
    VLCApplication.runBackground(new Runnable() {

        @Override
        public void run() {
            updateMeta();
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MediaInfoAdapter(org.videolan.vlc.gui.video.MediaInfoAdapter)

Example 30 with MediaLibraryItem

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

the class PlaylistActivity method removeFromPlaylist.

private void removeFromPlaylist(final List<MediaWrapper> list) {
    final List<MediaLibraryItem> oldAdapter = new ArrayList<>(mAdapter.getAll());
    for (MediaLibraryItem mediaItem : list) mAdapter.remove(mediaItem);
    UiTools.snackerWithCancel(mBinding.getRoot(), getString(R.string.file_deleted), new Runnable() {

        @Override
        public void run() {
            for (MediaLibraryItem mediaItem : list) ((Playlist) mPlaylist).remove(mediaItem.getId());
            if (mPlaylist.getTracks().length == 0)
                ((Playlist) mPlaylist).delete();
        }
    }, new Runnable() {

        @Override
        public void run() {
            mAdapter.update(oldAdapter);
        }
    });
}
Also used : Playlist(org.videolan.medialibrary.media.Playlist) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Aggregations

MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)46 ArrayList (java.util.ArrayList)25 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)23 Bitmap (android.graphics.Bitmap)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)8 List (java.util.List)7 View (android.view.View)6 RecyclerView (android.support.v7.widget.RecyclerView)5 TextView (android.widget.TextView)4 Playlist (org.videolan.medialibrary.media.Playlist)4 Bundle (android.os.Bundle)3 LinkedList (java.util.LinkedList)3 Storage (org.videolan.medialibrary.media.Storage)3 ContextMenuRecyclerView (org.videolan.vlc.gui.view.ContextMenuRecyclerView)3 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 WorkerThread (android.support.annotation.WorkerThread)2 TextInputLayout (android.support.design.widget.TextInputLayout)2 ImageCardView (android.support.v17.leanback.widget.ImageCardView)2