Tweak Database.kt code
This commit is contained in:
parent
ed7ee1b6c0
commit
98939b6ac1
1 changed files with 18 additions and 52 deletions
|
@ -313,21 +313,12 @@ interface Database {
|
|||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(searchQuery: SearchQuery)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(info: Artist): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(info: Album): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(playlist: Playlist): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(songPlaylistMap: SongPlaylistMap): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(songAlbumMap: SongAlbumMap): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.ABORT)
|
||||
fun insert(songArtistMap: SongArtistMap): Long
|
||||
|
||||
|
@ -340,6 +331,12 @@ interface Database {
|
|||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insertSongPlaylistMaps(songPlaylistMaps: List<SongPlaylistMap>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(album: Album, songAlbumMap: SongAlbumMap)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(artists: List<Artist>, songArtistMaps: List<SongArtistMap>)
|
||||
|
||||
@Transaction
|
||||
fun insert(mediaItem: MediaItem, block: (Song) -> Song = { it }) {
|
||||
val song = Song(
|
||||
|
@ -353,49 +350,27 @@ interface Database {
|
|||
}
|
||||
|
||||
mediaItem.mediaMetadata.extras?.getString("albumId")?.let { albumId ->
|
||||
Album(
|
||||
id = albumId,
|
||||
title = mediaItem.mediaMetadata.albumTitle?.toString(),
|
||||
year = null,
|
||||
authorsText = null,
|
||||
thumbnailUrl = null,
|
||||
shareUrl = null,
|
||||
timestamp = null,
|
||||
).also(::insert)
|
||||
|
||||
upsert(
|
||||
SongAlbumMap(
|
||||
songId = song.id,
|
||||
albumId = albumId,
|
||||
position = null
|
||||
)
|
||||
insert(
|
||||
Album(id = albumId, title = mediaItem.mediaMetadata.albumTitle?.toString()),
|
||||
SongAlbumMap(songId = song.id, albumId = albumId, position = null)
|
||||
)
|
||||
}
|
||||
|
||||
mediaItem.mediaMetadata.extras?.getStringArrayList("artistNames")?.let { artistNames ->
|
||||
mediaItem.mediaMetadata.extras?.getStringArrayList("artistIds")?.let { artistIds ->
|
||||
artistNames.mapIndexed { index, artistName ->
|
||||
Artist(
|
||||
id = artistIds[index],
|
||||
name = artistName,
|
||||
thumbnailUrl = null,
|
||||
info = null,
|
||||
timestamp = null
|
||||
).also(::insert)
|
||||
}
|
||||
}
|
||||
}?.forEach { artist ->
|
||||
if (artistNames.size == artistIds.size) {
|
||||
insert(
|
||||
SongArtistMap(
|
||||
songId = song.id,
|
||||
artistId = artist.id
|
||||
)
|
||||
artistNames.mapIndexed { index, artistName ->
|
||||
Artist(id = artistIds[index], name = artistName)
|
||||
},
|
||||
artistIds.map { artistId ->
|
||||
SongArtistMap(songId = song.id, artistId = artistId)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Update
|
||||
fun update(song: Song)
|
||||
}
|
||||
}
|
||||
|
||||
@Update
|
||||
fun update(artist: Artist)
|
||||
|
@ -403,12 +378,6 @@ interface Database {
|
|||
@Update
|
||||
fun update(album: Album)
|
||||
|
||||
@Update
|
||||
fun update(songAlbumMap: SongAlbumMap)
|
||||
|
||||
@Update
|
||||
fun update(songPlaylistMap: SongPlaylistMap)
|
||||
|
||||
@Update
|
||||
fun update(playlist: Playlist)
|
||||
|
||||
|
@ -427,9 +396,6 @@ interface Database {
|
|||
@Delete
|
||||
fun delete(playlist: Playlist)
|
||||
|
||||
@Delete
|
||||
fun delete(playlist: Album)
|
||||
|
||||
@Delete
|
||||
fun delete(songPlaylistMap: SongPlaylistMap)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue