use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
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) {
final FragmentManager fm = getActivity().getSupportFragmentManager();
SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
final 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) {
final 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 (append)
MediaUtils.appendMedia(getActivity(), medias);
else if (insert_next)
MediaUtils.insertNext(getActivity(), medias);
else
MediaUtils.openArray(getActivity(), medias, startPosition);
return true;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
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);
final AudioBrowserAdapter adapter = pos == MODE_SONG ? mSongsAdapter : mPlaylistAdapter;
final 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);
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class AudioBrowserFragment method setupObservers.
private void setupObservers() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
artistProvider = ViewModelProviders.of(requireActivity(), new ArtistProvider.Factory(prefs.getBoolean(Constants.KEY_ARTISTS_SHOW_ALL, false))).get(ArtistProvider.class);
albumProvider = ViewModelProviders.of(requireActivity()).get(AlbumProvider.class);
tracksProvider = ViewModelProviders.of(requireActivity()).get(TracksProvider.class);
genresprovider = ViewModelProviders.of(requireActivity()).get(Genresprovider.class);
playlistsProvider = ViewModelProviders.of(requireActivity()).get(PlaylistsProvider.class);
mProvidersList = new AudioModel[] { artistProvider, albumProvider, tracksProvider, genresprovider, playlistsProvider };
// Register current tab first
final int currentTab = mViewPager.getCurrentItem();
mProvidersList[currentTab].getSections().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
public void onChanged(@Nullable List<MediaLibraryItem> items) {
if (items != null)
mAdapters[currentTab].update(items);
}
});
for (int i = 0; i < mProvidersList.length; ++i) {
if (i == currentTab)
continue;
final int index = i;
mProvidersList[i].getSections().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
public void onChanged(@Nullable List<MediaLibraryItem> items) {
if (items != null)
mAdapters[index].update(items);
}
});
}
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class BaseBrowserAdapter method prepareList.
@SuppressWarnings("unchecked")
@Override
protected List<MediaLibraryItem> prepareList(List<? extends MediaLibraryItem> list) {
final List<MediaLibraryItem> internalList = new ArrayList<>(list);
mMediaCount = 0;
for (MediaLibraryItem item : internalList) {
if (item.getItemType() == MediaLibraryItem.TYPE_MEDIA && (((MediaWrapper) item).getType() == MediaWrapper.TYPE_AUDIO || ((MediaWrapper) item).getType() == MediaWrapper.TYPE_VIDEO))
++mMediaCount;
}
return internalList;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class StorageBrowserAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final MediaViewHolder vh = (MediaViewHolder) holder;
MediaLibraryItem storage = getItem(position);
if (storage.getItemType() == MediaLibraryItem.TYPE_MEDIA)
storage = new Storage(((MediaWrapper) storage).getUri());
String storagePath = ((Storage) storage).getUri().getPath();
if (!storagePath.endsWith("/"))
storagePath += "/";
boolean hasContextMenu = mCustomDirsLocation.contains(storagePath);
boolean checked = ((StorageBrowserFragment) fragment).mScannedDirectory || mMediaDirsLocation.contains(storagePath);
vh.binding.setItem(storage);
vh.binding.setHasContextMenu(hasContextMenu);
if (checked)
vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_CHECKED);
else if (hasDiscoveredChildren(storagePath))
vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_PARTIAL);
else
vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_UNCHECKED);
vh.binding.setCheckEnabled(!((StorageBrowserFragment) fragment).mScannedDirectory);
}
Aggregations