mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-01 07:03:35 +00:00
Add song/genre sync
This commit is contained in:
@@ -12,14 +12,16 @@ import com.cappielloantonio.play.database.dao.GenreDao;
|
||||
import com.cappielloantonio.play.database.dao.PlaylistDao;
|
||||
import com.cappielloantonio.play.database.dao.RecentSearchDao;
|
||||
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.Artist;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
@Database(entities = {Album.class, Artist.class, Genre.class, Playlist.class, Song.class, RecentSearch.class}, version = 4, exportSchema = false)
|
||||
@Database(entities = {Album.class, Artist.class, Genre.class, Playlist.class, Song.class, RecentSearch.class, SongGenreCross.class}, version = 5, exportSchema = false)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
private static final String TAG = "AppDatabase";
|
||||
|
||||
@@ -47,4 +49,6 @@ public abstract class AppDatabase extends RoomDatabase {
|
||||
public abstract SongDao songDao();
|
||||
|
||||
public abstract RecentSearchDao recentSearchDao();
|
||||
|
||||
public abstract SongGenreCrossDao songGenreCrossDao();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ 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);
|
||||
|
||||
|
||||
@@ -35,9 +35,15 @@ public interface SongDao {
|
||||
@Query("SELECT * FROM song WHERE play_count != 0 AND artistId = :artistID ORDER BY play_count DESC LIMIT :number")
|
||||
LiveData<List<Song>> getArtistTopSongsSample(String artistID, int number);
|
||||
|
||||
@Query("SELECT * FROM song WHERE artistId = :artistID ORDER BY play_count DESC")
|
||||
LiveData<List<Song>> getArtistTopSongs(String artistID);
|
||||
|
||||
@Query("SELECT * FROM song WHERE albumId = :albumID ORDER BY trackNumber ASC")
|
||||
LiveData<List<Song>> getAlbumSong(String albumID);
|
||||
|
||||
@Query("SELECT * 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 EXISTS(SELECT * FROM song WHERE id = :id)")
|
||||
boolean exist(String id);
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
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.Song;
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user