The last element listened to is the first in the list at the next start

This commit is contained in:
CappielloAntonio 2021-12-30 20:07:20 +01:00
parent 9328ec87ab
commit 15e7c28b14
4 changed files with 59 additions and 3 deletions

View file

@ -128,12 +128,29 @@ public class QueueRepository {
return count;
}
public void setTimestamp(Song song) {
SetTimestampThreadSafe delete = new SetTimestampThreadSafe(queueDao, song.getId());
Thread thread = new Thread(delete);
public void setTimestamp(String id) {
SetTimestampThreadSafe timestamp = new SetTimestampThreadSafe(queueDao, id);
Thread thread = new Thread(timestamp);
thread.start();
}
public int getLastPlayedSongIndex() {
int index = 0;
GetLastPlayedSongThreadSafe getLastPlayedSongThreadSafe = new GetLastPlayedSongThreadSafe(queueDao);
Thread thread = new Thread(getLastPlayedSongThreadSafe);
thread.start();
try {
thread.join();
index = getLastPlayedSongThreadSafe.getIndex();
} catch (InterruptedException e) {
e.printStackTrace();
}
return index;
}
private static class GetSongsThreadSafe implements Runnable {
private final QueueDao queueDao;
private List<Song> songs;
@ -227,4 +244,22 @@ public class QueueRepository {
queueDao.setLastPlay(songId, Instant.now().toEpochMilli());
}
}
private static class GetLastPlayedSongThreadSafe implements Runnable {
private final QueueDao queueDao;
private int index;
public GetLastPlayedSongThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
index = queueDao.getLastPlay();
}
public int getIndex() {
return index;
}
}
}