mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Added lastPlay info in queue model
This commit is contained in:
parent
4adde9e951
commit
76f4f1d021
6 changed files with 44 additions and 3 deletions
|
|
@ -15,7 +15,7 @@ import com.cappielloantonio.play.model.Queue;
|
|||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.model.Server;
|
||||
|
||||
@Database(entities = {Queue.class, Server.class, RecentSearch.class, Download.class}, version = 14, exportSchema = false)
|
||||
@Database(entities = {Queue.class, Server.class, RecentSearch.class, Download.class}, version = 15, exportSchema = false)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
private static final String TAG = "AppDatabase";
|
||||
|
||||
|
|
|
|||
|
|
@ -29,4 +29,7 @@ public interface QueueDao {
|
|||
|
||||
@Query("SELECT COUNT(*) FROM queue")
|
||||
int count();
|
||||
|
||||
@Query("UPDATE queue SET last_play=:timestamp WHERE id=:id")
|
||||
void setLastPlay(String id, long timestamp);
|
||||
}
|
||||
|
|
@ -36,7 +36,10 @@ public class Queue {
|
|||
@ColumnInfo(name = "duration")
|
||||
private long duration;
|
||||
|
||||
public Queue(int trackOrder, String songID, String title, String albumId, String albumName, String artistId, String artistName, String primary, long duration) {
|
||||
@ColumnInfo(name = "last_play")
|
||||
private long lastPlay;
|
||||
|
||||
public Queue(int trackOrder, String songID, String title, String albumId, String albumName, String artistId, String artistName, String primary, long duration, long lastPlay) {
|
||||
this.trackOrder = trackOrder;
|
||||
this.songID = songID;
|
||||
this.title = title;
|
||||
|
|
@ -46,6 +49,7 @@ public class Queue {
|
|||
this.artistName = artistName;
|
||||
this.primary = primary;
|
||||
this.duration = duration;
|
||||
this.lastPlay = lastPlay;
|
||||
}
|
||||
|
||||
public int getTrackOrder() {
|
||||
|
|
@ -119,4 +123,12 @@ public class Queue {
|
|||
public void setDuration(long duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public long getLastPlay() {
|
||||
return lastPlay;
|
||||
}
|
||||
|
||||
public void setLastPlay(long lastPlay) {
|
||||
this.lastPlay = lastPlay;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.cappielloantonio.play.util.MappingUtil;
|
|||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
import com.cappielloantonio.play.util.QueueUtil;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -93,6 +94,12 @@ public class QueueRepository {
|
|||
return count;
|
||||
}
|
||||
|
||||
public void setTimestamp(Song song) {
|
||||
SetTimestampThreadSafe delete = new SetTimestampThreadSafe(queueDao, song.getId());
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class GetSongsThreadSafe implements Runnable {
|
||||
private QueueDao queueDao;
|
||||
private List<Song> songs;
|
||||
|
|
@ -171,4 +178,19 @@ public class QueueRepository {
|
|||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SetTimestampThreadSafe implements Runnable {
|
||||
private QueueDao queueDao;
|
||||
private String songId;
|
||||
|
||||
public SetTimestampThreadSafe(QueueDao queueDao, String songId) {
|
||||
this.queueDao = queueDao;
|
||||
this.songId = songId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
queueDao.setLastPlay(songId, Instant.now().toEpochMilli());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.cappielloantonio.play.R;
|
|||
import com.cappielloantonio.play.broadcast.receiver.MediaButtonIntentReceiver;
|
||||
import com.cappielloantonio.play.interfaces.Playback;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
|
@ -598,7 +599,10 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
|||
|
||||
private void increaseSongCount() {
|
||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
||||
|
||||
songRepository.scrobble(getCurrentSong().getId());
|
||||
queueRepository.setTimestamp(getCurrentSong());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class QueueUtil {
|
|||
List<Queue> queue = new ArrayList<>();
|
||||
|
||||
for (Song song : songs) {
|
||||
queue.add(new Queue(counter, song.getId(), song.getTitle(), song.getAlbumId(), song.getAlbumName(), song.getArtistId(), song.getArtistName(), song.getPrimary(), song.getDuration()));
|
||||
queue.add(new Queue(counter, song.getId(), song.getTitle(), song.getAlbumId(), song.getAlbumName(), song.getArtistId(), song.getArtistName(), song.getPrimary(), song.getDuration(), 0));
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue