mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 09:04:32 +01:00
Optimised Track Progress Updation Logic
This commit is contained in:
parent
9685091c4b
commit
643b5aaa9c
@ -175,21 +175,18 @@ internal class SpotiFlyerListStoreProvider(dependencies: SpotiFlyerList.Dependen
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun List<TrackDetails>.updateTracksStatuses(map: Map<String, DownloadStatus>): List<TrackDetails> {
|
private fun List<TrackDetails>.updateTracksStatuses(map: Map<String, DownloadStatus>): List<TrackDetails> {
|
||||||
val updatedList = ArrayList(this)
|
// create a copy in order not to access real referenced ever-changing collections
|
||||||
LinkedHashMap(map).forEach { newTrack ->
|
val trackList = ArrayList(this)
|
||||||
indexOfFirst { it.title == newTrack.key }.let { position ->
|
val updatedMap = HashMap(map)
|
||||||
if (position != -1) {
|
|
||||||
updatedList.getOrNull(position)?.copy(
|
repeat(trackList.size) { index ->
|
||||||
downloaded = newTrack.value,
|
trackList[index].also { oldTrack ->
|
||||||
progress = (newTrack.value as? DownloadStatus.Downloading)?.progress
|
updatedMap[oldTrack.title]?.also { newStatus ->
|
||||||
?: updatedList[position].progress
|
trackList[index] = oldTrack.copy(downloaded = newStatus)
|
||||||
)?.also { updatedTrack ->
|
|
||||||
updatedList[position] = updatedTrack
|
|
||||||
// logger.d("$position) ${updatedTrack.downloaded} - ${updatedTrack.title}","List Store Track Update")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return updatedList
|
return trackList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,12 @@ class FetchPlatformQueryResult(
|
|||||||
downloadLink = URL
|
downloadLink = URL
|
||||||
audioQuality = quality
|
audioQuality = quality
|
||||||
audioFormat = format
|
audioFormat = format
|
||||||
|
}.onFailure {
|
||||||
|
// Append Error To StackTrace
|
||||||
|
appendPadded(
|
||||||
|
"Fetching From YT Failed:",
|
||||||
|
it.stackTraceToString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user