use of org.videolan.vlc.viewmodels.audio.TracksProvider in project vlc-android by GeoffreyMetais.
the class PlaylistActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.playlist_activity);
initAudioPlayerContainerActivity();
mFragmentContainer = findViewById(R.id.container_list);
mOriginalBottomPadding = mFragmentContainer.getPaddingBottom();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mPlaylist = (MediaLibraryItem) (savedInstanceState != null ? savedInstanceState.getParcelable(AudioBrowserFragment.TAG_ITEM) : getIntent().getParcelableExtra(AudioBrowserFragment.TAG_ITEM));
mIsPlaylist = mPlaylist.getItemType() == MediaLibraryItem.TYPE_PLAYLIST;
mBinding.setPlaylist(mPlaylist);
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this);
mBinding.songs.setLayoutManager(new LinearLayoutManager(this));
mBinding.songs.setAdapter(mAdapter);
tracksProvider = ViewModelProviders.of(this, new TracksProvider.Factory(mPlaylist)).get(TracksProvider.class);
tracksProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
public void onChanged(@Nullable List<MediaLibraryItem> tracks) {
if (tracks != null)
mAdapter.update(tracks);
}
});
final int fabVisibility = savedInstanceState != null ? savedInstanceState.getInt(TAG_FAB_VISIBILITY) : -1;
if (!TextUtils.isEmpty(mPlaylist.getArtworkMrl())) {
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(mPlaylist.getArtworkMrl()), 0);
if (cover != null) {
mBinding.setCover(new BitmapDrawable(PlaylistActivity.this.getResources(), cover));
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
mBinding.appbar.setExpanded(true, true);
if (fabVisibility != -1)
mBinding.fab.setVisibility(fabVisibility);
}
});
} else
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
fabFallback();
}
});
}
});
} else
fabFallback();
mBinding.fab.setOnClickListener(this);
}
use of org.videolan.vlc.viewmodels.audio.TracksProvider 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);
}
});
}
}
Aggregations