[Android] Call audio list updates from main thread
Geoffrey Métais
git at videolan.org
Thu Feb 23 10:33:26 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 23 10:23:45 2017 +0100| [2488ed1c14ab41a67ba923daadd33cf4dd7118e8] | committer: Geoffrey Métais
Call audio list updates from main thread
> https://code.videolan.org/videolan/vlc-android/commit/2488ed1c14ab41a67ba923daadd33cf4dd7118e8
---
.../vlc/gui/audio/AudioAlbumsSongsFragment.java | 6 +-
.../vlc/gui/audio/AudioBrowserFragment.java | 124 ++++++++++++++++-----
2 files changed, 101 insertions(+), 29 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index ffbe905..a073ea0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -275,8 +275,7 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
albums = ((Genre) mItem).getAlbums(mMediaLibrary);
else
return;
- mAlbumsAdapter.update(albums);
- LinkedList<MediaLibraryItem> songs = new LinkedList<>();
+ final LinkedList<MediaLibraryItem> songs = new LinkedList<>();
for (Album album : albums) {
String title = album.getTitle();
if (TextUtils.isEmpty(title))
@@ -284,10 +283,11 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
songs.add(new DummyItem(title));
songs.addAll(Arrays.asList(album.getTracks(mMediaLibrary)));
}
- mSongsAdapter.update(songs.toArray(new MediaLibraryItem[songs.size()]));
mHandler.post(new Runnable() {
@Override
public void run() {
+ mAlbumsAdapter.update(albums);
+ mSongsAdapter.update(songs.toArray(new MediaLibraryItem[songs.size()]));
mFastScroller.setRecyclerView(mLists[mViewPager.getCurrentItem()]);
mSwipeRefreshLayout.setRefreshing(false);
}
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 f6b60f5..ad7dc38 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -48,6 +48,9 @@ import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
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.Genre;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.media.Playlist;
@@ -556,6 +559,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
if (adapter == getCurrentAdapter()) {
+ mHandler.sendEmptyMessage(UNSET_REFRESHING);
mSwipeRefreshLayout.setEnabled(((LinearLayoutManager)getCurrentRV().getLayoutManager()).findFirstVisibleItemPosition() <= 0);
updateEmptyView(mViewPager.getCurrentItem());
mFastScroller.setRecyclerView(getCurrentRV());
@@ -564,44 +568,98 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
@Override
public void onArtistsAdded() {
- mArtistsAdapter.update(mMediaLibrary.getArtists());
- if (mViewPager.getCurrentItem() == MODE_ARTIST)
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ VLCApplication.runBackground(new Runnable() {
+ final Artist[] artists = mMediaLibrary.getArtists();
+ @Override
+ public void run() {
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(artists);
+ }
+ });
+ }
+ });
}
@Override
public void onArtistsModified() {
- mArtistsAdapter.update(mMediaLibrary.getArtists());
- if (mViewPager.getCurrentItem() == MODE_ARTIST)
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ VLCApplication.runBackground(new Runnable() {
+ final Artist[] artists = mMediaLibrary.getArtists();
+ @Override
+ public void run() {
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(artists);
+ }
+ });
+ }
+ });
}
@Override
public void onAlbumsAdded() {
- mAlbumsAdapter.update(mMediaLibrary.getAlbums());
- if (mViewPager.getCurrentItem() == MODE_ALBUM)
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ VLCApplication.runBackground(new Runnable() {
+ final Album[] albums = mMediaLibrary.getAlbums();
+ @Override
+ public void run() {
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(albums);
+ }
+ });
+ }
+ });
}
@Override
public void onAlbumsModified() {
- mAlbumsAdapter.update(mMediaLibrary.getAlbums());
- if (mViewPager.getCurrentItem() == MODE_ALBUM)
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ VLCApplication.runBackground(new Runnable() {
+ final Album[] albums = mMediaLibrary.getAlbums();
+ @Override
+ public void run() {
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(albums);
+ }
+ });
+ }
+ });
}
@Override
public void onMediaAdded(MediaWrapper[] mediaList) {
- mSongsAdapter.update(mMediaLibrary.getAudio());
- if (mViewPager.getCurrentItem() == MODE_SONG)
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ VLCApplication.runBackground(new Runnable() {
+ final MediaWrapper[] media = mMediaLibrary.getAudio();
+ @Override
+ public void run() {
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(media);
+ }
+ });
+ }
+ });
}
@Override
public void onMediaUpdated(MediaWrapper[] mediaList) {
- mSongsAdapter.update(mMediaLibrary.getAudio());
- if (mViewPager.getCurrentItem() == MODE_SONG)
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ VLCApplication.runBackground(new Runnable() {
+ final MediaWrapper[] media = mMediaLibrary.getAudio();
+ @Override
+ public void run() {
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(media);
+ }
+ });
+ }
+ });
}
protected AudioBrowserAdapter getCurrentAdapter() {
@@ -665,13 +723,21 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
- mArtistsAdapter.update(mMediaLibrary.getArtists());
- mAlbumsAdapter.update(mMediaLibrary.getAlbums());
- mSongsAdapter.update(mMediaLibrary.getAudio());
- mGenresAdapter.update(mMediaLibrary.getGenres());
- mPlaylistAdapter.update(mMediaLibrary.getPlaylists());
- mHandler.sendEmptyMessage(UNSET_REFRESHING);
- mHandler.sendEmptyMessage(UPDATE_EMPTY_VIEW);
+ final Artist[] artists = mMediaLibrary.getArtists();
+ final Album[] albums = mMediaLibrary.getAlbums();
+ final MediaWrapper[] media = mMediaLibrary.getAudio();
+ final Genre[] genres = mMediaLibrary.getGenres();
+ final Playlist[] playlists = mMediaLibrary.getPlaylists();
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mArtistsAdapter.update(artists);
+ mAlbumsAdapter.update(albums);
+ mSongsAdapter.update(media);
+ mGenresAdapter.update(genres);
+ mPlaylistAdapter.update(playlists);
+ }
+ });
}
});
}
@@ -680,7 +746,13 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
- mPlaylistAdapter.update(mMediaLibrary.getPlaylists());
+ final Playlist[] playlists = mMediaLibrary.getPlaylists();
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mPlaylistAdapter.update(playlists);
+ }
+ });
}
});
}
More information about the Android
mailing list