Code refactor
This commit is contained in:
parent
5ebeb9c587
commit
0ef83c7136
23 changed files with 156 additions and 94 deletions
|
@ -0,0 +1,18 @@
|
|||
package code.name.monkey.retromusic.db
|
||||
|
||||
import androidx.room.*
|
||||
|
||||
@Dao
|
||||
interface LyricsDao {
|
||||
@Query("SELECT * FROM LyricsEntity WHERE songId =:songId LIMIT 1")
|
||||
fun lyricsWithSongId(songId: Int): LyricsEntity?
|
||||
|
||||
@Insert
|
||||
fun insertLyrics(lyricsEntity: LyricsEntity)
|
||||
|
||||
@Delete
|
||||
fun deleteLyrics(lyricsEntity: LyricsEntity)
|
||||
|
||||
@Update
|
||||
fun updateLyrics(lyricsEntity: LyricsEntity)
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package code.name.monkey.retromusic.db
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
class LyricsEntity(
|
||||
@PrimaryKey val songId: Int,
|
||||
val lyrics: String
|
||||
)
|
|
@ -18,10 +18,10 @@ interface PlaylistDao {
|
|||
suspend fun playlists(): List<PlaylistEntity>
|
||||
|
||||
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId")
|
||||
suspend fun deleteSongsInPlaylist(playlistId: Int)
|
||||
suspend fun deletePlaylistSongs(playlistId: Int)
|
||||
|
||||
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
|
||||
suspend fun removeSongFromPlaylist(playlistId: Int, songId: Int)
|
||||
suspend fun deleteSongFromPlaylist(playlistId: Int, songId: Int)
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM PlaylistEntity")
|
||||
|
@ -34,7 +34,7 @@ interface PlaylistDao {
|
|||
suspend fun isSongExistsInPlaylist(playlistId: Int, songId: Int): List<SongEntity>
|
||||
|
||||
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId")
|
||||
suspend fun songsFromPlaylist(playlistId: Int): List<SongEntity>
|
||||
fun songsFromPlaylist(playlistId: Int): LiveData<List<SongEntity>>
|
||||
|
||||
@Delete
|
||||
suspend fun deletePlaylist(playlistEntity: PlaylistEntity)
|
||||
|
@ -43,7 +43,7 @@ interface PlaylistDao {
|
|||
suspend fun deletePlaylists(playlistEntities: List<PlaylistEntity>)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
||||
suspend fun deletePlaylistSongs(songs: List<SongEntity>)
|
||||
|
||||
|
||||
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
|
||||
|
@ -53,5 +53,4 @@ interface PlaylistDao {
|
|||
fun favoritesSongs(playlistId: Int): List<SongEntity>
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -4,8 +4,8 @@ import androidx.room.Database
|
|||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(
|
||||
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class, BlackListStoreEntity::class],
|
||||
version = 20,
|
||||
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class, BlackListStoreEntity::class, LyricsEntity::class],
|
||||
version = 21,
|
||||
exportSchema = false
|
||||
)
|
||||
abstract class RetroDatabase : RoomDatabase() {
|
||||
|
@ -13,4 +13,5 @@ abstract class RetroDatabase : RoomDatabase() {
|
|||
abstract fun blackListStore(): BlackListStoreDao
|
||||
abstract fun playCountDao(): PlayCountDao
|
||||
abstract fun historyDao(): HistoryDao
|
||||
abstract fun lyricsDao(): LyricsDao
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue