Search in sources :

Example 1 with PlaylistsProvider

use of org.videolan.vlc.viewmodels.audio.PlaylistsProvider 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)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)1 AlbumProvider (org.videolan.vlc.viewmodels.audio.AlbumProvider)1 ArtistProvider (org.videolan.vlc.viewmodels.audio.ArtistProvider)1 Genresprovider (org.videolan.vlc.viewmodels.audio.Genresprovider)1 PlaylistsProvider (org.videolan.vlc.viewmodels.audio.PlaylistsProvider)1 TracksProvider (org.videolan.vlc.viewmodels.audio.TracksProvider)1