musikr: re-add playlist renaming
This commit is contained in:
parent
9f657adf94
commit
f4822a4e40
2 changed files with 15 additions and 4 deletions
|
@ -32,7 +32,7 @@ internal data class LibraryImpl(
|
||||||
override val albums: Collection<AlbumImpl>,
|
override val albums: Collection<AlbumImpl>,
|
||||||
override val artists: Collection<ArtistImpl>,
|
override val artists: Collection<ArtistImpl>,
|
||||||
override val genres: Collection<GenreImpl>,
|
override val genres: Collection<GenreImpl>,
|
||||||
override val playlists: Collection<Playlist>,
|
override val playlists: Collection<PlaylistImpl>,
|
||||||
private val storedPlaylists: StoredPlaylists,
|
private val storedPlaylists: StoredPlaylists,
|
||||||
private val playlistInterpreter: PlaylistInterpreter
|
private val playlistInterpreter: PlaylistInterpreter
|
||||||
) : MutableLibrary {
|
) : MutableLibrary {
|
||||||
|
@ -58,14 +58,21 @@ internal data class LibraryImpl(
|
||||||
|
|
||||||
override suspend fun createPlaylist(name: String, songs: List<Song>): MutableLibrary {
|
override suspend fun createPlaylist(name: String, songs: List<Song>): MutableLibrary {
|
||||||
val handle = storedPlaylists.new(name, songs)
|
val handle = storedPlaylists.new(name, songs)
|
||||||
val prePlaylist = playlistInterpreter.interpret(name, handle)
|
val postPlaylist = playlistInterpreter.interpret(name, handle)
|
||||||
val core = NewPlaylistCore(prePlaylist, songs)
|
val core = NewPlaylistCore(postPlaylist, songs)
|
||||||
val playlist = PlaylistImpl(core)
|
val playlist = PlaylistImpl(core)
|
||||||
return copy(playlists = playlists + playlist)
|
return copy(playlists = playlists + playlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun renamePlaylist(playlist: Playlist, name: String): MutableLibrary {
|
override suspend fun renamePlaylist(playlist: Playlist, name: String): MutableLibrary {
|
||||||
return this
|
val playlistImpl = requireNotNull(playlistUidMap[playlist.uid]) {
|
||||||
|
"Playlist to rename is not in this library"
|
||||||
|
}
|
||||||
|
playlistImpl.handle.rename(name)
|
||||||
|
val postPlaylist = playlistInterpreter.interpret(name, playlistImpl.handle)
|
||||||
|
val core = NewPlaylistCore(postPlaylist, playlist.songs)
|
||||||
|
val newPlaylist = PlaylistImpl(core)
|
||||||
|
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 {
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.oxycblt.musikr.model
|
||||||
import org.oxycblt.musikr.Playlist
|
import org.oxycblt.musikr.Playlist
|
||||||
import org.oxycblt.musikr.Song
|
import org.oxycblt.musikr.Song
|
||||||
import org.oxycblt.musikr.cover.Cover
|
import org.oxycblt.musikr.cover.Cover
|
||||||
|
import org.oxycblt.musikr.playlist.interpret.PlaylistInterpreter
|
||||||
import org.oxycblt.musikr.playlist.interpret.PrePlaylistInfo
|
import org.oxycblt.musikr.playlist.interpret.PrePlaylistInfo
|
||||||
import org.oxycblt.musikr.tag.Name
|
import org.oxycblt.musikr.tag.Name
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ internal class PlaylistImpl(private val core: PlaylistCore) : Playlist {
|
||||||
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()
|
||||||
|
|
||||||
|
@ -45,4 +48,5 @@ internal class PlaylistImpl(private val core: PlaylistCore) : Playlist {
|
||||||
override fun hashCode() = hashCode
|
override fun hashCode() = hashCode
|
||||||
|
|
||||||
override fun toString() = "Playlist(uid=$uid, name=$name)"
|
override fun toString() = "Playlist(uid=$uid, name=$name)"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue