mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Added song/artist and album/artist synchronization
This commit is contained in:
parent
b577ce7e2e
commit
ef1deea33a
13 changed files with 476 additions and 20 deletions
|
|
@ -0,0 +1,68 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.QueueDao;
|
||||
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.util.QueueUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AlbumArtistRepository {
|
||||
private static final String TAG = "AlbumArtistRepository";
|
||||
|
||||
private AlbumArtistCrossDao albumArtistCrossDao;
|
||||
|
||||
public AlbumArtistRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
albumArtistCrossDao = database.albumArtistCrossDao();
|
||||
}
|
||||
|
||||
public void insertAll(List<AlbumArtistCross> crosses) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(albumArtistCrossDao, crosses);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private AlbumArtistCrossDao albumArtistCrossDao;
|
||||
private List<AlbumArtistCross> crosses;
|
||||
|
||||
public InsertAllThreadSafe(AlbumArtistCrossDao albumArtistCrossDao, List<AlbumArtistCross> crosses) {
|
||||
this.albumArtistCrossDao = albumArtistCrossDao;
|
||||
this.crosses = crosses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
albumArtistCrossDao.insertAll(crosses);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllAlbumArtistCrossThreadSafe delete = new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class DeleteAllAlbumArtistCrossThreadSafe implements Runnable {
|
||||
private AlbumArtistCrossDao albumArtistCrossDao;
|
||||
|
||||
public DeleteAllAlbumArtistCrossThreadSafe(AlbumArtistCrossDao albumArtistCrossDao) {
|
||||
this.albumArtistCrossDao = albumArtistCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
albumArtistCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||
import com.cappielloantonio.play.model.SongArtistCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongArtistRepository {
|
||||
private static final String TAG = "AlbumArtistRepository";
|
||||
|
||||
private SongArtistCrossDao songArtistCrossDao;
|
||||
|
||||
public SongArtistRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
songArtistCrossDao = database.songArtistCrossDao();
|
||||
}
|
||||
|
||||
public void insertAll(List<SongArtistCross> crosses) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songArtistCrossDao, crosses);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private SongArtistCrossDao songArtistCrossDao;
|
||||
private List<SongArtistCross> crosses;
|
||||
|
||||
public InsertAllThreadSafe(SongArtistCrossDao songArtistCrossDao, List<SongArtistCross> crosses) {
|
||||
this.songArtistCrossDao = songArtistCrossDao;
|
||||
this.crosses = crosses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songArtistCrossDao.insertAll(crosses);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllSongArtistCrossThreadSafe delete = new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class DeleteAllSongArtistCrossThreadSafe implements Runnable {
|
||||
private SongArtistCrossDao songArtistCrossDao;
|
||||
|
||||
public DeleteAllSongArtistCrossThreadSafe(SongArtistCrossDao songArtistCrossDao) {
|
||||
this.songArtistCrossDao = songArtistCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songArtistCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue