mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 10:23:33 +00:00
Removed unused database references
This commit is contained in:
parent
ca1831d23c
commit
ce79bda976
46 changed files with 182 additions and 1975 deletions
|
|
@ -1,68 +0,0 @@
|
|||
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.model.AlbumArtistCross;
|
||||
|
||||
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) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(albumArtistCrossDao, crosses));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllAlbumArtistCrossThreadSafe delete = new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllAlbumArtistCrossThreadSafe implements Runnable {
|
||||
private AlbumArtistCrossDao albumArtistCrossDao;
|
||||
|
||||
public DeleteAllAlbumArtistCrossThreadSafe(AlbumArtistCrossDao albumArtistCrossDao) {
|
||||
this.albumArtistCrossDao = albumArtistCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
albumArtistCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,11 +6,7 @@ import androidx.lifecycle.LiveData;
|
|||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
|
|
@ -28,20 +24,12 @@ public class AlbumRepository {
|
|||
|
||||
private AlbumSongListClient albumSongListClient;
|
||||
|
||||
private AlbumDao albumDao;
|
||||
private LiveData<List<Album>> artistListLiveAlbums;
|
||||
private LiveData<List<Album>> listLiveSampleAlbum;
|
||||
private LiveData<List<Album>> searchListLiveAlbum;
|
||||
|
||||
private MutableLiveData<List<Album>> listLiveRecentlyAddedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveMostPlayedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveRecentlyPlayedAlbums = new MutableLiveData<>();
|
||||
|
||||
public AlbumRepository(Application application) {
|
||||
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
|
||||
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
albumDao = database.albumDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getListLiveAlbums(String type, int size) {
|
||||
|
|
@ -104,143 +92,4 @@ public class AlbumRepository {
|
|||
|
||||
return starredAlbums;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getArtistListLiveAlbums(String artistId) {
|
||||
artistListLiveAlbums = albumDao.getArtistAlbums(artistId);
|
||||
return artistListLiveAlbums;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getListLiveSampleAlbum() {
|
||||
listLiveSampleAlbum = albumDao.getSample(10);
|
||||
return listLiveSampleAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> searchListLiveAlbum(String name, int limit) {
|
||||
searchListLiveAlbum = albumDao.searchAlbum(name, limit);
|
||||
return searchListLiveAlbum;
|
||||
}
|
||||
|
||||
public List<String> getSearchSuggestion(String query) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
SearchSuggestionsThreadSafe suggestionsThread = new SearchSuggestionsThreadSafe(albumDao, query, 5);
|
||||
Thread thread = new Thread(suggestionsThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
suggestions = suggestionsThread.getSuggestions();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
public void insertAll(ArrayList<Album> albums) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllThreadSafe(albumDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(albumDao, albums));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(albumDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public Album getAlbumByID(String id) {
|
||||
Album album = null;
|
||||
|
||||
GetAlbumByIDThreadSafe getAlbum = new GetAlbumByIDThreadSafe(albumDao, id);
|
||||
Thread thread = new Thread(getAlbum);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
album = getAlbum.getAlbum();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
private static class SearchSuggestionsThreadSafe implements Runnable {
|
||||
private AlbumDao albumDao;
|
||||
private String query;
|
||||
private int number;
|
||||
private List<String> suggestions = new ArrayList<>();
|
||||
|
||||
public SearchSuggestionsThreadSafe(AlbumDao albumDao, String query, int number) {
|
||||
this.albumDao = albumDao;
|
||||
this.query = query;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
suggestions = albumDao.searchSuggestions(query, number);
|
||||
}
|
||||
|
||||
public List<String> getSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllThreadSafe implements Runnable {
|
||||
private AlbumDao albumDao;
|
||||
|
||||
public DeleteAllThreadSafe(AlbumDao albumDao) {
|
||||
this.albumDao = albumDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
albumDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetAlbumByIDThreadSafe implements Runnable {
|
||||
private Album album;
|
||||
private AlbumDao albumDao;
|
||||
private String id;
|
||||
|
||||
public GetAlbumByIDThreadSafe(AlbumDao albumDao, String id) {
|
||||
this.albumDao = albumDao;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
album = albumDao.getAlbumByID(id);
|
||||
}
|
||||
|
||||
public Album getAlbum() {
|
||||
return album;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private AlbumDao albumDao;
|
||||
private ArrayList<Album> albums;
|
||||
|
||||
public InsertAllThreadSafe(AlbumDao albumDao, ArrayList<Album> albums) {
|
||||
this.albumDao = albumDao;
|
||||
this.albums = albums;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
albumDao.insertAll(albums);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.ArtistDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||
|
|
@ -25,7 +23,6 @@ import retrofit2.Response;
|
|||
public class ArtistRepository {
|
||||
private AlbumSongListClient albumSongListClient;
|
||||
|
||||
private ArtistDao artistDao;
|
||||
private LiveData<List<Artist>> listLiveArtists;
|
||||
private LiveData<List<Artist>> listLiveSampleArtist;
|
||||
private LiveData<List<Artist>> searchListLiveArtist;
|
||||
|
|
@ -34,9 +31,6 @@ public class ArtistRepository {
|
|||
|
||||
public ArtistRepository(Application application) {
|
||||
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
|
||||
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
artistDao = database.artistDao();
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getStarredArtists() {
|
||||
|
|
@ -58,143 +52,4 @@ public class ArtistRepository {
|
|||
|
||||
return starredArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getListLiveArtists() {
|
||||
listLiveArtists = artistDao.getAll();
|
||||
return listLiveArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getListLiveSampleArtist() {
|
||||
listLiveSampleArtist = artistDao.getSample(10);
|
||||
return listLiveSampleArtist;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> searchListLiveArtist(String name, int limit) {
|
||||
searchListLiveArtist = artistDao.searchArtist(name, limit);
|
||||
return searchListLiveArtist;
|
||||
}
|
||||
|
||||
public List<String> getSearchSuggestion(String query) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
SearchSuggestionsThreadSafe suggestionsThread = new SearchSuggestionsThreadSafe(artistDao, query, 5);
|
||||
Thread thread = new Thread(suggestionsThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
suggestions = suggestionsThread.getSuggestions();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
public void insertAll(ArrayList<Artist> artists) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllThreadSafe(artistDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(artistDao, artists));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(artistDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public Artist getArtistByID(String id) {
|
||||
Artist artist = null;
|
||||
|
||||
GetArtistByIDThreadSafe getArtist = new GetArtistByIDThreadSafe(artistDao, id);
|
||||
Thread thread = new Thread(getArtist);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
artist = getArtist.getArtist();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return artist;
|
||||
}
|
||||
|
||||
private static class SearchSuggestionsThreadSafe implements Runnable {
|
||||
private ArtistDao artistDao;
|
||||
private String query;
|
||||
private int number;
|
||||
private List<String> suggestions = new ArrayList<>();
|
||||
|
||||
public SearchSuggestionsThreadSafe(ArtistDao artistDao, String query, int number) {
|
||||
this.artistDao = artistDao;
|
||||
this.query = query;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
suggestions = artistDao.searchSuggestions(query, number);
|
||||
}
|
||||
|
||||
public List<String> getSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private ArtistDao artistDao;
|
||||
private ArrayList<Artist> artists;
|
||||
|
||||
public InsertAllThreadSafe(ArtistDao artistDao, ArrayList<Artist> artists) {
|
||||
this.artistDao = artistDao;
|
||||
this.artists = artists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
artistDao.insertAll(artists);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllThreadSafe implements Runnable {
|
||||
private ArtistDao artistDao;
|
||||
|
||||
public DeleteAllThreadSafe(ArtistDao artistDao) {
|
||||
this.artistDao = artistDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
artistDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetArtistByIDThreadSafe implements Runnable {
|
||||
private Artist artist;
|
||||
private ArtistDao artistDao;
|
||||
private String id;
|
||||
|
||||
public GetArtistByIDThreadSafe(ArtistDao artistDao, String id) {
|
||||
this.artistDao = artistDao;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
artist = artistDao.getArtistByID(id);
|
||||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,164 +2,7 @@ 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.GenreDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GenreRepository {
|
||||
private GenreDao genreDao;
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private LiveData<List<Genre>> listLiveGenres;
|
||||
private LiveData<List<Genre>> listLiveAlbumGenre;
|
||||
private LiveData<List<Genre>> searchListLiveGenre;
|
||||
|
||||
public GenreRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
genreDao = database.genreDao();
|
||||
songGenreCrossDao = database.songGenreCrossDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Genre>> getListLiveGenres() {
|
||||
listLiveGenres = genreDao.getAll();
|
||||
return listLiveGenres;
|
||||
}
|
||||
|
||||
public LiveData<List<Genre>> getListLiveSampleGenre() {
|
||||
listLiveAlbumGenre = genreDao.getSample(6 * 3);
|
||||
return listLiveAlbumGenre;
|
||||
}
|
||||
|
||||
public List<Genre> getListGenre() {
|
||||
List<Genre> list = null;
|
||||
|
||||
GetGenreListThreadSafe getGenreListThread = new GetGenreListThreadSafe(genreDao);
|
||||
Thread thread = new Thread(getGenreListThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
list = getGenreListThread.getList();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public void insertAll(ArrayList<Genre> genres) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllGenreThreadSafe(genreDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(genreDao, genres));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllGenreThreadSafe delete = new DeleteAllGenreThreadSafe(genreDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public LiveData<List<Genre>> searchListLiveGenre(String name, int limit) {
|
||||
searchListLiveGenre = genreDao.searchGenre(name, limit);
|
||||
return searchListLiveGenre;
|
||||
}
|
||||
|
||||
public List<String> getSearchSuggestion(String query) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
SearchSuggestionsThreadSafe suggestionsThread = new SearchSuggestionsThreadSafe(genreDao, query, 5);
|
||||
Thread thread = new Thread(suggestionsThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
suggestions = suggestionsThread.getSuggestions();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private static class GetGenreListThreadSafe implements Runnable {
|
||||
private GenreDao genreDao;
|
||||
private List<Genre> list = null;
|
||||
|
||||
public GetGenreListThreadSafe(GenreDao genreDao) {
|
||||
this.genreDao = genreDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
list = genreDao.getGenreList();
|
||||
}
|
||||
|
||||
public List<Genre> getList() {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private GenreDao genreDao;
|
||||
private ArrayList<Genre> genres;
|
||||
|
||||
public InsertAllThreadSafe(GenreDao genreDao, ArrayList<Genre> genres) {
|
||||
this.genreDao = genreDao;
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
genreDao.deleteAll();
|
||||
genreDao.insertAll(genres);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllGenreThreadSafe implements Runnable {
|
||||
private GenreDao genreDao;
|
||||
|
||||
public DeleteAllGenreThreadSafe(GenreDao genreDao) {
|
||||
this.genreDao = genreDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
genreDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class SearchSuggestionsThreadSafe implements Runnable {
|
||||
private GenreDao genreDao;
|
||||
private String query;
|
||||
private int number;
|
||||
private List<String> suggestions = new ArrayList<>();
|
||||
|
||||
public SearchSuggestionsThreadSafe(GenreDao genreDao, String query, int number) {
|
||||
this.genreDao = genreDao;
|
||||
this.query = query;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
suggestions = genreDao.searchSuggestions(query, number);
|
||||
}
|
||||
|
||||
public List<String> getSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,111 +2,7 @@ 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.PlaylistDao;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistRepository {
|
||||
private PlaylistDao playlistDao;
|
||||
private LiveData<List<Playlist>> listLivePlaylists;
|
||||
|
||||
public PlaylistRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
playlistDao = database.playlistDao();
|
||||
listLivePlaylists = playlistDao.getAll();
|
||||
}
|
||||
|
||||
public LiveData<List<Playlist>> getListLivePlaylists() {
|
||||
return listLivePlaylists;
|
||||
}
|
||||
|
||||
public void insertAll(ArrayList<Playlist> playlists) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllThreadSafe(playlistDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(playlistDao, playlists));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(playlistDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public List<Playlist> getRandomSample(int number) {
|
||||
List<Playlist> sample = new ArrayList<>();
|
||||
|
||||
PickRandomThreadSafe randomThread = new PickRandomThreadSafe(playlistDao, number);
|
||||
Thread thread = new Thread(randomThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
sample = randomThread.getSample();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private PlaylistDao playlistDao;
|
||||
private ArrayList<Playlist> playlists;
|
||||
|
||||
public InsertAllThreadSafe(PlaylistDao playlistDao, ArrayList<Playlist> playlists) {
|
||||
this.playlistDao = playlistDao;
|
||||
this.playlists = playlists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
playlistDao.insertAll(playlists);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllThreadSafe implements Runnable {
|
||||
private PlaylistDao playlistDao;
|
||||
|
||||
public DeleteAllThreadSafe(PlaylistDao playlistDao) {
|
||||
this.playlistDao = playlistDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
playlistDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class PickRandomThreadSafe implements Runnable {
|
||||
private PlaylistDao playlistDao;
|
||||
private int elementNumber;
|
||||
private List<Playlist> sample;
|
||||
|
||||
public PickRandomThreadSafe(PlaylistDao playlistDao, int number) {
|
||||
this.playlistDao = playlistDao;
|
||||
this.elementNumber = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sample = playlistDao.random(elementNumber);
|
||||
}
|
||||
|
||||
public List<Playlist> getSample() {
|
||||
return sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.PlaylistSongCrossDao;
|
||||
import com.cappielloantonio.play.model.PlaylistSongCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistSongRepository {
|
||||
private static final String TAG = "AlbumArtistRepository";
|
||||
|
||||
private PlaylistSongCrossDao playlistSongCrossDao;
|
||||
|
||||
public PlaylistSongRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
playlistSongCrossDao = database.playlistSongCrossDao();
|
||||
}
|
||||
|
||||
public void insertAll(List<PlaylistSongCross> crosses) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(playlistSongCrossDao, crosses);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private PlaylistSongCrossDao playlistSongCrossDao;
|
||||
private List<PlaylistSongCross> crosses;
|
||||
|
||||
public InsertAllThreadSafe(PlaylistSongCrossDao playlistSongCrossDao, List<PlaylistSongCross> crosses) {
|
||||
this.playlistSongCrossDao = playlistSongCrossDao;
|
||||
this.crosses = crosses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
playlistSongCrossDao.insertAll(crosses);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllPlaylistSongCrossThreadSafe delete = new DeleteAllPlaylistSongCrossThreadSafe(playlistSongCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class DeleteAllPlaylistSongCrossThreadSafe implements Runnable {
|
||||
private PlaylistSongCrossDao playlistSongCrossDao;
|
||||
|
||||
public DeleteAllPlaylistSongCrossThreadSafe(PlaylistSongCrossDao playlistSongCrossDao) {
|
||||
this.playlistSongCrossDao = playlistSongCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
playlistSongCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,8 +6,9 @@ import androidx.lifecycle.LiveData;
|
|||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.QueueDao;
|
||||
import com.cappielloantonio.play.database.dao.SongDao;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.QueueUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -16,17 +17,15 @@ import java.util.List;
|
|||
public class QueueRepository {
|
||||
private static final String TAG = "QueueRepository";
|
||||
|
||||
private SongDao songDao;
|
||||
private QueueDao queueDao;
|
||||
private LiveData<List<Song>> listLiveQueue;
|
||||
private LiveData<List<Queue>> listLiveQueue;
|
||||
|
||||
public QueueRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
songDao = database.songDao();
|
||||
queueDao = database.queueDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getLiveQueue() {
|
||||
public LiveData<List<Queue>> getLiveQueue() {
|
||||
listLiveQueue = queueDao.getAll();
|
||||
return listLiveQueue;
|
||||
}
|
||||
|
|
@ -58,7 +57,7 @@ public class QueueRepository {
|
|||
List<String> IDs = QueueUtil.getIDsFromSongs(media);
|
||||
List<Song> mix = new ArrayList<>();
|
||||
|
||||
GetSongsByIDThreadSafe getSongsByIDThreadSafe = new GetSongsByIDThreadSafe(songDao, IDs);
|
||||
/*GetSongsByIDThreadSafe getSongsByIDThreadSafe = new GetSongsByIDThreadSafe(songDao, IDs);
|
||||
Thread thread = new Thread(getSongsByIDThreadSafe);
|
||||
thread.start();
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ public class QueueRepository {
|
|||
insertAllAndStartNew(mix);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
return mix;
|
||||
}
|
||||
|
|
@ -94,12 +93,6 @@ public class QueueRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public int count() {
|
||||
int count = 0;
|
||||
|
||||
|
|
@ -127,27 +120,7 @@ public class QueueRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = queueDao.getAllSimple();
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetSongsByIDThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private List<String> IDs;
|
||||
private List<Song> songs;
|
||||
|
||||
public GetSongsByIDThreadSafe(SongDao songDao, List<String> IDs) {
|
||||
this.songDao = songDao;
|
||||
this.IDs = IDs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = songDao.getSongsByID(IDs);
|
||||
songs = MappingUtil.mapQueue(queueDao.getAllSimple());
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
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) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(songArtistCrossDao, crosses));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllSongArtistCrossThreadSafe delete = new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllSongArtistCrossThreadSafe implements Runnable {
|
||||
private SongArtistCrossDao songArtistCrossDao;
|
||||
|
||||
public DeleteAllSongArtistCrossThreadSafe(SongArtistCrossDao songArtistCrossDao) {
|
||||
this.songArtistCrossDao = songArtistCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songArtistCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongGenreRepository {
|
||||
private static final String TAG = "AlbumArtistRepository";
|
||||
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
|
||||
public SongGenreRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
songGenreCrossDao = database.songGenreCrossDao();
|
||||
}
|
||||
|
||||
public void insertAll(List<SongGenreCross> crosses) {
|
||||
InsertAllThreadSafe insert = new InsertAllThreadSafe(songGenreCrossDao, crosses);
|
||||
Thread thread = new Thread(insert);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllSongGenreCrossThreadSafe delete = new DeleteAllSongGenreCrossThreadSafe(songGenreCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private List<SongGenreCross> crosses;
|
||||
|
||||
public InsertAllThreadSafe(SongGenreCrossDao songGenreCrossDao, List<SongGenreCross> crosses) {
|
||||
this.songGenreCrossDao = songGenreCrossDao;
|
||||
this.crosses = crosses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songGenreCrossDao.insertAll(crosses);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllSongGenreCrossThreadSafe implements Runnable {
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
|
||||
public DeleteAllSongGenreCrossThreadSafe(SongGenreCrossDao songGenreCrossDao) {
|
||||
this.songGenreCrossDao = songGenreCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songGenreCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,11 @@ package com.cappielloantonio.play.repository;
|
|||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.SongDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.api.browsing.BrowsingClient;
|
||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||
|
|
@ -19,7 +14,6 @@ import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
|||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
|
|
@ -32,33 +26,11 @@ public class SongRepository {
|
|||
private AlbumSongListClient albumSongListClient;
|
||||
private BrowsingClient browsingClient;
|
||||
|
||||
private SongDao songDao;
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private LiveData<List<Song>> searchListLiveSongs;
|
||||
private LiveData<List<Song>> listLiveSampleDiscoverSongs;
|
||||
private LiveData<List<Song>> listLiveSampleRecentlyAddedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleRecentlyPlayedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleMostPlayedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleArtistTopSongs;
|
||||
private LiveData<List<Song>> listLiveAlbumSongs;
|
||||
private LiveData<List<Song>> listLivePlaylistSongs;
|
||||
private LiveData<List<Song>> listLiveSongByGenre;
|
||||
private LiveData<List<Song>> listLiveFilteredSongs;
|
||||
private LiveData<List<Song>> listLiveSongByYear;
|
||||
private LiveData<List<Song>> listLiveSampleFavoritesSong;
|
||||
private LiveData<List<Song>> listLiveFavoritesSong;
|
||||
private LiveData<List<Song>> listLiveSampleDownloadedSong;
|
||||
private LiveData<List<Song>> listLiveDownloadedSong;
|
||||
|
||||
private MutableLiveData<List<Song>> starredSongs = new MutableLiveData<>();
|
||||
|
||||
public SongRepository(Application application) {
|
||||
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
|
||||
browsingClient = App.getSubsonicClientInstance(application, false).getBrowsingClient();
|
||||
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
songDao = database.songDao();
|
||||
songGenreCrossDao = database.songGenreCrossDao();
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getStarredSongs() {
|
||||
|
|
@ -90,10 +62,9 @@ public class SongRepository {
|
|||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
List<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
if(songs.size() > 1) {
|
||||
if (songs.size() > 1) {
|
||||
callback.onLoadMedia(songs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
songs.add(song);
|
||||
callback.onLoadMedia(songs);
|
||||
}
|
||||
|
|
@ -109,241 +80,6 @@ public class SongRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> searchListLiveSong(String title, int limit) {
|
||||
searchListLiveSongs = songDao.searchSong(title, limit);
|
||||
return searchListLiveSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveDiscoverSampleSong(List<Integer> pseudoRandomNumber) {
|
||||
listLiveSampleDiscoverSongs = songDao.getDiscoverySample(pseudoRandomNumber);
|
||||
return listLiveSampleDiscoverSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveRecentlyAddedSampleSong(int number) {
|
||||
listLiveSampleRecentlyAddedSongs = songDao.getRecentlyAddedSample(number);
|
||||
return listLiveSampleRecentlyAddedSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveRecentlyPlayedSampleSong(int number) {
|
||||
listLiveSampleRecentlyPlayedSongs = songDao.getRecentlyPlayedSample(number);
|
||||
return listLiveSampleRecentlyPlayedSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveMostPlayedSampleSong(int number) {
|
||||
listLiveSampleMostPlayedSongs = songDao.getMostPlayedSample(number);
|
||||
return listLiveSampleMostPlayedSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveSongByGenre(String genreID) {
|
||||
listLiveSongByGenre = songDao.getSongByGenre(genreID);
|
||||
return listLiveSongByGenre;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getArtistListLiveTopSongSample(String artistID) {
|
||||
listLiveSampleArtistTopSongs = songDao.getArtistTopSongsSample(artistID, 5);
|
||||
return listLiveSampleArtistTopSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getArtistListLiveTopSong(String artistID) {
|
||||
listLiveSampleArtistTopSongs = songDao.getArtistTopSongs(artistID);
|
||||
return listLiveSampleArtistTopSongs;
|
||||
}
|
||||
|
||||
public List<Song> getArtistListLiveRandomSong(String artistID) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
GetRandomSongsByArtistIDThreadSafe randomArtistSongThread = new GetRandomSongsByArtistIDThreadSafe(songDao, artistID, 100);
|
||||
Thread thread = new Thread(randomArtistSongThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
songs = randomArtistSongThread.getSongs();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getAlbumListLiveSong(String albumID) {
|
||||
listLiveAlbumSongs = songDao.getLiveAlbumSong(albumID);
|
||||
return listLiveAlbumSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getPlaylistLiveSong(String playlistID) {
|
||||
listLivePlaylistSongs = songDao.getLivePlaylistSong(playlistID);
|
||||
return listLivePlaylistSongs;
|
||||
}
|
||||
|
||||
public List<Song> getAlbumListSong(String albumID, boolean randomOrder) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
GetSongsByAlbumIDThreadSafe suggestionsThread = new GetSongsByAlbumIDThreadSafe(songDao, albumID);
|
||||
Thread thread = new Thread(suggestionsThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
songs = suggestionsThread.getSongs();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (randomOrder) {
|
||||
Collections.shuffle(songs);
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getFilteredListLiveSong(ArrayList<String> filters) {
|
||||
listLiveFilteredSongs = songDao.getFilteredSong(filters);
|
||||
return listLiveFilteredSongs;
|
||||
}
|
||||
|
||||
public List<String> getSearchSuggestion(String query) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
SearchSuggestionsThreadSafe suggestionsThread = new SearchSuggestionsThreadSafe(songDao, query, 5);
|
||||
Thread thread = new Thread(suggestionsThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
suggestions = suggestionsThread.getSuggestions();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/*
|
||||
* Funzione che ritorna l'intero set di canzoni.
|
||||
* Utilizzato per l'aggiornamento del catalogo.
|
||||
*/
|
||||
public List<Song> getCatalogue() {
|
||||
List<Song> catalogue = new ArrayList<>();
|
||||
|
||||
GetCatalogueThreadSafe getCatalogueThread = new GetCatalogueThreadSafe(songDao);
|
||||
Thread thread = new Thread(getCatalogueThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
catalogue = getCatalogueThread.getCatalogue();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return catalogue;
|
||||
}
|
||||
|
||||
public List<Integer> getYearList() {
|
||||
List<Integer> years = new ArrayList<>();
|
||||
|
||||
GetYearListThreadSafe getYearListThreadSafe = new GetYearListThreadSafe(songDao);
|
||||
Thread thread = new Thread(getYearListThreadSafe);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
years = getYearListThreadSafe.getYearList();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return years;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getSongByYearListLive(int year) {
|
||||
listLiveSongByYear = songDao.getSongsByYear(year);
|
||||
return listLiveSongByYear;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveFavoritesSampleSong(int number) {
|
||||
listLiveSampleFavoritesSong = songDao.getFavoriteSongSample(number);
|
||||
return listLiveSampleFavoritesSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveFavoritesSong() {
|
||||
listLiveFavoritesSong = songDao.getFavoriteSong();
|
||||
return listLiveFavoritesSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveDownloadedSampleSong(int number) {
|
||||
listLiveSampleDownloadedSong = songDao.getDownloadedSongSample(number);
|
||||
return listLiveSampleDownloadedSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveDownloadedSong() {
|
||||
listLiveDownloadedSong = songDao.getDownloadedSong();
|
||||
return listLiveDownloadedSong;
|
||||
}
|
||||
|
||||
public void insertAll(ArrayList<Song> songs) {
|
||||
try {
|
||||
final Thread deleteAll = new Thread(new DeleteAllSongThreadSafe(songDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(songDao, songGenreCrossDao, songs));
|
||||
|
||||
deleteAll.start();
|
||||
deleteAll.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songDao, songGenreCrossDao, songs);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void increasePlayCount(Song song) {
|
||||
if (song.nowPlaying()) {
|
||||
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
|
||||
Thread thread = new Thread(update);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFavoriteStatus(Song song) {
|
||||
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
|
||||
Thread thread = new Thread(update);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void setOfflineStatus(Song song) {
|
||||
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
|
||||
Thread thread = new Thread(update);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void setAllOffline() {
|
||||
SetAllOfflineThreadSafe update = new SetAllOfflineThreadSafe(songDao);
|
||||
Thread thread = new Thread(update);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void insertSongPerGenre(ArrayList<SongGenreCross> songGenreCrosses) {
|
||||
InsertPerGenreThreadSafe insertPerGenre = new InsertPerGenreThreadSafe(songGenreCrossDao, songGenreCrosses);
|
||||
Thread thread = new Thread(insertPerGenre);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAllSong() {
|
||||
DeleteAllSongThreadSafe delete = new DeleteAllSongThreadSafe(songDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAllSongGenreCross() {
|
||||
DeleteAllSongGenreCrossThreadSafe delete = new DeleteAllSongGenreCrossThreadSafe(songGenreCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void getRandomSample(int number, MediaCallback callback) {
|
||||
albumSongListClient
|
||||
.getRandomSongs(number)
|
||||
|
|
@ -365,258 +101,4 @@ public class SongRepository {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<Song> getPlaylistSong(String playlistID) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
GetSongsByPlaylistIDThreadSafe playlistThread = new GetSongsByPlaylistIDThreadSafe(songDao, playlistID);
|
||||
Thread thread = new Thread(playlistThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
songs = playlistThread.getSongs();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
private static class GetRandomSongsByArtistIDThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private String artistID;
|
||||
private int limit;
|
||||
private List<Song> songs = new ArrayList<>();
|
||||
|
||||
public GetRandomSongsByArtistIDThreadSafe(SongDao songDao, String artistID, int limit) {
|
||||
this.songDao = songDao;
|
||||
this.artistID = artistID;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = songDao.getArtistRandomSongs(artistID, limit);
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetSongsByAlbumIDThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private String albumID;
|
||||
private List<Song> songs = new ArrayList<>();
|
||||
|
||||
public GetSongsByAlbumIDThreadSafe(SongDao songDao, String albumID) {
|
||||
this.songDao = songDao;
|
||||
this.albumID = albumID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = songDao.getAlbumSong(albumID);
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SearchSuggestionsThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private String query;
|
||||
private int number;
|
||||
private List<String> suggestions = new ArrayList<>();
|
||||
|
||||
public SearchSuggestionsThreadSafe(SongDao songDao, String query, int number) {
|
||||
this.songDao = songDao;
|
||||
this.query = query;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
suggestions = songDao.searchSuggestions(query, number);
|
||||
}
|
||||
|
||||
public List<String> getSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetCatalogueThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private List<Song> catalogue = new ArrayList<>();
|
||||
|
||||
public GetCatalogueThreadSafe(SongDao songDao) {
|
||||
this.songDao = songDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
catalogue = songDao.getAllList();
|
||||
}
|
||||
|
||||
public List<Song> getCatalogue() {
|
||||
return catalogue;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetYearListThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private List<Integer> years = new ArrayList<>();
|
||||
private List<Integer> decades = new ArrayList<>();
|
||||
|
||||
public GetYearListThreadSafe(SongDao songDao) {
|
||||
this.songDao = songDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
years = songDao.getYearList();
|
||||
|
||||
for (int year : years) {
|
||||
if (!decades.contains(year - year % 10)) {
|
||||
decades.add(year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getYearList() {
|
||||
return years;
|
||||
}
|
||||
|
||||
public List<Integer> getDecadeList() {
|
||||
return decades;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private ArrayList<Song> songs;
|
||||
|
||||
public InsertAllThreadSafe(SongDao songDao, SongGenreCrossDao songGenreCrossDao, ArrayList<Song> songs) {
|
||||
this.songDao = songDao;
|
||||
this.songGenreCrossDao = songGenreCrossDao;
|
||||
this.songs = songs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songDao.insertAll(songs);
|
||||
}
|
||||
}
|
||||
|
||||
private static class UpdateThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private Song song;
|
||||
|
||||
public UpdateThreadSafe(SongDao songDao, Song song) {
|
||||
this.songDao = songDao;
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songDao.update(song);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SetAllOfflineThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
|
||||
public SetAllOfflineThreadSafe(SongDao songDao) {
|
||||
this.songDao = songDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songDao.updateAllOffline();
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertPerGenreThreadSafe implements Runnable {
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private ArrayList<SongGenreCross> cross;
|
||||
|
||||
public InsertPerGenreThreadSafe(SongGenreCrossDao songGenreCrossDao, ArrayList<SongGenreCross> cross) {
|
||||
this.songGenreCrossDao = songGenreCrossDao;
|
||||
this.cross = cross;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songGenreCrossDao.insertAll(cross);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllSongThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
|
||||
public DeleteAllSongThreadSafe(SongDao songDao) {
|
||||
this.songDao = songDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllSongGenreCrossThreadSafe implements Runnable {
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
|
||||
public DeleteAllSongGenreCrossThreadSafe(SongGenreCrossDao songGenreCrossDao) {
|
||||
this.songGenreCrossDao = songGenreCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songGenreCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class PickRandomThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private int elementNumber;
|
||||
private List<Song> sample;
|
||||
|
||||
public PickRandomThreadSafe(SongDao songDao, int number) {
|
||||
this.songDao = songDao;
|
||||
this.elementNumber = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sample = songDao.random(elementNumber);
|
||||
}
|
||||
|
||||
public List<Song> getSample() {
|
||||
return sample;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetSongsByPlaylistIDThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private String playlistID;
|
||||
private List<Song> songs = new ArrayList<>();
|
||||
|
||||
public GetSongsByPlaylistIDThreadSafe(SongDao songDao, String playlistID) {
|
||||
this.songDao = songDao;
|
||||
this.playlistID = playlistID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = songDao.getPlaylistSong(playlistID);
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue