[Android] Properly get artists tracks
Geoffrey Métais
git at videolan.org
Fri Jan 26 12:08:19 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 26 12:07:38 2018 +0100| [6f1e285e402f71cb2623ef0759bd59e9bf834feb] | committer: Geoffrey Métais
Properly get artists tracks
> https://code.videolan.org/videolan/vlc-android/commit/6f1e285e402f71cb2623ef0759bd59e9bf834feb
---
medialibrary/jni/AndroidMediaLibrary.cpp | 4 ++--
medialibrary/jni/medialibrary.cpp | 7 +------
.../org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java | 12 ++++--------
3 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 8d038bead..c68132032 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -339,7 +339,7 @@ std::vector<medialibrary::MediaPtr>
AndroidMediaLibrary::mediaFromArtist( int64_t artistId )
{
auto artist = p_ml->artist(artistId);
- return artist == nullptr ? std::vector<medialibrary::MediaPtr>() : artist->media();
+ return artist == nullptr ? std::vector<medialibrary::MediaPtr>() : artist->media(medialibrary::SortingCriteria::Album);
}
std::vector<medialibrary::AlbumPtr>
@@ -353,7 +353,7 @@ std::vector<medialibrary::MediaPtr>
AndroidMediaLibrary::mediaFromGenre( int64_t genreId )
{
auto genre = p_ml->genre(genreId);
- return genre == nullptr ? std::vector<medialibrary::MediaPtr>() : genre->tracks();
+ return genre == nullptr ? std::vector<medialibrary::MediaPtr>() : genre->tracks(medialibrary::SortingCriteria::Album);
}
std::vector<medialibrary::AlbumPtr>
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index ee242aac1..7e5e11731 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -559,12 +559,7 @@ jobjectArray
getMediaFromArtist(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id)
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
- std::vector<medialibrary::AlbumPtr> albumList = aml->albumsFromArtist(id);
- std::vector<medialibrary::MediaPtr> mediaList;
- for (medialibrary::AlbumPtr album : albumList) {
- std::vector<medialibrary::MediaPtr> tracks = album->tracks();
- mediaList.insert(std::end(mediaList), std::begin(tracks), std::end(tracks));
- }
+ std::vector<medialibrary::MediaPtr> mediaList = aml->mediaFromArtist(id);
jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(mediaList.size(), ml_fields.MediaWrapper.clazz, NULL);
int index = -1, drops = 0;
for(medialibrary::MediaPtr const& media : mediaList) {
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 f2b05ad92..77fd106a6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -281,8 +281,7 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
}
private void updateList() {
- if (mItem == null || getActivity() == null)
- return;
+ if (mItem == null || getActivity() == null) return;
VLCApplication.runBackground(new Runnable() {
@Override
@@ -292,12 +291,8 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
albums = Util.arrayToMediaArrayList(((Artist) mItem).getAlbums());
} else if (mItem.getItemType() == MediaLibraryItem.TYPE_GENRE)
albums = Util.arrayToMediaArrayList(((Genre) mItem).getAlbums());
- else
- return;
- final List<MediaLibraryItem> songs = new ArrayList<>();
- for (MediaLibraryItem album : albums) {
- songs.addAll(Util.arrayToArrayList(album.getTracks()));
- }
+ else return;
+ final List<MediaLibraryItem> songs = Util.arrayToMediaArrayList(mItem.getTracks());
mAlbumsAdapter.update(albums);
mSongsAdapter.update(songs);
}
@@ -308,6 +303,7 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
public void onUpdateFinished(RecyclerView.Adapter adapter) {
mFastScroller.setRecyclerView(getCurrentRV());
mSwipeRefreshLayout.setRefreshing(false);
+ if (mAlbumsAdapter.isEmpty()) mViewPager.setCurrentItem(1);
}
/*
More information about the Android
mailing list