Limit GetSongs if length is too short

This commit is contained in:
Maxence G (Hello-Fluffy) 2021-08-20 21:39:33 +02:00 committed by tzugen
parent a23e5ff794
commit 7eb3d01ae8
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930

View File

@ -42,6 +42,7 @@ import org.moire.ultrasonic.util.Constants
import org.moire.ultrasonic.util.FileUtil
import org.moire.ultrasonic.util.Util
import timber.log.Timber
import java.lang.Math.min
// TODO: There are quite a number of deeply nested and complicated functions in this class..
// Simplify them :)
@ -257,7 +258,8 @@ class OfflineMusicService : MusicService, KoinComponent {
return result
}
children.shuffle()
for (i in 0 until size) {
val finalSize: Int = min(children.size, size)
for (i in 0 until finalSize) {
val file = children[i % children.size]
result.addChild(createEntry(file, getName(file)))
}