mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Fix bug in image visualization
This commit is contained in:
parent
a0f417fa94
commit
18fae806a6
36 changed files with 431 additions and 150 deletions
|
|
@ -1,17 +1,12 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.database.dao.SongDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.paulrybitskyi.persistentsearchview.adapters.model.SuggestionItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -103,6 +98,12 @@ public class AlbumRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(albumDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class ExistThreadSafe implements Runnable {
|
||||
private AlbumDao albumDao;
|
||||
private Album album;
|
||||
|
|
@ -149,6 +150,7 @@ public class AlbumRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
albumDao.deleteAll();
|
||||
albumDao.insertAll(albums);
|
||||
}
|
||||
}
|
||||
|
|
@ -189,4 +191,17 @@ public class AlbumRepository {
|
|||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllThreadSafe implements Runnable {
|
||||
private AlbumDao albumDao;
|
||||
|
||||
public DeleteAllThreadSafe(AlbumDao albumDao) {
|
||||
this.albumDao = albumDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
albumDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,10 @@ import android.app.Application;
|
|||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.database.dao.ArtistDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ArtistRepository {
|
||||
|
|
@ -95,6 +91,12 @@ public class ArtistRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(artistDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class ExistThreadSafe implements Runnable {
|
||||
private ArtistDao artistDao;
|
||||
private Artist artist;
|
||||
|
|
@ -141,6 +143,7 @@ public class ArtistRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
artistDao.deleteAll();
|
||||
artistDao.insertAll(artists);
|
||||
}
|
||||
}
|
||||
|
|
@ -181,4 +184,17 @@ public class ArtistRepository {
|
|||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllThreadSafe implements Runnable {
|
||||
private ArtistDao artistDao;
|
||||
|
||||
public DeleteAllThreadSafe(ArtistDao artistDao) {
|
||||
this.artistDao = artistDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
artistDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ 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.Album;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -84,14 +82,20 @@ public class GenreRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void insertPerGenre(ArrayList<SongGenreCross> songGenreCrosses) {
|
||||
InsertPerGenreThreadSafe insertPerGenre = new InsertPerGenreThreadSafe(songGenreCrossDao, songGenreCrosses);
|
||||
Thread thread = new Thread(insertPerGenre);
|
||||
public void delete(Genre genre) {
|
||||
DeleteThreadSafe delete = new DeleteThreadSafe(genreDao, genre);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void delete(Genre genre) {
|
||||
DeleteThreadSafe delete = new DeleteThreadSafe(genreDao, genre);
|
||||
public void deleteAll() {
|
||||
DeleteAllGenreThreadSafe delete = new DeleteAllGenreThreadSafe(genreDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAllSongGenreCross() {
|
||||
DeleteAllSongGenreCrossThreadSafe delete = new DeleteAllSongGenreCrossThreadSafe(songGenreCrossDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
|
@ -160,25 +164,11 @@ public class GenreRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
genreDao.deleteAll();
|
||||
genreDao.insertAll(genres);
|
||||
}
|
||||
}
|
||||
|
||||
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 DeleteThreadSafe implements Runnable {
|
||||
private GenreDao genreDao;
|
||||
private Genre genre;
|
||||
|
|
@ -193,4 +183,30 @@ public class GenreRepository {
|
|||
genreDao.delete(genre);
|
||||
}
|
||||
}
|
||||
|
||||
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 DeleteAllSongGenreCrossThreadSafe implements Runnable {
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
|
||||
public DeleteAllSongGenreCrossThreadSafe(SongGenreCrossDao songGenreCrossDao) {
|
||||
this.songGenreCrossDao = songGenreCrossDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songGenreCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,12 @@ public class PlaylistRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(playlistDao);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class ExistThreadSafe implements Runnable {
|
||||
private PlaylistDao playlistDao;
|
||||
private Playlist playlist;
|
||||
|
|
@ -107,6 +113,7 @@ public class PlaylistRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
playlistDao.deleteAll();
|
||||
playlistDao.insertAll(playlists);
|
||||
}
|
||||
}
|
||||
|
|
@ -125,4 +132,17 @@ public class PlaylistRepository {
|
|||
playlistDao.delete(playlist);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllThreadSafe implements Runnable {
|
||||
private PlaylistDao playlistDao;
|
||||
|
||||
public DeleteAllThreadSafe(PlaylistDao playlistDao) {
|
||||
this.playlistDao = playlistDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
playlistDao.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@ import android.app.Application;
|
|||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.database.dao.SongDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SongRepository {
|
||||
private SongDao songDao;
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private LiveData<List<Song>> searchListLiveSongs;
|
||||
private LiveData<List<Song>> listLiveSampleRecentlyAddedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleRecentlyPlayedSongs;
|
||||
|
|
@ -29,6 +29,7 @@ public class SongRepository {
|
|||
public SongRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
songDao = database.songDao();
|
||||
songGenreCrossDao = database.songGenreCrossDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> searchListLiveSong(String title) {
|
||||
|
|
@ -93,6 +94,27 @@ public class SongRepository {
|
|||
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 boolean exist(Song song) {
|
||||
boolean exist = false;
|
||||
|
||||
|
|
@ -117,7 +139,7 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public void insertAll(ArrayList<Song> songs) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songDao, songs);
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songDao, songGenreCrossDao, songs);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
}
|
||||
|
|
@ -136,6 +158,30 @@ public class SongRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void getAll() {
|
||||
GetCatalogueThreadSafe catalogue = new GetCatalogueThreadSafe(songDao);
|
||||
Thread thread = new Thread(catalogue);
|
||||
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 List<Song> getRandomSample(int number) {
|
||||
List<Song> sample = new ArrayList<>();
|
||||
|
||||
|
|
@ -190,15 +236,19 @@ public class SongRepository {
|
|||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private ArrayList<Song> songs;
|
||||
|
||||
public InsertAllThreadSafe(SongDao songDao, 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.deleteAll();
|
||||
songGenreCrossDao.deleteAll();
|
||||
songDao.insertAll(songs);
|
||||
}
|
||||
}
|
||||
|
|
@ -274,4 +324,63 @@ public class SongRepository {
|
|||
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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue