[Android] Video player: Use playlist viewmodel as datasource
Geoffrey Métais
git at videolan.org
Tue Oct 30 12:00:02 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct 29 17:45:01 2018 +0100| [a9192ff3266cfc84db37d60088bc17ef99e1d92d] | committer: Geoffrey Métais
Video player: Use playlist viewmodel as datasource
> https://code.videolan.org/videolan/vlc-android/commit/a9192ff3266cfc84db37d60088bc17ef99e1d92d
---
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 1280f0dfd..2696d14bc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -731,13 +731,21 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
loadMedia();
}
+ private Observer<List<MediaWrapper>> mPlaylistObserver = new Observer<List<MediaWrapper>>() {
+ @Override
+ public void onChanged(List<MediaWrapper> mediaWrappers) {
+ if (mediaWrappers != null) mPlaylistAdapter.update(mediaWrappers);
+ }
+ };
+
private void initPlaylistUi() {
- if (mService.hasPlaylist()) {
+ if (mService != null && mService.hasPlaylist()) {
mHasPlaylist = true;
mPlaylistAdapter = new PlaylistAdapter(this);
mPlaylistModel = ViewModelProviders.of(this, new PlaylistModel.Factory(mService)).get(PlaylistModel.class);
mPlaylistModel.setup();
mPlaylistAdapter.setModel(mPlaylistModel);
+ mPlaylistModel.getDataset().observe(this, mPlaylistObserver);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mPlaylist.setLayoutManager(layoutManager);
@@ -1461,7 +1469,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
@Override
public void update() {
if (mService == null || mPlaylistAdapter == null) return;
- mPlaylistAdapter.update(mService.getMedias());
+ mPlaylistModel.update();
}
@Override
@@ -3171,6 +3179,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
@Override
public void onDisconnected() {
mService = null;
+ if (mPlaylistModel != null) mPlaylistModel.getDataset().removeObserver(mPlaylistObserver);
mHandler.sendEmptyMessage(AUDIO_SERVICE_CONNECTION_FAILED);
}
More information about the Android
mailing list