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