mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Added artist's random-song playing
This commit is contained in:
parent
7adeac1e01
commit
9bc48c7800
3 changed files with 65 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue