Add option to order and delete elements from queue by dragging and swiping

This commit is contained in:
CappielloAntonio 2021-04-16 18:00:19 +02:00
parent 49c3d60ed1
commit a2770daaa8
9 changed files with 70 additions and 111 deletions

View file

@ -19,7 +19,6 @@ public class QueueRepository {
private QueueDao queueDao;
private LiveData<List<Song>> listLiveQueue;
private LiveData<Song> liveLastPlayedSong;
public QueueRepository(Application application) {
AppDatabase database = AppDatabase.getInstance(application);
@ -31,34 +30,6 @@ public class QueueRepository {
return listLiveQueue;
}
public Song getSongByPosition(int position) {
Song song = null;
GetSongByPositionThreadSafe getSong = new GetSongByPositionThreadSafe(queueDao, position);
Thread thread = new Thread(getSong);
thread.start();
try {
thread.join();
song = getSong.getSong();
} catch (InterruptedException e) {
e.printStackTrace();
}
return song;
}
public LiveData<Song> getLiveLastPlayedSong() {
liveLastPlayedSong = queueDao.getLastPlayedSong();
return liveLastPlayedSong;
}
public void setLiveLastPlayedSong(Song song, int position) {
SetLastPlayedSongThreadSafe update = new SetLastPlayedSongThreadSafe(queueDao, song, position);
Thread thread = new Thread(update);
thread.start();
}
public List<Song> getSongs() {
List<Song> songs = new ArrayList<>();
@ -245,44 +216,4 @@ public class QueueRepository {
return songs;
}
}
private static class SetLastPlayedSongThreadSafe implements Runnable {
private QueueDao queueDao;
private Song song;
private int position;
public SetLastPlayedSongThreadSafe(QueueDao queueDao, Song song, int position) {
this.queueDao = queueDao;
this.song = song;
this.position = position;
}
@Override
public void run() {
if(song != null)
queueDao.setLastPlayedSong(song.getId(), Instant.now().toEpochMilli());
else
queueDao.setLastPlayedSong(position, Instant.now().toEpochMilli());
}
}
private static class GetSongByPositionThreadSafe implements Runnable {
private QueueDao queueDao;
private int position;
private Song song;
public GetSongByPositionThreadSafe(QueueDao queueDao, int position) {
this.queueDao = queueDao;
this.position = position;
}
@Override
public void run() {
song = queueDao.getSongByIndex(position);
}
public Song getSong() {
return song;
}
}
}