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) @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSongs(songEntities: List<SongEntity>) 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> suspend fun checkSongExistsWithPlaylistName(playlistName: String, songId: Int): List<SongEntity>
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId ORDER BY song_key") @Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId ORDER BY song_key")

View file

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

View file

@ -4,17 +4,54 @@ import android.os.Parcelable
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import code.name.monkey.retromusic.model.Song
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity @Entity
class SongEntity( class SongEntity(
@ColumnInfo(name = "song_id")
val songId: Int,
@ColumnInfo(name = "playlist_creator_id") @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 { ) : Parcelable {
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "song_key") @ColumnInfo(name = "song_key")
var songPrimaryKey: Long = 0 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> { private fun List<Song>.withPlaylistIds(playlistEntity: PlaylistEntity): List<SongEntity> {
val songEntities = map { return map {
SongEntity(it.id, playlistEntity.playListId) it.toSongEntity(playlistEntity.playListId)
} }
println(songEntities.size)
return songEntities
} }

View file

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

View file

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