Skip to content

Commit

Permalink
music: build saf loader playlist boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
OxygenCobalt committed Nov 24, 2024
1 parent ba9ab5a commit c4f4797
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 399 deletions.
23 changes: 20 additions & 3 deletions app/src/main/java/org/oxycblt/auxio/music/stack/explore/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.oxycblt.auxio.music.stack.explore

import android.net.Uri
import org.oxycblt.auxio.music.Music
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.music.stack.interpret.model.SongImpl
import org.oxycblt.auxio.music.info.Date
import org.oxycblt.auxio.music.stack.explore.fs.Path
Expand Down Expand Up @@ -61,6 +63,21 @@ data class AudioFile(
var genreNames: List<String> = listOf()
)

interface PlaylistFile {
val name: String
}
data class PlaylistFile(
val name: String,
val songPointers: List<SongPointer>,
val editor: PlaylistHandle
)

interface PlaylistHandle {
val uid: Music.UID
suspend fun rename(name: String)
suspend fun add(songs: List<Song>)
suspend fun rewrite(songs: List<Song>)
suspend fun delete()
}

sealed interface SongPointer {
data class UID(val uid: Music.UID) : SongPointer
// data class Path(val options: List<Path>) : SongPointer
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.oxycblt.auxio.music.user
package org.oxycblt.auxio.music.stack.explore.playlists

import androidx.room.Dao
import androidx.room.Database
Expand All @@ -38,7 +38,7 @@ import org.oxycblt.auxio.music.Music
version = 30,
exportSchema = false)
@TypeConverters(Music.UID.TypeConverters::class)
abstract class UserMusicDatabase : RoomDatabase() {
abstract class PlaylistDatabase : RoomDatabase() {
abstract fun playlistDao(): PlaylistDao
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.oxycblt.auxio.music.user
package org.oxycblt.auxio.music.stack.explore.playlists

import androidx.room.ColumnInfo
import androidx.room.Embedded
Expand All @@ -27,7 +27,7 @@ import androidx.room.Relation
import org.oxycblt.auxio.music.Music

/**
* Raw playlist information persisted to [UserMusicDatabase].
* Raw playlist information persisted to [PlaylistDatabase].
*
* @author Alexander Capehart (OxygenCobalt)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.oxycblt.auxio.music.stack.explore.playlists

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import org.oxycblt.auxio.music.stack.explore.PlaylistFile
import org.oxycblt.auxio.music.stack.explore.SongPointer
import javax.inject.Inject

interface StoredPlaylists {
fun read(): Flow<PlaylistFile>
}

class StoredPlaylistsImpl @Inject constructor(
private val playlistDao: PlaylistDao
) : StoredPlaylists {
override fun read() = flow {
emitAll(playlistDao.readRawPlaylists()
.asFlow()
.map {
TODO()
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.oxycblt.auxio.music.user
package org.oxycblt.auxio.music.stack.explore.playlists

import android.content.Context
import androidx.room.Room
Expand All @@ -29,19 +29,19 @@ import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
interface UserModule {
@Binds fun userLibraryFactory(factory: UserLibraryFactoryImpl): UserLibrary.Factory
interface PlaylistModule {
@Binds fun storedPlaylists(impl: StoredPlaylistsImpl): StoredPlaylists
}

@Module
@InstallIn(SingletonComponent::class)
class UserRoomModule {
@Provides fun playlistDao(database: UserMusicDatabase) = database.playlistDao()
class PlaylistRoomModule {
@Provides fun playlistDao(database: PlaylistDatabase) = database.playlistDao()

@Provides
fun userMusicDatabase(@ApplicationContext context: Context) =
fun playlistDatabase(@ApplicationContext context: Context) =
Room.databaseBuilder(
context.applicationContext, UserMusicDatabase::class.java, "user_music.db")
context.applicationContext, PlaylistDatabase::class.java, "user_music.db")
.fallbackToDestructiveMigration()
.build()
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.oxycblt.auxio.music.stack.interpret.linker

import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.music.stack.explore.PlaylistFile
import org.oxycblt.auxio.music.stack.interpret.model.AlbumImpl
import org.oxycblt.auxio.music.stack.interpret.model.ArtistImpl
import org.oxycblt.auxio.music.stack.interpret.model.GenreImpl
import org.oxycblt.auxio.music.stack.interpret.model.PlaylistImpl
import org.oxycblt.auxio.music.stack.interpret.model.SongImpl
import org.oxycblt.auxio.music.stack.interpret.prepare.PreAlbum
import org.oxycblt.auxio.music.stack.interpret.prepare.PrePlaylist
import org.oxycblt.auxio.music.stack.interpret.prepare.PreSong

interface LinkedSong {
Expand All @@ -19,6 +23,11 @@ interface LinkedAlbum {
val artists: Linked<List<ArtistImpl>, AlbumImpl>
}

interface LinkedPlaylist {
val prePlaylist: PrePlaylist
val songs: Linked<List<SongImpl>, PlaylistImpl>
}

interface Linked<P, C> {
fun resolve(child: C): P
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.oxycblt.auxio.music.stack.interpret.linker

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import org.oxycblt.auxio.music.stack.explore.PlaylistFile
import org.oxycblt.auxio.music.stack.interpret.model.GenreImpl
import org.oxycblt.auxio.music.stack.interpret.model.PlaylistImpl
import org.oxycblt.auxio.music.stack.interpret.model.SongImpl
import org.oxycblt.auxio.music.stack.interpret.prepare.PreSong


class PlaylistLinker {
fun register(playlists: Flow<PlaylistFile>, linkedSongs: Flow<AlbumLinker.LinkedSong>): Flow<LinkedPlaylist> = emptyFlow()
fun resolve(): Collection<PlaylistImpl> = setOf()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023 Auxio Project
* PlaylistImpl.kt is part of Auxio.
*
* This program 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 program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.oxycblt.auxio.music.stack.interpret.model

import org.oxycblt.auxio.image.extractor.ParentCover
import org.oxycblt.auxio.music.Music
import org.oxycblt.auxio.music.MusicType
import org.oxycblt.auxio.music.Playlist
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.music.info.Name
import org.oxycblt.auxio.music.stack.explore.PlaylistFile
import org.oxycblt.auxio.music.stack.explore.playlists.RawPlaylist
import org.oxycblt.auxio.music.stack.interpret.linker.LinkedPlaylist

class PlaylistImpl(linkedPlaylist: LinkedPlaylist) : Playlist {
private val prePlaylist = linkedPlaylist.prePlaylist
override val uid = prePlaylist.handle.uid
override val name: Name.Known = prePlaylist.name
override val songs = linkedPlaylist.songs.resolve(this)
override val durationMs = songs.sumOf { it.durationMs }
override val cover = songs.takeIf { it.isNotEmpty() }?.let { ParentCover.from(it.first(), it) }
private var hashCode = uid.hashCode()

init {
hashCode = 31 * hashCode + prePlaylist.hashCode()
hashCode = 31 * hashCode + songs.hashCode()
}

override fun equals(other: Any?) =
other is PlaylistImpl && prePlaylist == other.prePlaylist && songs == other.songs

override fun hashCode() = hashCode

override fun toString() = "Playlist(uid=$uid, name=$name)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import org.oxycblt.auxio.music.info.Date
import org.oxycblt.auxio.music.info.Disc
import org.oxycblt.auxio.music.info.Name
import org.oxycblt.auxio.music.info.ReleaseType
import org.oxycblt.auxio.music.stack.explore.PlaylistFile
import org.oxycblt.auxio.music.stack.explore.PlaylistHandle
import org.oxycblt.auxio.music.stack.explore.fs.MimeType
import org.oxycblt.auxio.music.stack.explore.fs.Path
import org.oxycblt.auxio.playback.replaygain.ReplayGainAdjustment
import java.util.UUID

interface PrePlaylist

data class PreSong(
val musicBrainzId: UUID?,
val name: Name,
Expand Down Expand Up @@ -51,3 +51,9 @@ data class PreGenre(
val name: Name,
val rawName: String?,
)

data class PrePlaylist(
val name: Name.Known,
val rawName: String?,
val handle: PlaylistHandle
)
103 changes: 0 additions & 103 deletions app/src/main/java/org/oxycblt/auxio/music/user/PlaylistImpl.kt

This file was deleted.

Loading

0 comments on commit c4f4797

Please sign in to comment.