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);
}
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));
}
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);
}
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;
}
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);
}
Aggregations