mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-26 05:32:15 +03:00
Fix a bug where newly added Artists were not cached correctly
This commit is contained in:
parent
fda746905d
commit
35a0dd761d
@ -18,6 +18,7 @@ import java.io.RandomAccessFile
|
|||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||||
|
import org.moire.ultrasonic.domain.Artist
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
||||||
import org.moire.ultrasonic.subsonic.ImageLoaderProvider
|
import org.moire.ultrasonic.subsonic.ImageLoaderProvider
|
||||||
@ -200,6 +201,8 @@ class DownloadFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inner class DownloadTask : CancellableTask() {
|
private inner class DownloadTask : CancellableTask() {
|
||||||
|
val musicService = getMusicService()
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
var inputStream: InputStream? = null
|
var inputStream: InputStream? = null
|
||||||
var outputStream: FileOutputStream? = null
|
var outputStream: FileOutputStream? = null
|
||||||
@ -222,8 +225,6 @@ class DownloadFile(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val musicService = getMusicService()
|
|
||||||
|
|
||||||
// Some devices seem to throw error on partial file which doesn't exist
|
// Some devices seem to throw error on partial file which doesn't exist
|
||||||
val needsDownloading: Boolean
|
val needsDownloading: Boolean
|
||||||
val duration = song.duration
|
val duration = song.duration
|
||||||
@ -314,9 +315,23 @@ class DownloadFile(
|
|||||||
// Once the albums are cached in db, we should retrieve the album,
|
// Once the albums are cached in db, we should retrieve the album,
|
||||||
// and then cache the album artist.
|
// and then cache the album artist.
|
||||||
if (artistId.isEmpty()) return
|
if (artistId.isEmpty()) return
|
||||||
val artist = activeServerProvider.getActiveMetaDatabase().artistsDao().get(artistId)
|
var artist: Artist? =
|
||||||
|
activeServerProvider.getActiveMetaDatabase().artistsDao().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.
|
||||||
|
if (artist == null) {
|
||||||
|
val artists: List<Artist> = musicService.getArtists(true)
|
||||||
|
artist = artists.find {
|
||||||
|
it.id == artistId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have found an artist, catch it.
|
||||||
|
if (artist != null) {
|
||||||
activeServerProvider.offlineMetaDatabase.artistsDao().insert(artist)
|
activeServerProvider.offlineMetaDatabase.artistsDao().insert(artist)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun downloadAndSaveCoverArt() {
|
private fun downloadAndSaveCoverArt() {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user