Add code to Downloader
This commit is contained in:
parent
8490f7115d
commit
60dbe70ca5
|
@ -457,8 +457,10 @@ class Downloader(
|
|||
)
|
||||
}
|
||||
|
||||
if (downloadFile.track.artistId != null) {
|
||||
cacheMetadata(downloadFile.track.artistId!!)
|
||||
try {
|
||||
downloadFile.track.cacheMetadata()
|
||||
} catch (ignore: Exception) {
|
||||
Timber.w(ignore)
|
||||
}
|
||||
|
||||
downloadAndSaveCoverArt()
|
||||
|
@ -510,13 +512,13 @@ class Downloader(
|
|||
return String.format(Locale.ROOT, "DownloadTask (%s)", downloadFile.track)
|
||||
}
|
||||
|
||||
private fun cacheMetadata(artistId: String) {
|
||||
// TODO: Right now it's caching the track artist.
|
||||
// Once the albums are cached in db, we should retrieve the album,
|
||||
// and then cache the album artist.
|
||||
if (artistId.isEmpty()) return
|
||||
var artist: Artist? =
|
||||
activeServerProvider.getActiveMetaDatabase().artistsDao().get(artistId)
|
||||
private fun Track.cacheMetadata() {
|
||||
if (artistId.isNullOrEmpty()) return
|
||||
|
||||
val onlineDB = activeServerProvider.getActiveMetaDatabase()
|
||||
val offlineDB = activeServerProvider.offlineMetaDatabase
|
||||
|
||||
var artist: Artist? = onlineDB.artistDao().get(artistId!!)
|
||||
|
||||
// If we are downloading a new album, and the user has not visited the Artists list
|
||||
// recently, then the artist won't be in the database.
|
||||
|
@ -527,10 +529,23 @@ class Downloader(
|
|||
}
|
||||
}
|
||||
|
||||
// If we have found an artist, catch it.
|
||||
// If we have found an artist, cache it.
|
||||
if (artist != null) {
|
||||
activeServerProvider.offlineMetaDatabase.artistsDao().insert(artist)
|
||||
offlineDB.artistDao().insert(artist)
|
||||
}
|
||||
|
||||
// Now cache the album
|
||||
if (albumId?.isNotEmpty() == true) {
|
||||
val albums = musicService.getAlbumsOfArtist(artistId!!, null, false)
|
||||
val album = albums.find { it.id == albumId }
|
||||
|
||||
if (album != null) {
|
||||
offlineDB.albumDao().insert(album)
|
||||
}
|
||||
}
|
||||
|
||||
// Now cache the track data
|
||||
offlineDB.trackDao().insert(this)
|
||||
}
|
||||
|
||||
private fun downloadAndSaveCoverArt() {
|
||||
|
|
Loading…
Reference in New Issue