From cb69400905bac544b073b1bbde84807834dac434 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Thu, 11 May 2023 13:15:42 -0600 Subject: [PATCH] music: add playlist creation stub Add a stub for creating a new playlist. UX details are not worked out yet, so the functionality is still extremely bare. --- .../oxycblt/auxio/music/MusicRepository.kt | 21 +++++++++++++++++-- .../org/oxycblt/auxio/music/MusicViewModel.kt | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt b/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt index e91bdcbbe..0542e0b59 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt @@ -33,6 +33,7 @@ import org.oxycblt.auxio.music.device.DeviceLibrary import org.oxycblt.auxio.music.device.RawSong import org.oxycblt.auxio.music.fs.MediaStoreExtractor import org.oxycblt.auxio.music.metadata.TagExtractor +import org.oxycblt.auxio.music.user.MutableUserLibrary import org.oxycblt.auxio.music.user.UserLibrary import org.oxycblt.auxio.util.logD import org.oxycblt.auxio.util.logE @@ -110,6 +111,14 @@ interface MusicRepository { */ fun find(uid: Music.UID): Music? + /** + * Create a new [Playlist] of the given [Song]s. + * + * @param name The name of the new [Playlist] + * @param songs The songs to populate the new [Playlist] with. + */ + fun createPlaylist(name: String, songs: List) + /** * Request that a music loading operation is started by the current [IndexingWorker]. Does * nothing if one is not available. @@ -183,7 +192,7 @@ constructor( private var indexingWorker: MusicRepository.IndexingWorker? = null override var deviceLibrary: DeviceLibrary? = null - override var userLibrary: UserLibrary? = null + override var userLibrary: MutableUserLibrary? = null private var previousCompletedState: IndexingState.Completed? = null private var currentIndexingState: IndexingState? = null override val indexingState: IndexingState? @@ -237,6 +246,14 @@ constructor( (deviceLibrary?.run { findSong(uid) ?: findAlbum(uid) ?: findArtist(uid) ?: findGenre(uid) } ?: userLibrary?.findPlaylist(uid)) + override fun createPlaylist(name: String, songs: List) { + userLibrary?.createPlaylist(name, songs) + for (listener in updateListeners) { + listener.onMusicChanges( + MusicRepository.Changes(deviceLibrary = false, userLibrary = true)) + } + } + override fun requestIndex(withCache: Boolean) { indexingWorker?.requestIndex(withCache) } @@ -374,7 +391,7 @@ constructor( } @Synchronized - private fun emitData(deviceLibrary: DeviceLibrary, userLibrary: UserLibrary) { + private fun emitData(deviceLibrary: DeviceLibrary, userLibrary: MutableUserLibrary) { val deviceLibraryChanged = this.deviceLibrary != deviceLibrary val userLibraryChanged = this.userLibrary != userLibrary if (!deviceLibraryChanged && !userLibraryChanged) return diff --git a/app/src/main/java/org/oxycblt/auxio/music/MusicViewModel.kt b/app/src/main/java/org/oxycblt/auxio/music/MusicViewModel.kt index 9397661ba..13a7b0fc3 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/MusicViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/MusicViewModel.kt @@ -84,7 +84,7 @@ class MusicViewModel @Inject constructor(private val musicRepository: MusicRepos * @param name The name of the new playlist. If null, the user will be prompted for a name. */ fun createPlaylist(name: String? = null) { - // TODO: Implement + musicRepository.createPlaylist(name ?: "New playlist", listOf()) } /**