mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 17:14:32 +01:00
Download Progress State Updates Fixes
This commit is contained in:
parent
440210931b
commit
661dd1ada4
@ -1,6 +1,5 @@
|
||||
package com.shabinder.common.di
|
||||
|
||||
import com.shabinder.common.di.providers.YoutubeMp3
|
||||
import com.shabinder.common.di.utils.ParallelExecutor
|
||||
import com.shabinder.common.models.AllPlatforms
|
||||
import com.shabinder.common.models.DownloadResult
|
||||
@ -68,33 +67,36 @@ suspend fun downloadTrack(
|
||||
fetcher.dir.logger.i { "LINK: $videoID -> $link" }
|
||||
downloadFile(link).collect {
|
||||
fetcher.dir.logger.d { it.toString() }
|
||||
when (it) {
|
||||
/*Construct a `NEW Map` from frozen Map to Modify for Native Platforms*/
|
||||
val map: MutableMap<String, DownloadStatus> = when (it) {
|
||||
is DownloadResult.Error -> {
|
||||
DownloadProgressFlow.emit(
|
||||
DownloadProgressFlow.replayCache.getOrElse(
|
||||
0
|
||||
) { hashMapOf() }.apply { set(trackDetails.title, DownloadStatus.Failed) }
|
||||
)
|
||||
) { hashMapOf() }.toMutableMap().apply {
|
||||
set(trackDetails.title, DownloadStatus.Failed)
|
||||
}
|
||||
}
|
||||
is DownloadResult.Progress -> {
|
||||
DownloadProgressFlow.emit(
|
||||
DownloadProgressFlow.replayCache.getOrElse(
|
||||
0
|
||||
) { hashMapOf() }.apply {
|
||||
set(trackDetails.title, DownloadStatus.Downloading(it.progress))
|
||||
) { hashMapOf() }.toMutableMap().apply {
|
||||
set(trackDetails.title,DownloadStatus.Downloading(it.progress))
|
||||
}
|
||||
)
|
||||
}
|
||||
is DownloadResult.Success -> { // Todo clear map
|
||||
saveFileWithMetaData(it.byteArray, trackDetails, methods.value::writeMp3Tags)
|
||||
DownloadProgressFlow.emit(
|
||||
DownloadProgressFlow.replayCache.getOrElse(
|
||||
0
|
||||
) { hashMapOf() }.apply { set(trackDetails.title, DownloadStatus.Downloaded) }
|
||||
) { hashMapOf() }.toMutableMap().apply {
|
||||
set(trackDetails.title, DownloadStatus.Downloaded)
|
||||
}
|
||||
}
|
||||
else -> { mutableMapOf() }
|
||||
}
|
||||
DownloadProgressFlow.emit(
|
||||
map as HashMap<String, DownloadStatus>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 41c6aca4938d13cc7364b1200bf6987c852dfdc2
|
||||
Subproject commit 777e45a555bcb7a8a0713705cbf159d05a45adb0
|
Loading…
Reference in New Issue
Block a user