Optimised Track Progress Updation Logic

This commit is contained in:
Shabinder Singh 2021-10-13 01:55:37 +05:30
parent 9685091c4b
commit 643b5aaa9c
2 changed files with 16 additions and 13 deletions

View File

@ -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
} }
} }

View File

@ -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()
)
} }
} }
} }