fix database concurrency issue
This commit is contained in:
parent
f95e2e89b9
commit
bfd3818c0a
2 changed files with 12 additions and 8 deletions
|
|
@ -45,4 +45,15 @@ public abstract class QueueSongDao {
|
|||
|
||||
insertQueueSongs(queueSongs);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public void updateQueues(List<Song> playingQueue, List<Song> shuffledQueue) {
|
||||
// copy queues by value to avoid concurrent modification exceptions from database
|
||||
App.getDatabase().songDao().deleteSongs();
|
||||
App.getDatabase().songDao().insertSongs(new ArrayList<>(playingQueue));
|
||||
|
||||
deleteQueueSongs();
|
||||
setQueue(new ArrayList<>(playingQueue), 0);
|
||||
setQueue(new ArrayList<>(shuffledQueue), 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,14 +294,7 @@ public class QueueManager {
|
|||
|
||||
public void saveQueue() {
|
||||
PreferenceUtil.getInstance(context).setPosition(position);
|
||||
|
||||
// copy queues by value to avoid concurrent modification exceptions from database
|
||||
App.getDatabase().songDao().deleteSongs();
|
||||
App.getDatabase().songDao().insertSongs(new ArrayList<>(playingQueue));
|
||||
|
||||
App.getDatabase().queueSongDao().deleteQueueSongs();
|
||||
App.getDatabase().queueSongDao().setQueue(new ArrayList<>(playingQueue), 0);
|
||||
App.getDatabase().queueSongDao().setQueue(new ArrayList<>(shuffledQueue), 1);
|
||||
App.getDatabase().queueSongDao().updateQueues(playingQueue, shuffledQueue);
|
||||
}
|
||||
|
||||
public int getRestoredProgress() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue