[Android] Tracks provider
Geoffrey Métais
git at videolan.org
Wed Apr 4 18:34:56 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 5 18:31:28 2018 +0100| [e7f0998582aeff91d48c6cad54ccc288d5113fa0] | committer: Geoffrey Métais
Tracks provider
> https://code.videolan.org/videolan/vlc-android/commit/e7f0998582aeff91d48c6cad54ccc288d5113fa0
---
.../vlc/gui/audio/AudioBrowserFragment.java | 40 ++++++----------------
.../vlc/viewmodels/audio/TracksProvider.kt | 20 +++++++++++
2 files changed, 31 insertions(+), 29 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 504066a46..2fec3f506 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -43,8 +43,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
-import org.videolan.medialibrary.interfaces.MediaAddedCb;
-import org.videolan.medialibrary.interfaces.MediaUpdatedCb;
import org.videolan.medialibrary.media.Album;
import org.videolan.medialibrary.media.Artist;
import org.videolan.medialibrary.media.MediaLibraryItem;
@@ -69,13 +67,14 @@ import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.WeakHandler;
import org.videolan.vlc.viewmodels.audio.AlbumProvider;
import org.videolan.vlc.viewmodels.audio.ArtistProvider;
+import org.videolan.vlc.viewmodels.audio.TracksProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
-public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, ViewPager.OnPageChangeListener, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener {
+public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, ViewPager.OnPageChangeListener, TabLayout.OnTabSelectedListener {
public final static String TAG = "VLC/AudioBrowserFragment";
private AudioBrowserAdapter mSongsAdapter;
@@ -86,6 +85,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
private ArtistProvider artistProvider;
private AlbumProvider albumProvider;
+ private TracksProvider tracksProvider;
private ViewPager mViewPager;
private TabLayout mTabLayout;
@@ -118,6 +118,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
artistProvider = ViewModelProviders.of(this).get(ArtistProvider.class);
albumProvider = ViewModelProviders.of(this).get(AlbumProvider.class);
+ tracksProvider = ViewModelProviders.of(this).get(TracksProvider.class);
}
@Override
@@ -179,6 +180,12 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
if (albums != null) mAlbumsAdapter.update(albums);
}
});
+ tracksProvider.getDataset().observe(this, new Observer<List<MediaWrapper>>() {
+ @Override
+ public void onChanged(@Nullable List<MediaWrapper> tracks) {
+ if (tracks != null) mSongsAdapter.update(tracks);
+ }
+ });
}
@Override
@@ -510,16 +517,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
}
}
- @Override
- public void onMediaAdded(MediaWrapper[] mediaList) {
- updateSongs();
- }
-
- @Override
- public void onMediaUpdated(MediaWrapper[] mediaList) {
- updateSongs();
- }
-
public AudioBrowserAdapter getCurrentAdapter() {
return (AudioBrowserAdapter) (getCurrentRV()).getAdapter();
}
@@ -559,7 +556,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
private void updateLists() {
mTabLayout.setVisibility(View.VISIBLE);
mHandler.sendEmptyMessageDelayed(SET_REFRESHING, 300);
- updateSongs();
+// updateSongs();
updateGenres();
updatePlaylists();
}
@@ -568,21 +565,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
artistProvider.refresh();
}
- private void updateSongs() {
- VLCApplication.runBackground(new Runnable() {
- @Override
- public void run() {
- final List<MediaLibraryItem> media = Util.arrayToMediaArrayList(mMediaLibrary.getAudio());
- VLCApplication.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- mSongsAdapter.update(media);
- }
- });
- }
- });
- }
-
private void updateGenres() {
VLCApplication.runBackground(new Runnable() {
@Override
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksProvider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksProvider.kt
new file mode 100644
index 000000000..fd0e8c364
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/TracksProvider.kt
@@ -0,0 +1,20 @@
+package org.videolan.vlc.viewmodels.audio
+
+import kotlinx.coroutines.experimental.async
+import org.videolan.medialibrary.media.MediaWrapper
+import org.videolan.vlc.viewmodels.MedialibraryModel
+
+
+class TracksProvider: MedialibraryModel<MediaWrapper>() {
+
+ override fun onMediaAdded(mediaList: Array<out MediaWrapper>?) {
+ refresh()
+ }
+
+ override fun onMediaUpdated(mediaList: Array<out MediaWrapper>?) {
+ refresh()
+ }
+ override suspend fun updateList() {
+ dataset.value = async { medialibrary.audio.toMutableList() }.await()
+ }
+}
\ No newline at end of file
More information about the Android
mailing list