[Android] Audio view: Load current tab content first
Geoffrey Métais
git at videolan.org
Wed Apr 4 18:35:23 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 15 16:51:33 2018 +0100| [69f524e1169d7b1ef12a056d50030343093ee72a] | committer: Geoffrey Métais
Audio view: Load current tab content first
> https://code.videolan.org/videolan/vlc-android/commit/69f524e1169d7b1ef12a056d50030343093ee72a
---
.../vlc/gui/audio/AudioBrowserFragment.java | 43 ++++++++--------------
1 file changed, 15 insertions(+), 28 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index f40af9b8c..5722fc72f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -172,37 +172,24 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
genresprovider = ViewModelProviders.of(this).get(Genresprovider.class);
playlistsProvider = ViewModelProviders.of(this).get(PlaylistsProvider.class);
mProvidersList = new AudioModel[] {artistProvider, albumProvider, tracksProvider, genresprovider, playlistsProvider};
-
- artistProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
- @Override
- public void onChanged(@Nullable List<MediaLibraryItem> artists) {
- if (artists != null) mArtistsAdapter.update(artists);
- }
- });
- albumProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
- @Override
- public void onChanged(@Nullable List<MediaLibraryItem> albums) {
- if (albums != null) mAlbumsAdapter.update(albums);
- }
- });
- tracksProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
+ //Register current tab first
+ final int currentTab = mViewPager.getCurrentItem();
+ mProvidersList[currentTab].getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
- public void onChanged(@Nullable List<MediaLibraryItem> tracks) {
- if (tracks != null) mSongsAdapter.update(tracks);
- }
- });
- genresprovider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
- @Override
- public void onChanged(@Nullable List<MediaLibraryItem> genres) {
- if (genres != null) mGenresAdapter.update(genres);
- }
- });
- playlistsProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
- @Override
- public void onChanged(@Nullable List<MediaLibraryItem> playlists) {
- if (playlists != null) mPlaylistAdapter.update(playlists);
+ 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].getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
+ @Override
+ public void onChanged(@Nullable List<MediaLibraryItem> items) {
+ if (items != null) mAdapters[index].update(items);
+ }
+ });
+ }
}
private void setupTabLayout() {
More information about the Android
mailing list