Search in sources :

Example 41 with MediaLibraryItem

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;
}
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 42 with MediaLibraryItem

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);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) MenuItem(android.view.MenuItem)

Example 43 with MediaLibraryItem

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);
            }
        });
    }
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) SharedPreferences(android.content.SharedPreferences) ArtistProvider(org.videolan.vlc.viewmodels.audio.ArtistProvider) PlaylistsProvider(org.videolan.vlc.viewmodels.audio.PlaylistsProvider) AlbumProvider(org.videolan.vlc.viewmodels.audio.AlbumProvider) TracksProvider(org.videolan.vlc.viewmodels.audio.TracksProvider) List(java.util.List) ArrayList(java.util.ArrayList) Genresprovider(org.videolan.vlc.viewmodels.audio.Genresprovider)

Example 44 with MediaLibraryItem

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;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Example 45 with MediaLibraryItem

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);
}
Also used : Storage(org.videolan.medialibrary.media.Storage) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

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