musikr: re-add playlist adding
This commit is contained in:
parent
f4822a4e40
commit
744097694f
2 changed files with 15 additions and 8 deletions
|
@ -23,9 +23,11 @@ import org.oxycblt.musikr.MutableLibrary
|
||||||
import org.oxycblt.musikr.Playlist
|
import org.oxycblt.musikr.Playlist
|
||||||
import org.oxycblt.musikr.Song
|
import org.oxycblt.musikr.Song
|
||||||
import org.oxycblt.musikr.fs.Path
|
import org.oxycblt.musikr.fs.Path
|
||||||
|
import org.oxycblt.musikr.playlist.PlaylistHandle
|
||||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||||
import org.oxycblt.musikr.playlist.interpret.PlaylistInterpreter
|
import org.oxycblt.musikr.playlist.interpret.PlaylistInterpreter
|
||||||
import org.oxycblt.musikr.playlist.interpret.PostPlaylist
|
import org.oxycblt.musikr.playlist.interpret.PostPlaylist
|
||||||
|
import org.oxycblt.musikr.playlist.interpret.PrePlaylistInfo
|
||||||
|
|
||||||
internal data class LibraryImpl(
|
internal data class LibraryImpl(
|
||||||
override val songs: Collection<SongImpl>,
|
override val songs: Collection<SongImpl>,
|
||||||
|
@ -68,15 +70,22 @@ internal data class LibraryImpl(
|
||||||
val playlistImpl = requireNotNull(playlistUidMap[playlist.uid]) {
|
val playlistImpl = requireNotNull(playlistUidMap[playlist.uid]) {
|
||||||
"Playlist to rename is not in this library"
|
"Playlist to rename is not in this library"
|
||||||
}
|
}
|
||||||
playlistImpl.handle.rename(name)
|
val prePlaylist = playlistImpl.core.prePlaylist
|
||||||
val postPlaylist = playlistInterpreter.interpret(name, playlistImpl.handle)
|
prePlaylist.handle.rename(name)
|
||||||
|
val postPlaylist = playlistInterpreter.interpret(name, prePlaylist.handle)
|
||||||
val core = NewPlaylistCore(postPlaylist, playlist.songs)
|
val core = NewPlaylistCore(postPlaylist, playlist.songs)
|
||||||
val newPlaylist = PlaylistImpl(core)
|
val newPlaylist = PlaylistImpl(core)
|
||||||
return copy(playlists = playlists - playlistImpl + newPlaylist)
|
return copy(playlists = playlists - playlistImpl + newPlaylist)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addToPlaylist(playlist: Playlist, songs: List<Song>): MutableLibrary {
|
override suspend fun addToPlaylist(playlist: Playlist, songs: List<Song>): MutableLibrary {
|
||||||
return this
|
val playlistImpl = requireNotNull(playlistUidMap[playlist.uid]) {
|
||||||
|
"Playlist to add to is not in this library"
|
||||||
|
}
|
||||||
|
playlistImpl.core.prePlaylist.handle.add(songs)
|
||||||
|
val core = NewPlaylistCore(playlistImpl.core.prePlaylist, playlistImpl.songs + songs)
|
||||||
|
val newPlaylist = PlaylistImpl(core)
|
||||||
|
return copy(playlists = playlists - playlistImpl + newPlaylist)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun rewritePlaylist(playlist: Playlist, songs: List<Song>): MutableLibrary {
|
override suspend fun rewritePlaylist(playlist: Playlist, songs: List<Song>): MutableLibrary {
|
||||||
|
@ -88,7 +97,7 @@ internal data class LibraryImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NewPlaylistCore(
|
private class NewPlaylistCore(
|
||||||
override val prePlaylist: PostPlaylist,
|
override val prePlaylist: PrePlaylistInfo,
|
||||||
override val songs: List<Song>
|
override val songs: List<Song>
|
||||||
) : PlaylistCore
|
) : PlaylistCore
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,13 @@ internal interface PlaylistCore {
|
||||||
val songs: List<Song>
|
val songs: List<Song>
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class PlaylistImpl(private val core: PlaylistCore) : Playlist {
|
internal class PlaylistImpl(val core: PlaylistCore) : Playlist {
|
||||||
override val uid = core.prePlaylist.handle.uid
|
override val uid = core.prePlaylist.handle.uid
|
||||||
override val name: Name.Known = core.prePlaylist.name
|
override val name: Name.Known = core.prePlaylist.name
|
||||||
override val durationMs = core.songs.sumOf { it.durationMs }
|
override val durationMs = core.songs.sumOf { it.durationMs }
|
||||||
override val cover = Cover.multi(core.songs)
|
override val cover = Cover.multi(core.songs)
|
||||||
override val songs = core.songs
|
override val songs = core.songs
|
||||||
|
|
||||||
val handle = core.prePlaylist.handle
|
|
||||||
|
|
||||||
private var hashCode =
|
private var hashCode =
|
||||||
31 * (31 * uid.hashCode() + core.prePlaylist.hashCode()) + songs.hashCode()
|
31 * (31 * uid.hashCode() + core.prePlaylist.hashCode()) + songs.hashCode()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue