154 lines
3.8 KiB
Kotlin
154 lines
3.8 KiB
Kotlin
/*
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
|
*
|
|
* Licensed under the GNU General Public License v3
|
|
*
|
|
* This is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
*/
|
|
package code.name.monkey.retromusic.db
|
|
|
|
import code.name.monkey.retromusic.model.Song
|
|
|
|
fun List<HistoryEntity>.fromHistoryToSongs(): List<Song> {
|
|
return map {
|
|
it.toSong()
|
|
}
|
|
}
|
|
|
|
fun List<SongEntity>.toSongs(): List<Song> {
|
|
return map {
|
|
it.toSong()
|
|
}
|
|
}
|
|
|
|
fun List<Song>.toSongs(playlistId: Long): List<SongEntity> {
|
|
return map {
|
|
it.toSongEntity(playlistId)
|
|
}
|
|
}
|
|
|
|
fun Song.toHistoryEntity(timePlayed: Long): HistoryEntity {
|
|
return HistoryEntity(
|
|
id = id,
|
|
title = title,
|
|
trackNumber = trackNumber,
|
|
year = year,
|
|
duration = duration,
|
|
data = data,
|
|
dateModified = dateModified,
|
|
albumId = albumId,
|
|
albumName = albumName,
|
|
artistId = artistId,
|
|
artistName = artistName,
|
|
composer = composer,
|
|
albumArtist = albumArtist,
|
|
timePlayed = timePlayed
|
|
)
|
|
}
|
|
|
|
fun Song.toSongEntity(playListId: Long): SongEntity {
|
|
return SongEntity(
|
|
playlistCreatorId = playListId,
|
|
id = id,
|
|
title = title,
|
|
trackNumber = trackNumber,
|
|
year = year,
|
|
duration = duration,
|
|
data = data,
|
|
dateModified = dateModified,
|
|
albumId = albumId,
|
|
albumName = albumName,
|
|
artistId = artistId,
|
|
artistName = artistName,
|
|
composer = composer,
|
|
albumArtist = albumArtist
|
|
)
|
|
}
|
|
|
|
fun SongEntity.toSong(): Song {
|
|
return Song(
|
|
id = id,
|
|
title = title,
|
|
trackNumber = trackNumber,
|
|
year = year,
|
|
duration = duration,
|
|
data = data,
|
|
dateModified = dateModified,
|
|
albumId = albumId,
|
|
albumName = albumName,
|
|
artistId = artistId,
|
|
artistName = artistName,
|
|
composer = composer,
|
|
albumArtist = albumArtist
|
|
)
|
|
}
|
|
|
|
fun PlayCountEntity.toSong(): Song {
|
|
return Song(
|
|
id = id,
|
|
title = title,
|
|
trackNumber = trackNumber,
|
|
year = year,
|
|
duration = duration,
|
|
data = data,
|
|
dateModified = dateModified,
|
|
albumId = albumId,
|
|
albumName = albumName,
|
|
artistId = artistId,
|
|
artistName = artistName,
|
|
composer = composer,
|
|
albumArtist = albumArtist
|
|
)
|
|
}
|
|
|
|
fun HistoryEntity.toSong(): Song {
|
|
return Song(
|
|
id = id,
|
|
title = title,
|
|
trackNumber = trackNumber,
|
|
year = year,
|
|
duration = duration,
|
|
data = data,
|
|
dateModified = dateModified,
|
|
albumId = albumId,
|
|
albumName = albumName,
|
|
artistId = artistId,
|
|
artistName = artistName,
|
|
composer = composer,
|
|
albumArtist = albumArtist
|
|
)
|
|
}
|
|
|
|
fun Song.toPlayCount(): PlayCountEntity {
|
|
return PlayCountEntity(
|
|
id = id,
|
|
title = title,
|
|
trackNumber = trackNumber,
|
|
year = year,
|
|
duration = duration,
|
|
data = data,
|
|
dateModified = dateModified,
|
|
albumId = albumId,
|
|
albumName = albumName,
|
|
artistId = artistId,
|
|
artistName = artistName,
|
|
composer = composer,
|
|
albumArtist = albumArtist,
|
|
timePlayed = System.currentTimeMillis(),
|
|
playCount = 1
|
|
)
|
|
}
|
|
|
|
fun List<Song>.toSongsEntity(playlistEntity: PlaylistEntity): List<SongEntity> {
|
|
return map {
|
|
it.toSongEntity(playlistEntity.playListId)
|
|
}
|
|
}
|