Search in sources :

Example 6 with MediaLibraryItem

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

the class AudioAlbumsSongsFragment method handleContextItemSelected.

protected boolean handleContextItemSelected(MenuItem item, final int position) {
    int startPosition;
    MediaWrapper[] medias;
    int id = item.getItemId();
    final AudioBrowserAdapter adapter = mViewPager.getCurrentItem() == MODE_ALBUM ? mAlbumsAdapter : mSongsAdapter;
    final MediaLibraryItem mediaItem = adapter.getItem(position);
    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;
    if (id == R.id.audio_list_browser_delete) {
        adapter.remove(mediaItem);
        final Runnable cancel = new Runnable() {

            @Override
            public void run() {
                adapter.addItems(mediaItem);
            }
        };
        UiTools.snackerWithCancel(mViewPager, getString(R.string.file_deleted), new Runnable() {

            @Override
            public void run() {
                deleteMedia(mediaItem, true, cancel);
            }
        }, cancel);
        return true;
    }
    if (id == R.id.audio_list_browser_set_song) {
        AudioUtil.setRingtone((MediaWrapper) mediaItem, getActivity());
        return true;
    }
    if (id == R.id.audio_view_info) {
        showInfoDialog((MediaWrapper) mediaItem);
        return true;
    }
    if (id == R.id.audio_view_add_playlist) {
        FragmentManager fm = getActivity().getSupportFragmentManager();
        SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
        Bundle args = new Bundle();
        args.putParcelableArray(SavePlaylistDialog.KEY_NEW_TRACKS, mediaItem.getTracks());
        savePlaylistDialog.setArguments(args);
        savePlaylistDialog.show(fm, "fragment_add_to_playlist");
        return true;
    }
    if (useAllItems) {
        List<MediaLibraryItem> items = new ArrayList<>();
        startPosition = mSongsAdapter.getListWithPosition(items, position);
        medias = items.toArray(new MediaWrapper[items.size()]);
    } else {
        startPosition = 0;
        if (mediaItem instanceof Album)
            medias = mediaItem.getTracks();
        else
            medias = new MediaWrapper[] { (MediaWrapper) mediaItem };
    }
    if (mService != null) {
        if (append)
            mService.append(medias);
        else if (insert_next)
            mService.insertNext(medias);
        else
            mService.load(medias, startPosition);
        return true;
    }
    return false;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Album(org.videolan.medialibrary.media.Album) SavePlaylistDialog(org.videolan.vlc.gui.dialogs.SavePlaylistDialog) FragmentManager(android.support.v4.app.FragmentManager)

Example 7 with MediaLibraryItem

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

the class AudioAlbumsSongsFragment method onFabPlayClick.

@Override
@SuppressWarnings("unchecked")
public void onFabPlayClick(View view) {
    if (mService == null)
        return;
    final List<MediaWrapper> list;
    if (mViewPager.getCurrentItem() == 0) {
        list = new ArrayList<>();
        for (MediaLibraryItem item : mAlbumsAdapter.getMediaItems()) list.addAll(Util.arrayToArrayList(item.getTracks()));
    } else {
        list = (List<MediaWrapper>) (List<?>) mSongsAdapter.getMediaItems();
    }
    mService.load(list, 0);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with MediaLibraryItem

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

the class AudioAlbumsSongsFragment method setContextMenuItems.

protected void setContextMenuItems(Menu menu, int position) {
    if (mViewPager.getCurrentItem() != MODE_SONG) {
        menu.setGroupVisible(R.id.songs_view_only, false);
        menu.setGroupVisible(R.id.phone_only, false);
    }
    if (!AndroidDevices.isPhone)
        menu.setGroupVisible(R.id.phone_only, false);
    menu.findItem(R.id.audio_list_browser_play).setVisible(true);
    // Hide delete if we cannot
    final AudioBrowserAdapter adapter = mViewPager.getCurrentItem() == MODE_ALBUM ? mAlbumsAdapter : mSongsAdapter;
    final MediaLibraryItem mediaItem = adapter.getItem(position);
    String location = mediaItem instanceof MediaWrapper ? ((MediaWrapper) mediaItem).getLocation() : null;
    menu.findItem(R.id.audio_list_browser_delete).setVisible(location != null && FileUtils.canWrite(location));
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 9 with MediaLibraryItem

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

the class AudioBrowserAdapter method remove.

public void remove(final MediaLibraryItem... items) {
    final List<MediaLibraryItem> referenceList = peekLast();
    if (referenceList.isEmpty())
        return;
    final List<MediaLibraryItem> dataList = new ArrayList<>(referenceList);
    for (MediaLibraryItem item : items) dataList.remove(item);
    update(dataList);
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Example 10 with MediaLibraryItem

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

the class AudioBrowserAdapter method generateSections.

private List<MediaLibraryItem> generateSections(List<? extends MediaLibraryItem> items, int sortby) {
    List<MediaLibraryItem> datalist = new ArrayList<>();
    switch(sortby) {
        case MediaLibraryItemComparator.SORT_BY_TITLE:
            String currentLetter = null;
            for (MediaLibraryItem item : items) {
                if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
                    continue;
                String title = item.getTitle();
                String letter = (title.isEmpty() || !Character.isLetter(title.charAt(0))) ? "#" : title.substring(0, 1).toUpperCase();
                if (currentLetter == null || !TextUtils.equals(currentLetter, letter)) {
                    currentLetter = letter;
                    DummyItem sep = new DummyItem(currentLetter);
                    datalist.add(sep);
                }
                datalist.add(item);
            }
            break;
        case MediaLibraryItemComparator.SORT_BY_ARTIST:
            String currentArtist = null;
            for (MediaLibraryItem item : items) {
                if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
                    continue;
                String artist = ((MediaWrapper) item).getArtist();
                if (artist == null)
                    artist = "";
                if (currentArtist == null || !TextUtils.equals(currentArtist, artist)) {
                    currentArtist = artist;
                    DummyItem sep = new DummyItem(TextUtils.isEmpty(currentArtist) ? VLCApplication.getAppResources().getString(R.string.unknown_artist) : currentArtist);
                    datalist.add(sep);
                }
                datalist.add(item);
            }
            break;
        case MediaLibraryItemComparator.SORT_BY_ALBUM:
            String currentAlbum = null;
            for (MediaLibraryItem item : items) {
                if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
                    continue;
                String album = ((MediaWrapper) item).getAlbum();
                if (album == null)
                    album = "";
                if (currentAlbum == null || !TextUtils.equals(currentAlbum, album)) {
                    currentAlbum = album;
                    DummyItem sep = new DummyItem(TextUtils.isEmpty(currentAlbum) ? VLCApplication.getAppResources().getString(R.string.unknown_album) : currentAlbum);
                    datalist.add(sep);
                }
                datalist.add(item);
            }
            break;
        case MediaLibraryItemComparator.SORT_BY_LENGTH:
            String currentLengthCategory = null;
            for (MediaLibraryItem item : items) {
                if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
                    continue;
                int length = MediaLibraryItemComparator.getLength(item);
                String lengthCategory = MediaLibraryItemComparator.lengthToCategory(length);
                if (currentLengthCategory == null || !TextUtils.equals(currentLengthCategory, lengthCategory)) {
                    currentLengthCategory = lengthCategory;
                    DummyItem sep = new DummyItem(currentLengthCategory);
                    datalist.add(sep);
                }
                datalist.add(item);
            }
            break;
        case MediaLibraryItemComparator.SORT_BY_DATE:
            String currentYear = null;
            for (MediaLibraryItem item : items) {
                if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
                    continue;
                String year = MediaLibraryItemComparator.getYear(item);
                if (currentYear == null || !TextUtils.equals(currentYear, year)) {
                    currentYear = year;
                    DummyItem sep = new DummyItem(currentYear);
                    datalist.add(sep);
                }
                datalist.add(item);
            }
            break;
        case MediaLibraryItemComparator.SORT_BY_NUMBER:
            int currentNumber = 0;
            for (MediaLibraryItem item : items) {
                if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
                    continue;
                int number = MediaLibraryItemComparator.getTracksCount(item);
                if (currentNumber != number) {
                    currentNumber = number;
                    DummyItem sep = new DummyItem(currentNumber == 0 ? VLCApplication.getAppResources().getString(R.string.unknown_number) : VLCApplication.getAppResources().getQuantityString(R.plurals.songs_quantity, currentNumber, currentNumber));
                    datalist.add(sep);
                }
                datalist.add(item);
            }
            break;
    }
    return datalist;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) DummyItem(org.videolan.medialibrary.media.DummyItem) 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