[ViewModel] Fixed long loading times for most played playlist
This commit is contained in:
parent
a6319167c9
commit
652a79f14e
1 changed files with 9 additions and 6 deletions
|
@ -29,6 +29,7 @@ import code.name.monkey.retromusic.util.DensityUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class LibraryViewModel(
|
class LibraryViewModel(
|
||||||
|
@ -278,14 +279,16 @@ class LibraryViewModel(
|
||||||
}
|
}
|
||||||
emit(songs)
|
emit(songs)
|
||||||
// Cleaning up deleted or moved songs
|
// Cleaning up deleted or moved songs
|
||||||
songs.forEach { song ->
|
withContext(IO) {
|
||||||
if (!File(song.data).exists() || song.id == -1L) {
|
songs.forEach { song ->
|
||||||
repository.deleteSongInPlayCount(song.toPlayCount())
|
if (!File(song.data).exists() || song.id == -1L) {
|
||||||
|
repository.deleteSongInPlayCount(song.toPlayCount())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
emit(repository.playCountSongs().map {
|
||||||
|
it.toSong()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
emit(repository.playCountSongs().map {
|
|
||||||
it.toSong()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun artists(type: Int): LiveData<List<Artist>> = liveData {
|
fun artists(type: Int): LiveData<List<Artist>> = liveData {
|
||||||
|
|
Loading…
Reference in a new issue