musikr: track playlist source files in the database
This commit is contained in:
@@ -41,5 +41,8 @@ internal interface PlaylistHandle {
|
|||||||
|
|
||||||
suspend fun rewrite(songs: List<Song>)
|
suspend fun rewrite(songs: List<Song>)
|
||||||
|
|
||||||
|
/** Update the stored source-file signature after a re-import. */
|
||||||
|
suspend fun updateSignature(signature: Long)
|
||||||
|
|
||||||
suspend fun delete()
|
suspend fun delete()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import org.oxycblt.musikr.Music
|
|||||||
*/
|
*/
|
||||||
@Database(
|
@Database(
|
||||||
entities = [PlaylistInfo::class, PlaylistSong::class, PlaylistSongCrossRef::class],
|
entities = [PlaylistInfo::class, PlaylistSong::class, PlaylistSongCrossRef::class],
|
||||||
version = 75,
|
version = 76,
|
||||||
exportSchema = false,
|
exportSchema = false,
|
||||||
)
|
)
|
||||||
@TypeConverters(Music.UID.TypeConverters::class)
|
@TypeConverters(Music.UID.TypeConverters::class)
|
||||||
@@ -117,7 +117,15 @@ internal abstract class PlaylistDatabase : RoomDatabase() {
|
|||||||
washUids(db, "PlaylistInfo", "playlistUid")
|
washUids(db, "PlaylistInfo", "playlistUid")
|
||||||
washUids(db, "PlaylistSongCrossRef", "playlistUid")
|
washUids(db, "PlaylistSongCrossRef", "playlistUid")
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
object : Migration(75, 76) {
|
||||||
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
|
db.execSQL("ALTER TABLE PlaylistInfo ADD COLUMN sourceUri TEXT")
|
||||||
|
db.execSQL(
|
||||||
|
"ALTER TABLE PlaylistInfo ADD COLUMN sourceSignature INTEGER"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.fallbackToDestructiveMigration(true)
|
.fallbackToDestructiveMigration(true)
|
||||||
.build()
|
.build()
|
||||||
@@ -143,6 +151,10 @@ internal abstract class PlaylistDao {
|
|||||||
@Query("SELECT * FROM PlaylistInfo")
|
@Query("SELECT * FROM PlaylistInfo")
|
||||||
abstract suspend fun readRawPlaylists(): List<RawPlaylist>
|
abstract suspend fun readRawPlaylists(): List<RawPlaylist>
|
||||||
|
|
||||||
|
/** Read the [PlaylistInfo] of playlists with a source file, for reconciliation. */
|
||||||
|
@Query("SELECT * FROM PlaylistInfo WHERE sourceUri IS NOT NULL AND sourceSignature IS NOT NULL")
|
||||||
|
abstract suspend fun readTrackedInfos(): List<PlaylistInfo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new playlist.
|
* Create a new playlist.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -46,7 +46,15 @@ internal data class RawPlaylist(
|
|||||||
*
|
*
|
||||||
* @author Alexander Capehart (OxygenCobalt)
|
* @author Alexander Capehart (OxygenCobalt)
|
||||||
*/
|
*/
|
||||||
@Entity internal data class PlaylistInfo(@PrimaryKey val playlistUid: Music.UID, val name: String)
|
@Entity
|
||||||
|
internal data class PlaylistInfo(
|
||||||
|
@PrimaryKey val playlistUid: Music.UID,
|
||||||
|
val name: String,
|
||||||
|
/** The document URI of the file this playlist was imported from. Null if unmanaged. */
|
||||||
|
val sourceUri: String? = null,
|
||||||
|
/** The content signature of the source file at import time. Null if unmanaged. */
|
||||||
|
val sourceSignature: Long? = null,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Song information corresponding to a [RawPlaylist] entry.
|
* Song information corresponding to a [RawPlaylist] entry.
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ internal class StoredPlaylistHandle(
|
|||||||
playlistDao.replacePlaylistSongs(uid, songs.map { PlaylistSong(it.uid) })
|
playlistDao.replacePlaylistSongs(uid, songs.map { PlaylistSong(it.uid) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateSignature(signature: Long) {
|
||||||
|
playlistDao.replacePlaylistInfo(playlistInfo.copy(sourceSignature = signature))
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun add(songs: List<Song>) {
|
override suspend fun add(songs: List<Song>) {
|
||||||
playlistDao.insertPlaylistSongs(uid, songs.map { PlaylistSong(it.uid) })
|
playlistDao.insertPlaylistSongs(uid, songs.map { PlaylistSong(it.uid) })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,24 @@ import org.oxycblt.musikr.Music
|
|||||||
import org.oxycblt.musikr.Song
|
import org.oxycblt.musikr.Song
|
||||||
import org.oxycblt.musikr.playlist.PlaylistFile
|
import org.oxycblt.musikr.playlist.PlaylistFile
|
||||||
import org.oxycblt.musikr.playlist.PlaylistHandle
|
import org.oxycblt.musikr.playlist.PlaylistHandle
|
||||||
|
import org.oxycblt.musikr.playlist.PlaylistReconciler
|
||||||
import org.oxycblt.musikr.playlist.SongPointer
|
import org.oxycblt.musikr.playlist.SongPointer
|
||||||
|
import org.oxycblt.musikr.util.unlikelyToBeNull
|
||||||
|
|
||||||
abstract class StoredPlaylists {
|
abstract class StoredPlaylists {
|
||||||
internal abstract suspend fun new(name: String, songs: List<Song>): PlaylistHandle
|
internal abstract suspend fun new(name: String, songs: List<Song>): PlaylistHandle
|
||||||
|
|
||||||
|
/** Create a playlist tracked against a source file. */
|
||||||
|
internal abstract suspend fun newTracked(
|
||||||
|
name: String,
|
||||||
|
songs: List<Song>,
|
||||||
|
sourceUri: String,
|
||||||
|
sourceSignature: Long,
|
||||||
|
): PlaylistHandle
|
||||||
|
|
||||||
|
/** Read the tracking identities of playlists with a source file. */
|
||||||
|
internal abstract suspend fun readTracked(): List<PlaylistReconciler.Tracked>
|
||||||
|
|
||||||
internal abstract suspend fun read(): List<PlaylistFile>
|
internal abstract suspend fun read(): List<PlaylistFile>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -43,6 +56,32 @@ private class StoredPlaylistsImpl(private val playlistDao: PlaylistDao) : Stored
|
|||||||
return StoredPlaylistHandle(info, playlistDao)
|
return StoredPlaylistHandle(info, playlistDao)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun newTracked(
|
||||||
|
name: String,
|
||||||
|
songs: List<Song>,
|
||||||
|
sourceUri: String,
|
||||||
|
sourceSignature: Long,
|
||||||
|
): PlaylistHandle {
|
||||||
|
val info =
|
||||||
|
PlaylistInfo(
|
||||||
|
Music.UID.auxio(Music.UID.Item.PLAYLIST),
|
||||||
|
name,
|
||||||
|
sourceUri = sourceUri,
|
||||||
|
sourceSignature = sourceSignature,
|
||||||
|
)
|
||||||
|
playlistDao.insertPlaylist(RawPlaylist(info, songs.map { PlaylistSong(it.uid) }))
|
||||||
|
return StoredPlaylistHandle(info, playlistDao)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun readTracked() =
|
||||||
|
playlistDao.readTrackedInfos().map {
|
||||||
|
PlaylistReconciler.Tracked(
|
||||||
|
it.playlistUid,
|
||||||
|
unlikelyToBeNull(it.sourceUri),
|
||||||
|
unlikelyToBeNull(it.sourceSignature),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun read() =
|
override suspend fun read() =
|
||||||
playlistDao.readRawPlaylists().map {
|
playlistDao.readRawPlaylists().map {
|
||||||
PlaylistFile(
|
PlaylistFile(
|
||||||
|
|||||||
Reference in New Issue
Block a user