[Android] Genres & Playlist ViewModels
Geoffrey Métais
git at videolan.org
Wed Apr 4 18:34:57 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 6 16:33:03 2018 +0100| [7ba2a453a643ca80218008993ef67bca1ae72d11] | committer: Geoffrey Métais
Genres & Playlist ViewModels
> https://code.videolan.org/videolan/vlc-android/commit/7ba2a453a643ca80218008993ef67bca1ae72d11
---
.../vlc/gui/audio/AudioBrowserFragment.java | 49 +++++++++-------------
.../vlc/viewmodels/audio/Genresprovider.kt | 13 ++++++
.../vlc/viewmodels/audio/PlaylistsProvider.kt | 13 ++++++
3 files changed, 45 insertions(+), 30 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 2fec3f506..1c5bfef1d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -29,7 +29,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
@@ -45,6 +44,7 @@ import android.widget.TextView;
import org.videolan.medialibrary.media.Album;
import org.videolan.medialibrary.media.Artist;
+import org.videolan.medialibrary.media.Genre;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.media.Playlist;
@@ -67,6 +67,8 @@ 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.Genresprovider;
+import org.videolan.vlc.viewmodels.audio.PlaylistsProvider;
import org.videolan.vlc.viewmodels.audio.TracksProvider;
import java.util.ArrayList;
@@ -86,6 +88,8 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
private ArtistProvider artistProvider;
private AlbumProvider albumProvider;
private TracksProvider tracksProvider;
+ private Genresprovider genresprovider;
+ private PlaylistsProvider playlistsProvider;
private ViewPager mViewPager;
private TabLayout mTabLayout;
@@ -93,7 +97,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
private final ContextMenuRecyclerView[] mLists = new ContextMenuRecyclerView[MODE_TOTAL];
private FastScroller mFastScroller;
- private static final int UPDATE_LIST = 102;
private static final int SET_REFRESHING = 103;
private static final int UNSET_REFRESHING = 104;
private static final int UPDATE_EMPTY_VIEW = 105;
@@ -119,6 +122,8 @@ 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);
+ genresprovider = ViewModelProviders.of(this).get(Genresprovider.class);
+ playlistsProvider = ViewModelProviders.of(this).get(PlaylistsProvider.class);
}
@Override
@@ -186,6 +191,18 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
if (tracks != null) mSongsAdapter.update(tracks);
}
});
+ genresprovider.getDataset().observe(this, new Observer<List<Genre>>() {
+ @Override
+ public void onChanged(@Nullable List<Genre> genres) {
+ if (genres != null) mGenresAdapter.update(genres);
+ }
+ });
+ playlistsProvider.getDataset().observe(this, new Observer<List<Playlist>>() {
+ @Override
+ public void onChanged(@Nullable List<Playlist> playlists) {
+ if (playlists != null) mPlaylistAdapter.update(playlists);
+ }
+ });
}
@Override
@@ -535,10 +552,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
final AudioBrowserFragment fragment = getOwner();
if (fragment == null) return;
switch (msg.what) {
- case UPDATE_LIST:
- removeMessages(UPDATE_LIST);
- fragment.updateLists();
- break;
case SET_REFRESHING:
fragment.mSwipeRefreshLayout.setRefreshing(true);
break;
@@ -552,34 +565,10 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
}
}
- @MainThread
- private void updateLists() {
- mTabLayout.setVisibility(View.VISIBLE);
- mHandler.sendEmptyMessageDelayed(SET_REFRESHING, 300);
-// updateSongs();
- updateGenres();
- updatePlaylists();
- }
-
public void updateArtists() {
artistProvider.refresh();
}
- private void updateGenres() {
- VLCApplication.runBackground(new Runnable() {
- @Override
- public void run() {
- final List<MediaLibraryItem> genres = Util.arrayToMediaArrayList(mMediaLibrary.getGenres());
- VLCApplication.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- mGenresAdapter.update(genres);
- }
- });
- }
- });
- }
-
private void updatePlaylists() {
VLCApplication.runBackground(new Runnable() {
@Override
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/Genresprovider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/Genresprovider.kt
new file mode 100644
index 000000000..6744dd9d6
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/Genresprovider.kt
@@ -0,0 +1,13 @@
+package org.videolan.vlc.viewmodels.audio
+
+import kotlinx.coroutines.experimental.async
+import org.videolan.medialibrary.media.Genre
+import org.videolan.vlc.viewmodels.MedialibraryModel
+
+
+class Genresprovider: MedialibraryModel<Genre>() {
+
+ override suspend fun updateList() {
+ dataset.value = async { medialibrary.genres.toMutableList() }.await()
+ }
+}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsProvider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsProvider.kt
new file mode 100644
index 000000000..8ddbaed72
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/audio/PlaylistsProvider.kt
@@ -0,0 +1,13 @@
+package org.videolan.vlc.viewmodels.audio
+
+import kotlinx.coroutines.experimental.async
+import org.videolan.medialibrary.media.Playlist
+import org.videolan.vlc.viewmodels.MedialibraryModel
+
+
+class PlaylistsProvider: MedialibraryModel<Playlist>() {
+
+ override suspend fun updateList() {
+ dataset.value = async { medialibrary.playlists.toMutableList() }.await()
+ }
+}
\ No newline at end of file
More information about the Android
mailing list