[ViewModel] Fixed long loading times for most played playlist

This commit is contained in:
Prathamesh More 2021-12-02 16:42:31 +05:30
parent a6319167c9
commit 652a79f14e

View file

@ -29,6 +29,7 @@ import code.name.monkey.retromusic.util.DensityUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
class LibraryViewModel(
@ -278,6 +279,7 @@ class LibraryViewModel(
}
emit(songs)
// Cleaning up deleted or moved songs
withContext(IO) {
songs.forEach { song ->
if (!File(song.data).exists() || song.id == -1L) {
repository.deleteSongInPlayCount(song.toPlayCount())
@ -287,6 +289,7 @@ class LibraryViewModel(
it.toSong()
})
}
}
fun artists(type: Int): LiveData<List<Artist>> = liveData {
when (type) {