Search in sources :

Example 26 with MediaWrapper

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

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

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

the class AudioAlbumsSongsFragment method onClick.

@Override
public void onClick(View v, int position, MediaLibraryItem item) {
    if (mActionMode != null) {
        super.onClick(v, position, item);
        return;
    }
    if (item instanceof Album) {
        Intent i = new Intent(getActivity(), PlaylistActivity.class);
        i.putExtra(AudioBrowserFragment.TAG_ITEM, item);
        startActivity(i);
    } else
        MediaUtils.openMedia(v.getContext(), (MediaWrapper) item);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Album(org.videolan.medialibrary.media.Album) Intent(android.content.Intent)

Example 29 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper 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)

Example 30 with MediaWrapper

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

the class AudioBrowserFragment method setContextMenuItems.

protected void setContextMenuItems(Menu menu, int position) {
    final int pos = mViewPager.getCurrentItem();
    if (pos != MODE_SONG) {
        menu.setGroupVisible(R.id.songs_view_only, false);
        menu.setGroupVisible(R.id.phone_only, false);
    }
    if (pos == MODE_ARTIST || pos == MODE_GENRE || pos == MODE_ALBUM)
        menu.findItem(R.id.audio_list_browser_play).setVisible(true);
    if (pos != MODE_SONG && pos != MODE_PLAYLIST)
        menu.findItem(R.id.audio_list_browser_delete).setVisible(false);
    else {
        final MenuItem item = menu.findItem(R.id.audio_list_browser_delete);
        AudioBrowserAdapter adapter = pos == MODE_SONG ? mSongsAdapter : mPlaylistAdapter;
        MediaLibraryItem mediaItem = adapter.getItem(position);
        if (pos == MODE_PLAYLIST)
            item.setVisible(true);
        else {
            String location = ((MediaWrapper) mediaItem).getLocation();
            item.setVisible(FileUtils.canWrite(location));
        }
    }
    if (!AndroidDevices.isPhone)
        menu.setGroupVisible(R.id.phone_only, false);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) MenuItem(android.view.MenuItem)

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