Added artist's random-song playing

This commit is contained in:
CappielloAntonio 2021-04-18 10:36:15 +02:00
parent 7adeac1e01
commit 9bc48c7800
3 changed files with 65 additions and 2 deletions

View file

@ -80,6 +80,23 @@ public class SongRepository {
return listLiveSampleArtistTopSongs;
}
public List<Song> getArtistListLiveRandomSong(String artistID) {
List<Song> songs = new ArrayList<>();
GetRandomSongsByArtistIDThreadSafe randomArtistSongThread = new GetRandomSongsByArtistIDThreadSafe(songDao, artistID, 100);
Thread thread = new Thread(randomArtistSongThread);
thread.start();
try {
thread.join();
songs = randomArtistSongThread.getSongs();
} catch (InterruptedException e) {
e.printStackTrace();
}
return songs;
}
public LiveData<List<Song>> getAlbumListLiveSong(String albumID) {
listLiveAlbumSongs = songDao.getLiveAlbumSong(albumID);
return listLiveAlbumSongs;
@ -310,6 +327,28 @@ public class SongRepository {
}
}
private static class GetRandomSongsByArtistIDThreadSafe implements Runnable {
private SongDao songDao;
private String artistID;
private int limit;
private List<Song> songs = new ArrayList<>();
public GetRandomSongsByArtistIDThreadSafe(SongDao songDao, String artistID, int limit) {
this.songDao = songDao;
this.artistID = artistID;
this.limit = limit;
}
@Override
public void run() {
songs = songDao.getArtistRandomSongs(artistID, limit);
}
public List<Song> getSongs() {
return songs;
}
}
private static class ExistThreadSafe implements Runnable {
private SongDao songDao;
private Song song;