mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-02 07:23:36 +00:00
The last element listened to is the first in the list at the next start
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user