Add code to Downloader
This commit is contained in:
parent
8490f7115d
commit
60dbe70ca5
|
@ -457,8 +457,10 @@ class Downloader(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadFile.track.artistId != null) {
|
try {
|
||||||
cacheMetadata(downloadFile.track.artistId!!)
|
downloadFile.track.cacheMetadata()
|
||||||
|
} catch (ignore: Exception) {
|
||||||
|
Timber.w(ignore)
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadAndSaveCoverArt()
|
downloadAndSaveCoverArt()
|
||||||
|
@ -510,13 +512,13 @@ class Downloader(
|
||||||
return String.format(Locale.ROOT, "DownloadTask (%s)", downloadFile.track)
|
return String.format(Locale.ROOT, "DownloadTask (%s)", downloadFile.track)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cacheMetadata(artistId: String) {
|
private fun Track.cacheMetadata() {
|
||||||
// TODO: Right now it's caching the track artist.
|
if (artistId.isNullOrEmpty()) return
|
||||||
// Once the albums are cached in db, we should retrieve the album,
|
|
||||||
// and then cache the album artist.
|
val onlineDB = activeServerProvider.getActiveMetaDatabase()
|
||||||
if (artistId.isEmpty()) return
|
val offlineDB = activeServerProvider.offlineMetaDatabase
|
||||||
var artist: Artist? =
|
|
||||||
activeServerProvider.getActiveMetaDatabase().artistsDao().get(artistId)
|
var artist: Artist? = onlineDB.artistDao().get(artistId!!)
|
||||||
|
|
||||||
// If we are downloading a new album, and the user has not visited the Artists list
|
// 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.
|
// 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) {
|
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() {
|
private fun downloadAndSaveCoverArt() {
|
||||||
|
|
Loading…
Reference in New Issue