Updated SongEntity to Song

This commit is contained in:
Hemanth S 2020-08-20 15:31:22 +05:30
parent a93dcb0285
commit bcb8f1b42b
6 changed files with 64 additions and 10 deletions

View file

@ -21,7 +21,7 @@ interface PlaylistDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSongs(songEntities: List<SongEntity>)
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistName AND song_id = :songId")
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistName AND id = :songId")
suspend fun checkSongExistsWithPlaylistName(playlistName: String, songId: Int): List<SongEntity>
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId ORDER BY song_key")

View file

@ -7,7 +7,7 @@ import androidx.room.RoomDatabase
@Database(
entities = [PlaylistEntity::class, SongEntity::class],
version = 7,
version = 8,
exportSchema = false
)
abstract class PlaylistDatabase : RoomDatabase() {

View file

@ -4,17 +4,54 @@ import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import code.name.monkey.retromusic.model.Song
import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity
class SongEntity(
@ColumnInfo(name = "song_id")
val songId: Int,
@ColumnInfo(name = "playlist_creator_id")
val playlistCreatorId: Int
val playlistCreatorId: Int,
val id: Int,
val title: String,
@ColumnInfo(name = "track_number")
val trackNumber: Int,
val year: Int,
val duration: Long,
val data: String,
@ColumnInfo(name = "date_modified")
val dateModified: Long,
@ColumnInfo(name = "album_id")
val albumId: Int,
@ColumnInfo(name = "album_name")
val albumName: String,
@ColumnInfo(name = "artist_id")
val artistId: Int,
@ColumnInfo(name = "artist_name")
val artistName: String,
val composer: String?,
@ColumnInfo(name = "album_artist")
val albumArtist: String?
) : Parcelable {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "song_key")
var songPrimaryKey: Long = 0
fun toSong(): Song {
return Song(
id,
title,
trackNumber,
year,
duration,
data,
dateModified,
albumId,
albumName,
artistId,
artistName,
composer,
albumArtist
)
}
}

View file

@ -53,9 +53,7 @@ class AddToRetroPlaylist : DialogFragment() {
}
private fun List<Song>.withPlaylistIds(playlistEntity: PlaylistEntity): List<SongEntity> {
val songEntities = map {
SongEntity(it.id, playlistEntity.playListId)
return map {
it.toSongEntity(playlistEntity.playListId)
}
println(songEntities.size)
return songEntities
}

View file

@ -14,6 +14,7 @@
package code.name.monkey.retromusic.model
import android.os.Parcelable
import code.name.monkey.retromusic.db.SongEntity
import kotlinx.android.parcel.Parcelize
@Parcelize
@ -32,6 +33,24 @@ open class Song(
val composer: String?,
val albumArtist: String?
) : Parcelable {
fun toSongEntity(playListId: Int): SongEntity {
return SongEntity(
playListId,
id,
title,
trackNumber,
year,
duration,
data,
dateModified,
albumId,
albumName,
artistId,
artistName,
composer,
albumArtist
)
}
companion object {

View file

@ -227,7 +227,7 @@ class RealRepository(
override suspend fun playlistSongs(playlistWithSongs: PlaylistWithSongs ): List<Song> {
return playlistWithSongs.songs.map {
songRepository.song(it.songId)
it.toSong()
}
}