mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-01 23:13:36 +00:00
TESTING - Queue changing (enqueue/play_next)
This commit is contained in:
@@ -47,8 +47,8 @@ public class QueueRepository {
|
||||
return songs;
|
||||
}
|
||||
|
||||
public void insert(Song song) {
|
||||
InsertThreadSafe insert = new InsertThreadSafe(queueDao, song);
|
||||
public void insert(Song song, int position) {
|
||||
InsertThreadSafe insert = new InsertThreadSafe(queueDao, song, position);
|
||||
Thread thread = new Thread(insert);
|
||||
thread.start();
|
||||
}
|
||||
@@ -111,15 +111,17 @@ public class QueueRepository {
|
||||
private static class InsertThreadSafe implements Runnable {
|
||||
private QueueDao queueDao;
|
||||
private Song song;
|
||||
private int position;
|
||||
|
||||
public InsertThreadSafe(QueueDao queueDao, Song song) {
|
||||
public InsertThreadSafe(QueueDao queueDao, Song song, int position) {
|
||||
this.queueDao = queueDao;
|
||||
this.song = song;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
queueDao.insert(QueueUtil.getQueueElementFromSong(song));
|
||||
queueDao.insert(QueueUtil.getQueueElementFromSong(song, position));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SongRepository {
|
||||
@@ -80,10 +81,31 @@ public class SongRepository {
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getAlbumListLiveSong(String albumID) {
|
||||
listLiveAlbumSongs = songDao.getAlbumSong(albumID);
|
||||
listLiveAlbumSongs = songDao.getLiveAlbumSong(albumID);
|
||||
return listLiveAlbumSongs;
|
||||
}
|
||||
|
||||
public List<Song> getAlbumListSong(String albumID, boolean randomOrder) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
GetSongsByAlbumIDThreadSafe suggestionsThread = new GetSongsByAlbumIDThreadSafe(songDao, albumID);
|
||||
Thread thread = new Thread(suggestionsThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
songs = suggestionsThread.getSongs();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(randomOrder) {
|
||||
Collections.shuffle(songs);
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getFilteredListLiveSong(ArrayList<String> filters) {
|
||||
listLiveFilteredSongs = songDao.getFilteredSong(filters);
|
||||
return listLiveFilteredSongs;
|
||||
@@ -268,6 +290,26 @@ public class SongRepository {
|
||||
return song;
|
||||
}
|
||||
|
||||
private static class GetSongsByAlbumIDThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private String albumID;
|
||||
private List<Song> songs = new ArrayList<>();
|
||||
|
||||
public GetSongsByAlbumIDThreadSafe(SongDao songDao, String albumID) {
|
||||
this.songDao = songDao;
|
||||
this.albumID = albumID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = songDao.getAlbumSong(albumID);
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExistThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private Song song;
|
||||
|
||||
Reference in New Issue
Block a user