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)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insert(searchQuery: SearchQuery)
|
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)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
fun insert(playlist: Playlist): Long
|
fun insert(playlist: Playlist): Long
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
fun insert(songPlaylistMap: SongPlaylistMap): Long
|
fun insert(songPlaylistMap: SongPlaylistMap): Long
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
|
||||||
fun insert(songAlbumMap: SongAlbumMap): Long
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.ABORT)
|
@Insert(onConflict = OnConflictStrategy.ABORT)
|
||||||
fun insert(songArtistMap: SongArtistMap): Long
|
fun insert(songArtistMap: SongArtistMap): Long
|
||||||
|
|
||||||
|
@ -340,6 +331,12 @@ interface Database {
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
fun insertSongPlaylistMaps(songPlaylistMaps: List<SongPlaylistMap>)
|
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
|
@Transaction
|
||||||
fun insert(mediaItem: MediaItem, block: (Song) -> Song = { it }) {
|
fun insert(mediaItem: MediaItem, block: (Song) -> Song = { it }) {
|
||||||
val song = Song(
|
val song = Song(
|
||||||
|
@ -353,62 +350,34 @@ interface Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaItem.mediaMetadata.extras?.getString("albumId")?.let { albumId ->
|
mediaItem.mediaMetadata.extras?.getString("albumId")?.let { albumId ->
|
||||||
Album(
|
insert(
|
||||||
id = albumId,
|
Album(id = albumId, title = mediaItem.mediaMetadata.albumTitle?.toString()),
|
||||||
title = mediaItem.mediaMetadata.albumTitle?.toString(),
|
SongAlbumMap(songId = song.id, albumId = albumId, position = null)
|
||||||
year = null,
|
|
||||||
authorsText = null,
|
|
||||||
thumbnailUrl = null,
|
|
||||||
shareUrl = null,
|
|
||||||
timestamp = null,
|
|
||||||
).also(::insert)
|
|
||||||
|
|
||||||
upsert(
|
|
||||||
SongAlbumMap(
|
|
||||||
songId = song.id,
|
|
||||||
albumId = albumId,
|
|
||||||
position = null
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaItem.mediaMetadata.extras?.getStringArrayList("artistNames")?.let { artistNames ->
|
mediaItem.mediaMetadata.extras?.getStringArrayList("artistNames")?.let { artistNames ->
|
||||||
mediaItem.mediaMetadata.extras?.getStringArrayList("artistIds")?.let { artistIds ->
|
mediaItem.mediaMetadata.extras?.getStringArrayList("artistIds")?.let { artistIds ->
|
||||||
artistNames.mapIndexed { index, artistName ->
|
if (artistNames.size == artistIds.size) {
|
||||||
Artist(
|
insert(
|
||||||
id = artistIds[index],
|
artistNames.mapIndexed { index, artistName ->
|
||||||
name = artistName,
|
Artist(id = artistIds[index], name = artistName)
|
||||||
thumbnailUrl = null,
|
},
|
||||||
info = null,
|
artistIds.map { artistId ->
|
||||||
timestamp = null
|
SongArtistMap(songId = song.id, artistId = artistId)
|
||||||
).also(::insert)
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}?.forEach { artist ->
|
|
||||||
insert(
|
|
||||||
SongArtistMap(
|
|
||||||
songId = song.id,
|
|
||||||
artistId = artist.id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Update
|
|
||||||
fun update(song: Song)
|
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
fun update(artist: Artist)
|
fun update(artist: Artist)
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
fun update(album: Album)
|
fun update(album: Album)
|
||||||
|
|
||||||
@Update
|
|
||||||
fun update(songAlbumMap: SongAlbumMap)
|
|
||||||
|
|
||||||
@Update
|
|
||||||
fun update(songPlaylistMap: SongPlaylistMap)
|
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
fun update(playlist: Playlist)
|
fun update(playlist: Playlist)
|
||||||
|
|
||||||
|
@ -427,9 +396,6 @@ interface Database {
|
||||||
@Delete
|
@Delete
|
||||||
fun delete(playlist: Playlist)
|
fun delete(playlist: Playlist)
|
||||||
|
|
||||||
@Delete
|
|
||||||
fun delete(playlist: Album)
|
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
fun delete(songPlaylistMap: SongPlaylistMap)
|
fun delete(songPlaylistMap: SongPlaylistMap)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue