mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Removed unused database references
This commit is contained in:
parent
ca1831d23c
commit
ce79bda976
46 changed files with 182 additions and 1975 deletions
|
|
@ -41,7 +41,7 @@ public class PlayerNowPlayingSongAdapter extends RecyclerView.Adapter<PlayerNowP
|
|||
Song song = songs.get(position);
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, song.getPrimary(), song.getBlurHash(), CustomGlideRequest.SONG_PIC)
|
||||
.from(context, song.getId(), song.getBlurHash(), CustomGlideRequest.SONG_PIC)
|
||||
.build()
|
||||
.into(holder.cover);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,32 +6,16 @@ import androidx.room.Database;
|
|||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.cappielloantonio.play.database.dao.AlbumArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.database.dao.ArtistDao;
|
||||
import com.cappielloantonio.play.database.dao.GenreDao;
|
||||
import com.cappielloantonio.play.database.dao.PlaylistDao;
|
||||
import com.cappielloantonio.play.database.dao.PlaylistSongCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.QueueDao;
|
||||
import com.cappielloantonio.play.database.dao.RecentSearchDao;
|
||||
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.SongDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.PlaylistSongCross;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongArtistCross;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
@Database(entities = {Album.class, Artist.class, Genre.class, Playlist.class, Song.class, RecentSearch.class, SongGenreCross.class, Queue.class, AlbumArtistCross.class, SongArtistCross.class, PlaylistSongCross.class}, version = 2, exportSchema = false)
|
||||
@Database(entities = {Queue.class, RecentSearch.class}, version = 2, exportSchema = false)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
private static final String TAG = "AppDatabase";
|
||||
|
||||
private final static String DB_NAME = "play_db";
|
||||
private static AppDatabase instance;
|
||||
|
||||
|
|
@ -44,25 +28,7 @@ public abstract class AppDatabase extends RoomDatabase {
|
|||
return instance;
|
||||
}
|
||||
|
||||
public abstract AlbumDao albumDao();
|
||||
|
||||
public abstract ArtistDao artistDao();
|
||||
|
||||
public abstract GenreDao genreDao();
|
||||
|
||||
public abstract PlaylistDao playlistDao();
|
||||
|
||||
public abstract SongDao songDao();
|
||||
public abstract QueueDao queueDao();
|
||||
|
||||
public abstract RecentSearchDao recentSearchDao();
|
||||
|
||||
public abstract SongGenreCrossDao songGenreCrossDao();
|
||||
|
||||
public abstract AlbumArtistCrossDao albumArtistCrossDao();
|
||||
|
||||
public abstract SongArtistCrossDao songArtistCrossDao();
|
||||
|
||||
public abstract PlaylistSongCrossDao playlistSongCrossDao();
|
||||
|
||||
public abstract QueueDao queueDao();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface AlbumArtistCrossDao {
|
||||
@Query("SELECT * FROM album_artist_cross")
|
||||
LiveData<List<AlbumArtistCross>> getAll();
|
||||
|
||||
@Query("SELECT EXISTS(SELECT * FROM album_artist_cross WHERE id = :id)")
|
||||
boolean exist(String id);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(AlbumArtistCross albumArtistCross);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<AlbumArtistCross> albumArtistCrosses);
|
||||
|
||||
@Delete
|
||||
void delete(AlbumArtistCross albumArtistCross);
|
||||
|
||||
@Update
|
||||
void update(AlbumArtistCross albumArtistCross);
|
||||
|
||||
@Query("DELETE FROM album_artist_cross")
|
||||
void deleteAll();
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface AlbumDao {
|
||||
@Query("SELECT * FROM album")
|
||||
LiveData<List<Album>> getAll();
|
||||
|
||||
@Query("SELECT album.* FROM album INNER JOIN album_artist_cross ON album.id = album_artist_cross.album_id AND album_artist_cross.artist_id = :artistId")
|
||||
LiveData<List<Album>> getArtistAlbums(String artistId);
|
||||
|
||||
@Query("SELECT * FROM album ORDER BY RANDOM() LIMIT :number;")
|
||||
LiveData<List<Album>> getSample(int number);
|
||||
|
||||
@Query("SELECT * FROM album WHERE title LIKE '%' || :name || '%' LIMIT :limit")
|
||||
LiveData<List<Album>> searchAlbum(String name, int limit);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(Album album);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Album> albums);
|
||||
|
||||
@Query("SELECT title FROM album WHERE title LIKE :query || '%' OR title like '% ' || :query || '%' GROUP BY title LIMIT :number")
|
||||
List<String> searchSuggestions(String query, int number);
|
||||
|
||||
@Query("DELETE FROM album")
|
||||
void deleteAll();
|
||||
|
||||
@Query("SELECT * FROM album WHERE id = :id")
|
||||
Album getAlbumByID(String id);
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface ArtistDao {
|
||||
@Query("SELECT * FROM artist")
|
||||
LiveData<List<Artist>> getAll();
|
||||
|
||||
@Query("SELECT * FROM artist ORDER BY RANDOM() LIMIT :number;")
|
||||
LiveData<List<Artist>> getSample(int number);
|
||||
|
||||
@Query("SELECT * FROM artist WHERE name LIKE '%' || :name || '%' LIMIT :limit")
|
||||
LiveData<List<Artist>> searchArtist(String name, int limit);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Artist> artists);
|
||||
|
||||
@Query("SELECT name FROM artist WHERE name LIKE :query || '%' OR name like '% ' || :query || '%' GROUP BY name LIMIT :number")
|
||||
List<String> searchSuggestions(String query, int number);
|
||||
|
||||
@Query("DELETE FROM artist")
|
||||
void deleteAll();
|
||||
|
||||
@Query("SELECT * FROM artist WHERE id = :id")
|
||||
Artist getArtistByID(String id);
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface GenreDao {
|
||||
@Query("SELECT * FROM genre")
|
||||
LiveData<List<Genre>> getAll();
|
||||
|
||||
@Query("SELECT * FROM genre")
|
||||
List<Genre> getGenreList();
|
||||
|
||||
@Query("SELECT * FROM genre ORDER BY RANDOM() LIMIT :number;")
|
||||
LiveData<List<Genre>> getSample(int number);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Genre> genres);
|
||||
|
||||
@Query("DELETE FROM genre")
|
||||
void deleteAll();
|
||||
|
||||
@Query("SELECT * FROM genre WHERE name LIKE '%' || :name || '%' LIMIT :limit")
|
||||
LiveData<List<Genre>> searchGenre(String name, int limit);
|
||||
|
||||
@Query("SELECT name FROM genre WHERE name LIKE :query || '%' OR name like '% ' || :query || '%' GROUP BY name LIMIT :number")
|
||||
List<String> searchSuggestions(String query, int number);
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface PlaylistDao {
|
||||
@Query("SELECT * FROM playlist")
|
||||
LiveData<List<Playlist>> getAll();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Playlist> playlists);
|
||||
|
||||
@Query("DELETE FROM playlist")
|
||||
void deleteAll();
|
||||
|
||||
@Query("SELECT * FROM playlist ORDER BY RANDOM() LIMIT :number")
|
||||
List<Playlist> random(int number);
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import com.cappielloantonio.play.model.PlaylistSongCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface PlaylistSongCrossDao {
|
||||
@Query("SELECT * FROM playlist_song_cross")
|
||||
LiveData<List<PlaylistSongCross>> getAll();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(PlaylistSongCross playlistSongCross);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<PlaylistSongCross> playlistSongCrosses);
|
||||
|
||||
@Delete
|
||||
void delete(PlaylistSongCross playlistSongCross);
|
||||
|
||||
@Update
|
||||
void update(PlaylistSongCross playlistSongCross);
|
||||
|
||||
@Query("DELETE FROM playlist_song_cross")
|
||||
void deleteAll();
|
||||
}
|
||||
|
|
@ -13,11 +13,11 @@ import java.util.List;
|
|||
|
||||
@Dao
|
||||
public interface QueueDao {
|
||||
@Query("SELECT song.* FROM song JOIN queue ON song.id = queue.id")
|
||||
LiveData<List<Song>> getAll();
|
||||
@Query("SELECT * FROM queue")
|
||||
LiveData<List<Queue>> getAll();
|
||||
|
||||
@Query("SELECT song.* FROM song JOIN queue ON song.id = queue.id")
|
||||
List<Song> getAllSimple();
|
||||
@Query("SELECT * FROM queue")
|
||||
List<Queue> getAllSimple();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Queue> songQueueObject);
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import com.cappielloantonio.play.model.SongArtistCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface SongArtistCrossDao {
|
||||
@Query("SELECT * FROM song_artist_cross")
|
||||
LiveData<List<SongArtistCross>> getAll();
|
||||
|
||||
@Query("SELECT EXISTS(SELECT * FROM song_artist_cross WHERE id = :id)")
|
||||
boolean exist(String id);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(SongArtistCross songArtistCross);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<SongArtistCross> songArtistCross);
|
||||
|
||||
@Delete
|
||||
void delete(SongArtistCross songArtistCross);
|
||||
|
||||
@Update
|
||||
void update(SongArtistCross songArtistCross);
|
||||
|
||||
@Query("DELETE FROM song_artist_cross")
|
||||
void deleteAll();
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface SongDao {
|
||||
@Query("SELECT * FROM song")
|
||||
LiveData<List<Song>> getAll();
|
||||
|
||||
@Query("SELECT * FROM song")
|
||||
List<Song> getAllList();
|
||||
|
||||
@Query("SELECT * FROM song WHERE title LIKE '%' || :title || '%' LIMIT :limit")
|
||||
LiveData<List<Song>> searchSong(String title, int limit);
|
||||
|
||||
// Da utilizzare in caso si decidesse di migliorare il viewpager nella home
|
||||
@Query("SELECT * FROM song WHERE id IN (:pseudoRandomNumber)")
|
||||
LiveData<List<Song>> getDiscoverySample(List<Integer> pseudoRandomNumber);
|
||||
|
||||
@Query("SELECT * FROM song ORDER BY added DESC LIMIT :number")
|
||||
LiveData<List<Song>> getRecentlyAddedSample(int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE last_play != 0 ORDER BY last_play DESC LIMIT :number")
|
||||
LiveData<List<Song>> getRecentlyPlayedSample(int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE play_count != 0 ORDER BY play_count DESC LIMIT :number")
|
||||
LiveData<List<Song>> getMostPlayedSample(int number);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN song_artist_cross ON song.id = song_artist_cross.song_id AND song_artist_cross.artist_id = :artistID ORDER BY play_count DESC LIMIT :number")
|
||||
LiveData<List<Song>> getArtistTopSongsSample(String artistID, int number);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN song_artist_cross ON song.id = song_artist_cross.song_id AND song_artist_cross.artist_id = :artistID ORDER BY play_count DESC")
|
||||
LiveData<List<Song>> getArtistTopSongs(String artistID);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN song_artist_cross ON song.id = song_artist_cross.song_id AND song_artist_cross.artist_id = :artistID ORDER BY RANDOM() LIMIT :number")
|
||||
List<Song> getArtistRandomSongs(String artistID, int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE albumId = :albumID ORDER BY trackNumber ASC")
|
||||
LiveData<List<Song>> getLiveAlbumSong(String albumID);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN playlist_song_cross ON song.id = playlist_song_cross.song_id AND playlist_song_cross.playlist_id = :playlistID ORDER BY playlist_song_cross.item_number")
|
||||
LiveData<List<Song>> getLivePlaylistSong(String playlistID);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN playlist_song_cross ON song.id = playlist_song_cross.song_id AND playlist_song_cross.playlist_id = :playlistID ORDER BY playlist_song_cross.item_number")
|
||||
List<Song> getPlaylistSong(String playlistID);
|
||||
|
||||
@Query("SELECT * FROM song WHERE albumId = :albumID ORDER BY trackNumber ASC")
|
||||
List<Song> getAlbumSong(String albumID);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN song_genre_cross ON song.id = song_genre_cross.song_id AND song_genre_cross.genre_id = :genreID")
|
||||
LiveData<List<Song>> getSongByGenre(String genreID);
|
||||
|
||||
@Query("SELECT song.* FROM song INNER JOIN song_genre_cross ON song.id = song_genre_cross.song_id AND song_genre_cross.genre_id IN (:filters) GROUP BY song.id")
|
||||
LiveData<List<Song>> getFilteredSong(ArrayList<String> filters);
|
||||
|
||||
@Query("SELECT * FROM song WHERE favorite = 1 LIMIT :number")
|
||||
LiveData<List<Song>> getFavoriteSongSample(int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE favorite = 1")
|
||||
LiveData<List<Song>> getFavoriteSong();
|
||||
|
||||
@Query("SELECT * FROM song WHERE offline = 1 LIMIT :number")
|
||||
LiveData<List<Song>> getDownloadedSongSample(int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE offline = 1 ORDER BY path, albumName, trackNumber")
|
||||
LiveData<List<Song>> getDownloadedSong();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Song> songs);
|
||||
|
||||
@Query("DELETE FROM song")
|
||||
void deleteAll();
|
||||
|
||||
@Update
|
||||
void update(Song song);
|
||||
|
||||
@Query("UPDATE song SET offline = 0 WHERE offline == 1")
|
||||
void updateAllOffline();
|
||||
|
||||
@Query("SELECT * FROM song WHERE id IN (:ids)")
|
||||
List<Song> getSongsByID(List<String> ids);
|
||||
|
||||
@Query("SELECT * FROM song ORDER BY RANDOM() LIMIT :number")
|
||||
List<Song> random(int number);
|
||||
|
||||
@Query("SELECT title FROM song WHERE title LIKE :query || '%' OR title like '% ' || :query || '%' GROUP BY title LIMIT :number")
|
||||
List<String> searchSuggestions(String query, int number);
|
||||
|
||||
@Query("SELECT year FROM song WHERE year != 0 GROUP BY year")
|
||||
List<Integer> getYearList();
|
||||
|
||||
@Query("SELECT * FROM song WHERE year = :year")
|
||||
LiveData<List<Song>> getSongsByYear(int year);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package com.cappielloantonio.play.database.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface SongGenreCrossDao {
|
||||
@Query("SELECT * FROM song_genre_cross")
|
||||
LiveData<List<SongGenreCross>> getAll();
|
||||
|
||||
@Query("SELECT EXISTS(SELECT * FROM song_genre_cross WHERE id = :id)")
|
||||
boolean exist(String id);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(SongGenreCross songGenreCross);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<SongGenreCross> songGenreCrosses);
|
||||
|
||||
@Delete
|
||||
void delete(SongGenreCross songGenreCross);
|
||||
|
||||
@Update
|
||||
void update(SongGenreCross songGenreCross);
|
||||
|
||||
@Query("DELETE FROM song_genre_cross")
|
||||
void deleteAll();
|
||||
}
|
||||
|
|
@ -15,9 +15,33 @@ public class Queue {
|
|||
@ColumnInfo(name = "id")
|
||||
private String songID;
|
||||
|
||||
public Queue(int trackOrder, String songID) {
|
||||
@ColumnInfo(name = "title")
|
||||
private String title;
|
||||
|
||||
@ColumnInfo(name = "albumId")
|
||||
private String albumId;
|
||||
|
||||
@ColumnInfo(name = "albumName")
|
||||
private String albumName;
|
||||
|
||||
@ColumnInfo(name = "artistId")
|
||||
private String artistId;
|
||||
|
||||
@ColumnInfo(name = "artistName")
|
||||
private String artistName;
|
||||
|
||||
@ColumnInfo(name = "primary")
|
||||
private String primary;
|
||||
|
||||
public Queue(int trackOrder, String songID, String title, String albumId, String albumName, String artistId, String artistName, String primary) {
|
||||
this.trackOrder = trackOrder;
|
||||
this.songID = songID;
|
||||
this.title = title;
|
||||
this.albumId = albumId;
|
||||
this.albumName = albumName;
|
||||
this.artistId = artistId;
|
||||
this.artistName = artistName;
|
||||
this.primary = primary;
|
||||
}
|
||||
|
||||
public int getTrackOrder() {
|
||||
|
|
@ -35,4 +59,52 @@ public class Queue {
|
|||
public void setSongID(String songID) {
|
||||
this.songID = songID;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAlbumId() {
|
||||
return albumId;
|
||||
}
|
||||
|
||||
public void setAlbumId(String albumId) {
|
||||
this.albumId = albumId;
|
||||
}
|
||||
|
||||
public String getAlbumName() {
|
||||
return albumName;
|
||||
}
|
||||
|
||||
public void setAlbumName(String albumName) {
|
||||
this.albumName = albumName;
|
||||
}
|
||||
|
||||
public String getArtistId() {
|
||||
return artistId;
|
||||
}
|
||||
|
||||
public void setArtistId(String artistId) {
|
||||
this.artistId = artistId;
|
||||
}
|
||||
|
||||
public String getArtistName() {
|
||||
return artistName;
|
||||
}
|
||||
|
||||
public void setArtistName(String artistName) {
|
||||
this.artistName = artistName;
|
||||
}
|
||||
|
||||
public String getPrimary() {
|
||||
return primary;
|
||||
}
|
||||
|
||||
public void setPrimary(String primary) {
|
||||
this.primary = primary;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,135 +15,46 @@ import com.cappielloantonio.play.subsonic.models.Child;
|
|||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity(tableName = "song")
|
||||
public class Song implements Parcelable {
|
||||
private static final String TAG = "SongClass";
|
||||
|
||||
@Ignore
|
||||
public static final String RECENTLY_PLAYED = "RECENTLY_PLAYED";
|
||||
|
||||
@Ignore
|
||||
public static final String MOST_PLAYED = "MOST_PLAYED";
|
||||
|
||||
@Ignore
|
||||
public static final String RECENTLY_ADDED = "RECENTLY_ADDED";
|
||||
|
||||
@Ignore
|
||||
public static final String BY_GENRE = "BY_GENRE";
|
||||
|
||||
@Ignore
|
||||
public static final String BY_GENRES = "BY_GENRES";
|
||||
|
||||
@Ignore
|
||||
public static final String BY_ARTIST = "BY_ARTIST";
|
||||
|
||||
@Ignore
|
||||
public static final String BY_YEAR = "BY_YEAR";
|
||||
|
||||
@Ignore
|
||||
public static final String IS_FAVORITE = "IS_FAVORITE";
|
||||
|
||||
@Ignore
|
||||
public static final String DOWNLOADED = "DOWNLOADED";
|
||||
|
||||
@Ignore
|
||||
public static final String RADIO = "RADIO";
|
||||
|
||||
@NonNull
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id")
|
||||
private String id;
|
||||
|
||||
@ColumnInfo(name = "title")
|
||||
private String title;
|
||||
|
||||
@ColumnInfo(name = "trackNumber")
|
||||
private int trackNumber;
|
||||
|
||||
@ColumnInfo(name = "discNumber")
|
||||
private int discNumber;
|
||||
|
||||
@ColumnInfo(name = "year")
|
||||
private int year;
|
||||
|
||||
@ColumnInfo(name = "duration")
|
||||
private long duration;
|
||||
|
||||
@ColumnInfo(name = "albumId")
|
||||
private String albumId;
|
||||
|
||||
@ColumnInfo(name = "albumName")
|
||||
private String albumName;
|
||||
|
||||
@ColumnInfo(name = "artistId")
|
||||
private String artistId;
|
||||
|
||||
@ColumnInfo(name = "artistName")
|
||||
private String artistName;
|
||||
|
||||
@ColumnInfo(name = "primary")
|
||||
private String primary;
|
||||
|
||||
@ColumnInfo(name = "blurHash")
|
||||
private String blurHash;
|
||||
|
||||
@ColumnInfo(name = "favorite")
|
||||
private boolean favorite;
|
||||
|
||||
@ColumnInfo(name = "path")
|
||||
private String path;
|
||||
|
||||
@ColumnInfo(name = "size")
|
||||
private long size;
|
||||
|
||||
@ColumnInfo(name = "container")
|
||||
private String container;
|
||||
|
||||
@ColumnInfo(name = "bitRate")
|
||||
private int bitRate;
|
||||
|
||||
@ColumnInfo(name = "added")
|
||||
private long added;
|
||||
|
||||
@ColumnInfo(name = "play_count")
|
||||
private int playCount;
|
||||
|
||||
@ColumnInfo(name = "last_play")
|
||||
private long lastPlay;
|
||||
|
||||
@ColumnInfo(name = "offline")
|
||||
private boolean offline;
|
||||
|
||||
public Song(@NonNull String id, String title, int trackNumber, int discNumber, int year, long duration, String albumId, String albumName, String artistId, String artistName, String primary, String blurHash, boolean favorite, String path, long size, String container, int bitRate, long added, int playCount, long lastPlay, boolean offline) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.trackNumber = trackNumber;
|
||||
this.discNumber = discNumber;
|
||||
this.year = year;
|
||||
this.duration = duration;
|
||||
this.albumId = albumId;
|
||||
this.albumName = albumName;
|
||||
this.artistId = artistId;
|
||||
this.artistName = artistName;
|
||||
this.primary = primary;
|
||||
this.blurHash = blurHash;
|
||||
this.favorite = favorite;
|
||||
this.path = path;
|
||||
this.size = size;
|
||||
this.container = container;
|
||||
this.bitRate = bitRate;
|
||||
this.added = added;
|
||||
this.playCount = playCount;
|
||||
this.lastPlay = lastPlay;
|
||||
this.offline = offline;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public Song() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public Song(Child child) {
|
||||
this.id = child.getId();
|
||||
this.title = child.getTitle();
|
||||
|
|
@ -167,7 +78,16 @@ public class Song implements Parcelable {
|
|||
this.offline = false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Song(Queue queue) {
|
||||
this.id = queue.getSongID();
|
||||
this.title = queue.getTitle();
|
||||
this.albumId = queue.getAlbumId();
|
||||
this.albumName = queue.getAlbumName();
|
||||
this.artistId = queue.getArtistId();
|
||||
this.artistName = queue.getArtistName();
|
||||
this.primary = queue.getPrimary();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -252,7 +172,7 @@ public class Song implements Parcelable {
|
|||
return offline;
|
||||
}
|
||||
|
||||
public void setId(@NonNull String id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,16 +86,10 @@ public class DownloadTracker {
|
|||
DownloadService.sendAddDownload(context, DownloaderService.class, getDownloadRequest(song.getId(), mediaItem.playbackProperties.uri), false);
|
||||
}
|
||||
|
||||
songRepository.setOfflineStatus(song);
|
||||
// songRepository.setOfflineStatus(song);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllDownloads() {
|
||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||
songRepository.setAllOffline();
|
||||
DownloadService.sendRemoveAllDownloads(context, DownloaderService.class, false);
|
||||
}
|
||||
|
||||
private void loadDownloads() {
|
||||
try (DownloadCursor loadedDownloads = downloadIndex.getDownloads()) {
|
||||
while (loadedDownloads.moveToNext()) {
|
||||
|
|
|
|||
|
|
@ -381,8 +381,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
|||
nextPosition = getNextPosition();
|
||||
playback.queueDataSource(getSongAt(nextPosition));
|
||||
}
|
||||
|
||||
increaseSongCount();
|
||||
}
|
||||
|
||||
public void initNotification() {
|
||||
|
|
@ -661,11 +659,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
|||
}
|
||||
}
|
||||
|
||||
private void increaseSongCount() {
|
||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||
songRepository.increasePlayCount(getCurrentSong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(int state) {
|
||||
notifyChange(STATE_CHANGED);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import com.cappielloantonio.play.helper.MusicProgressViewUpdateHelper;
|
|||
import com.cappielloantonio.play.interfaces.MusicServiceEventListener;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
|
||||
|
|
@ -103,7 +104,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
|
||||
playerNowPlayingSongAdapter = new PlayerNowPlayingSongAdapter(requireContext());
|
||||
bind.playerBodyLayout.playerSongCoverViewPager.setAdapter(playerNowPlayingSongAdapter);
|
||||
playerBottomSheetViewModel.getQueueSong().observe(requireActivity(), songs -> playerNowPlayingSongAdapter.setItems(songs));
|
||||
playerBottomSheetViewModel.getQueueSong().observe(requireActivity(), queue -> playerNowPlayingSongAdapter.setItems(MappingUtil.mapQueue(queue)));
|
||||
|
||||
bind.playerBodyLayout.playerSongCoverViewPager.setOffscreenPageLimit(3);
|
||||
bind.playerBodyLayout.playerSongCoverViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
|
|
@ -140,7 +141,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
|
||||
playerSongQueueAdapter = new PlayerSongQueueAdapter(requireContext(), this);
|
||||
bind.playerBodyLayout.playerQueueRecyclerView.setAdapter(playerSongQueueAdapter);
|
||||
playerBottomSheetViewModel.getQueueSong().observe(requireActivity(), songs -> playerSongQueueAdapter.setItems(songs));
|
||||
playerBottomSheetViewModel.getQueueSong().observe(requireActivity(), queue -> playerSongQueueAdapter.setItems(MappingUtil.mapQueue(queue)));
|
||||
|
||||
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT) {
|
||||
int originalPosition = -1;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,8 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
|
||||
playRandom = view.findViewById(R.id.play_random_text_view);
|
||||
playRandom.setOnClickListener(v -> {
|
||||
List<Song> songs = songRepository.getAlbumListSong(album.getId(), true);
|
||||
// List<Song> songs = songRepository.getAlbumListSong(album.getId(), true);
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
||||
queueRepository.insertAllAndStartNew(songs);
|
||||
|
|
@ -122,21 +123,21 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
|
||||
playNext = view.findViewById(R.id.play_next_text_view);
|
||||
playNext.setOnClickListener(v -> {
|
||||
MusicPlayerRemote.playNext(songRepository.getAlbumListSong(album.getId(), false));
|
||||
// MusicPlayerRemote.playNext(songRepository.getAlbumListSong(album.getId(), false));
|
||||
((MainActivity) requireActivity()).isBottomSheetInPeek(true);
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
addToQueue = view.findViewById(R.id.add_to_queue_text_view);
|
||||
addToQueue.setOnClickListener(v -> {
|
||||
MusicPlayerRemote.enqueue(songRepository.getAlbumListSong(album.getId(), false));
|
||||
// MusicPlayerRemote.enqueue(songRepository.getAlbumListSong(album.getId(), false));
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
Download = view.findViewById(R.id.download_text_view);
|
||||
Download.setOnClickListener(v -> {
|
||||
List<Song> songs = songRepository.getAlbumListSong(album.getId(), false);
|
||||
DownloadUtil.getDownloadTracker(requireContext()).toggleDownload(songs);
|
||||
// List<Song> songs = songRepository.getAlbumListSong(album.getId(), false);
|
||||
// DownloadUtil.getDownloadTracker(requireContext()).toggleDownload(songs);
|
||||
dismissBottomSheet();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,8 @@ public class ArtistBottomSheetDialog extends BottomSheetDialogFragment implement
|
|||
|
||||
playRandom = view.findViewById(R.id.play_random_text_view);
|
||||
playRandom.setOnClickListener(v -> {
|
||||
List<Song> songs = songRepository.getArtistListLiveRandomSong(artist.getId());
|
||||
// List<Song> songs = songRepository.getArtistListLiveRandomSong(artist.getId());
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
if(songs.size() > 0) {
|
||||
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.cappielloantonio.play.util;
|
|||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||
|
|
@ -40,4 +41,14 @@ public class MappingUtil {
|
|||
|
||||
return artists;
|
||||
}
|
||||
|
||||
public static ArrayList<Song> mapQueue(List<Queue> queueList) {
|
||||
ArrayList<Song> songs = new ArrayList();
|
||||
|
||||
for(Queue item : queueList){
|
||||
songs.add(new Song(item));
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class QueueUtil {
|
|||
private static final String TAG = "QueueUtil";
|
||||
|
||||
public static Queue getQueueElementFromSong(Song song, int startingPosition) {
|
||||
return new Queue(startingPosition, song.getId());
|
||||
return new Queue(startingPosition, song.getId(), song.getTitle(), song.getAlbumId(), song.getAlbumName(), song.getArtistId(), song.getArtistName(), song.getPrimary());
|
||||
}
|
||||
|
||||
public static List<Queue> getQueueElementsFromSongs(List<Song> songs) {
|
||||
|
|
@ -18,7 +18,7 @@ public class QueueUtil {
|
|||
List<Queue> queue = new ArrayList<>();
|
||||
|
||||
for (Song song : songs) {
|
||||
queue.add(new Queue(counter, song.getId()));
|
||||
queue.add(new Queue(counter, song.getId(), song.getTitle(), song.getAlbumId(), song.getAlbumName(), song.getArtistId(), song.getArtistName(), song.getPrimary()));
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class AlbumBottomSheetViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artistRepository.getArtistByID(album.getArtistId());
|
||||
// return artistRepository.getArtistByID(album.getArtistId());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,13 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Song>> getAlbumSongLiveList() {
|
||||
songLiveList = songRepository.getAlbumListLiveSong(album.getId());
|
||||
// songLiveList = songRepository.getAlbumListLiveSong(album.getId());
|
||||
return songLiveList;
|
||||
}
|
||||
|
||||
public List<Song> getAlbumSongList() {
|
||||
return songRepository.getAlbumListSong(album.getId(), false);
|
||||
// return songRepository.getAlbumListSong(album.getId(), false);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Album getAlbum() {
|
||||
|
|
@ -47,6 +48,7 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artistRepository.getArtistByID(album.getArtistId());
|
||||
// return artistRepository.getArtistByID(album.getArtistId());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class ArtistCatalogueViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Artist>> getArtistList() {
|
||||
artistList = artistRepository.getListLiveArtists();
|
||||
// artistList = artistRepository.getListLiveArtists();
|
||||
return artistList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,17 +32,17 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Album>> getAlbumList() {
|
||||
albumList = albumRepository.getArtistListLiveAlbums(artist.id);
|
||||
// albumList = albumRepository.getArtistListLiveAlbums(artist.id);
|
||||
return albumList;
|
||||
}
|
||||
|
||||
public List<Song> getArtistRandomSongList() {
|
||||
randomList = songRepository.getArtistListLiveRandomSong(artist.id);
|
||||
// randomList = songRepository.getArtistListLiveRandomSong(artist.id);
|
||||
return randomList;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getArtistTopSongList() {
|
||||
songList = songRepository.getArtistListLiveTopSongSample(artist.id);
|
||||
// songList = songRepository.getArtistListLiveTopSongSample(artist.id);
|
||||
return songList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class FilterViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Genre>> getGenreList() {
|
||||
allGenres = genreRepository.getListLiveGenres();
|
||||
// allGenres = genreRepository.getListLiveGenres();
|
||||
return allGenres;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class GenreCatalogueViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Genre>> getGenreList() {
|
||||
genreList = genreRepository.getListLiveGenres();
|
||||
// genreList = genreRepository.getListLiveGenres();
|
||||
return genreList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.app.Application;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
|
|
@ -43,9 +44,12 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
albumRepository = new AlbumRepository(application);
|
||||
artistRepository = new ArtistRepository(application);
|
||||
|
||||
favoritesSongSample = songRepository.getListLiveFavoritesSampleSong(20);
|
||||
downloadedSongSample = songRepository.getListLiveDownloadedSampleSong(20);
|
||||
years = songRepository.getYearList();
|
||||
// favoritesSongSample = songRepository.getListLiveFavoritesSampleSong(20);
|
||||
// downloadedSongSample = songRepository.getListLiveDownloadedSampleSong(20);
|
||||
// years = songRepository.getYearList();
|
||||
|
||||
downloadedSongSample = new MutableLiveData<>();
|
||||
years = new ArrayList<>();
|
||||
|
||||
mostPlayedAlbumSample = albumRepository.getListLiveAlbums("frequent", 20);
|
||||
recentlyAddedAlbumSample = albumRepository.getListLiveAlbums("newest", 20);
|
||||
|
|
|
|||
|
|
@ -38,15 +38,15 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
|
||||
// Inizializzate all'interno del costruttore, in modo da rimanere immutabili per tutto il
|
||||
// ciclo di vita dell'applicazione
|
||||
sampleAlbum = albumRepository.getListLiveSampleAlbum();
|
||||
sampleArtist = artistRepository.getListLiveSampleArtist();
|
||||
sampleGenres = genreRepository.getListLiveSampleGenre();
|
||||
playlistSample = playlistRepository.getRandomSample(5);
|
||||
// sampleAlbum = albumRepository.getListLiveSampleAlbum();
|
||||
// sampleArtist = artistRepository.getListLiveSampleArtist();
|
||||
// sampleGenres = genreRepository.getListLiveSampleGenre();
|
||||
// playlistSample = playlistRepository.getRandomSample(5);
|
||||
}
|
||||
|
||||
public List<Playlist> getPlaylistSample() {
|
||||
if (playlistSample.isEmpty()) {
|
||||
playlistSample = playlistRepository.getRandomSample(5);
|
||||
// playlistSample = playlistRepository.getRandomSample(5);
|
||||
}
|
||||
|
||||
return playlistSample;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
|
@ -19,7 +20,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
private SongRepository songRepository;
|
||||
private QueueRepository queueRepository;
|
||||
|
||||
private LiveData<List<Song>> queueSong;
|
||||
private LiveData<List<Queue>> queueSong;
|
||||
|
||||
public PlayerBottomSheetViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -30,14 +31,14 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
queueSong = queueRepository.getLiveQueue();
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getQueueSong() {
|
||||
public LiveData<List<Queue>> getQueueSong() {
|
||||
return queueSong;
|
||||
}
|
||||
|
||||
public void setFavorite() {
|
||||
Song song = MusicPlayerRemote.getCurrentSong();
|
||||
song.setFavorite(!song.isFavorite());
|
||||
songRepository.setFavoriteStatus(song);
|
||||
// songRepository.setFavoriteStatus(song);
|
||||
}
|
||||
|
||||
public void orderSongAfterSwap(List<Song> songs) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPlaylistList() {
|
||||
playlistList = playlistRepository.getListLivePlaylists();
|
||||
// playlistList = playlistRepository.getListLivePlaylists();
|
||||
return playlistList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,13 @@ public class PlaylistPageViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Song>> getPlaylistSongLiveList() {
|
||||
songLiveList = songRepository.getPlaylistLiveSong(playlist.getId());
|
||||
// songLiveList = songRepository.getPlaylistLiveSong(playlist.getId());
|
||||
return songLiveList;
|
||||
}
|
||||
|
||||
public List<Song> getPlaylistSongList() {
|
||||
return songRepository.getPlaylistSong(playlist.getId());
|
||||
// return songRepository.getPlaylistSong(playlist.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
public Playlist getPlaylist() {
|
||||
|
|
|
|||
|
|
@ -62,22 +62,22 @@ public class SearchViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Song>> searchSong(String title, Context context) {
|
||||
searchSong = songRepository.searchListLiveSong(title, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
// searchSong = songRepository.searchListLiveSong(title, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> searchAlbum(String name, Context context) {
|
||||
searchAlbum = albumRepository.searchListLiveAlbum(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
// searchAlbum = albumRepository.searchListLiveAlbum(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> searchArtist(String name, Context context) {
|
||||
searchArtist = artistRepository.searchListLiveArtist(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
// searchArtist = artistRepository.searchListLiveArtist(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchArtist;
|
||||
}
|
||||
|
||||
public LiveData<List<Genre>> searchGenre(String name, Context context) {
|
||||
searchGenre = genreRepository.searchListLiveGenre(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
// searchGenre = genreRepository.searchListLiveGenre(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchGenre;
|
||||
}
|
||||
|
||||
|
|
@ -91,10 +91,10 @@ public class SearchViewModel extends AndroidViewModel {
|
|||
|
||||
public List<String> getSearchSuggestion(String query) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
suggestions.addAll(songRepository.getSearchSuggestion(query));
|
||||
suggestions.addAll(albumRepository.getSearchSuggestion(query));
|
||||
suggestions.addAll(artistRepository.getSearchSuggestion(query));
|
||||
suggestions.addAll(genreRepository.getSearchSuggestion(query));
|
||||
// suggestions.addAll(songRepository.getSearchSuggestion(query));
|
||||
// suggestions.addAll(albumRepository.getSearchSuggestion(query));
|
||||
// suggestions.addAll(artistRepository.getSearchSuggestion(query));
|
||||
// suggestions.addAll(genreRepository.getSearchSuggestion(query));
|
||||
|
||||
LinkedHashSet<String> hashSet = new LinkedHashSet<>(suggestions);
|
||||
ArrayList<String> suggestionsWithoutDuplicates = new ArrayList<>(hashSet);
|
||||
|
|
|
|||
|
|
@ -37,14 +37,16 @@ public class SongBottomSheetViewModel extends AndroidViewModel {
|
|||
|
||||
public void setFavorite() {
|
||||
song.setFavorite(!song.isFavorite());
|
||||
songRepository.setFavoriteStatus(song);
|
||||
// songRepository.setFavoriteStatus(song);
|
||||
}
|
||||
|
||||
public Album getAlbum() {
|
||||
return albumRepository.getAlbumByID(song.getAlbumId());
|
||||
// return albumRepository.getAlbumByID(song.getAlbumId());
|
||||
return null;
|
||||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artistRepository.getArtistByID(song.getArtistId());
|
||||
// return artistRepository.getArtistByID(song.getArtistId());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,31 +34,31 @@ public class SongListPageViewModel extends AndroidViewModel {
|
|||
public LiveData<List<Song>> getSongList() {
|
||||
switch (title) {
|
||||
case Song.RECENTLY_PLAYED:
|
||||
songList = songRepository.getListLiveRecentlyPlayedSampleSong(100);
|
||||
// songList = songRepository.getListLiveRecentlyPlayedSampleSong(100);
|
||||
break;
|
||||
case Song.MOST_PLAYED:
|
||||
songList = songRepository.getListLiveMostPlayedSampleSong(100);
|
||||
// songList = songRepository.getListLiveMostPlayedSampleSong(100);
|
||||
break;
|
||||
case Song.RECENTLY_ADDED:
|
||||
songList = songRepository.getListLiveRecentlyAddedSampleSong(100);
|
||||
// songList = songRepository.getListLiveRecentlyAddedSampleSong(100);
|
||||
break;
|
||||
case Song.BY_GENRE:
|
||||
songList = songRepository.getListLiveSongByGenre(genre.getId());
|
||||
// songList = songRepository.getListLiveSongByGenre(genre.getId());
|
||||
break;
|
||||
case Song.BY_ARTIST:
|
||||
songList = songRepository.getArtistListLiveTopSong(artist.getId());
|
||||
// songList = songRepository.getArtistListLiveTopSong(artist.getId());
|
||||
break;
|
||||
case Song.BY_GENRES:
|
||||
songList = songRepository.getFilteredListLiveSong(filters);
|
||||
// songList = songRepository.getFilteredListLiveSong(filters);
|
||||
break;
|
||||
case Song.BY_YEAR:
|
||||
songList = songRepository.getSongByYearListLive(year);
|
||||
// songList = songRepository.getSongByYearListLive(year);
|
||||
break;
|
||||
case Song.IS_FAVORITE:
|
||||
songList = songRepository.getListLiveFavoritesSong();
|
||||
// songList = songRepository.getListLiveFavoritesSong();
|
||||
break;
|
||||
case Song.DOWNLOADED:
|
||||
songList = songRepository.getListLiveDownloadedSong();
|
||||
// songList = songRepository.getListLiveDownloadedSong();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,24 +12,17 @@ import com.cappielloantonio.play.repository.AlbumRepository;
|
|||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.GenreRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistSongRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.Genre;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class SyncViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "SyncViewModel";
|
||||
|
||||
|
||||
private boolean syncAlbum = false;
|
||||
private boolean syncArtist = false;
|
||||
private boolean syncGenres = false;
|
||||
|
|
@ -47,7 +40,6 @@ public class SyncViewModel extends AndroidViewModel {
|
|||
private ArtistRepository artistRepository;
|
||||
private PlaylistRepository playlistRepository;
|
||||
private GenreRepository genreRepository;
|
||||
private PlaylistSongRepository playlistSongRepository;
|
||||
|
||||
public SyncViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -57,7 +49,6 @@ public class SyncViewModel extends AndroidViewModel {
|
|||
artistRepository = new ArtistRepository(application);
|
||||
playlistRepository = new PlaylistRepository(application);
|
||||
genreRepository = new GenreRepository(application);
|
||||
playlistSongRepository = new PlaylistSongRepository(application);
|
||||
}
|
||||
|
||||
public void setArguemnts(Bundle bundle) {
|
||||
|
|
@ -131,14 +122,4 @@ public class SyncViewModel extends AndroidViewModel {
|
|||
public void addToSongList(ArrayList<Song> songList) {
|
||||
this.songList.addAll(songList);
|
||||
}
|
||||
|
||||
public Map<Integer, Song> getCatalogue() {
|
||||
Map<Integer, Song> map = new HashMap<>();
|
||||
|
||||
for (Song song : songRepository.getCatalogue()) {
|
||||
map.put(song.hashCode(), song);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue