Download Progress State Updates Fixes

This commit is contained in:
shabinder 2021-05-04 17:10:31 +05:30
parent 440210931b
commit 661dd1ada4
2 changed files with 22 additions and 20 deletions

View File

@ -1,6 +1,5 @@
package com.shabinder.common.di package com.shabinder.common.di
import com.shabinder.common.di.providers.YoutubeMp3
import com.shabinder.common.di.utils.ParallelExecutor import com.shabinder.common.di.utils.ParallelExecutor
import com.shabinder.common.models.AllPlatforms import com.shabinder.common.models.AllPlatforms
import com.shabinder.common.models.DownloadResult import com.shabinder.common.models.DownloadResult
@ -68,32 +67,35 @@ suspend fun downloadTrack(
fetcher.dir.logger.i { "LINK: $videoID -> $link" } fetcher.dir.logger.i { "LINK: $videoID -> $link" }
downloadFile(link).collect { downloadFile(link).collect {
fetcher.dir.logger.d { it.toString() } 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 -> { is DownloadResult.Error -> {
DownloadProgressFlow.emit( DownloadProgressFlow.replayCache.getOrElse(
DownloadProgressFlow.replayCache.getOrElse( 0
0 ) { hashMapOf() }.toMutableMap().apply {
) { hashMapOf() }.apply { set(trackDetails.title, DownloadStatus.Failed) } set(trackDetails.title, DownloadStatus.Failed)
) }
} }
is DownloadResult.Progress -> { is DownloadResult.Progress -> {
DownloadProgressFlow.emit( DownloadProgressFlow.replayCache.getOrElse(
DownloadProgressFlow.replayCache.getOrElse( 0
0 ) { hashMapOf() }.toMutableMap().apply {
) { hashMapOf() }.apply { set(trackDetails.title,DownloadStatus.Downloading(it.progress))
set(trackDetails.title, DownloadStatus.Downloading(it.progress)) }
}
)
} }
is DownloadResult.Success -> { // Todo clear map is DownloadResult.Success -> { // Todo clear map
saveFileWithMetaData(it.byteArray, trackDetails, methods.value::writeMp3Tags) saveFileWithMetaData(it.byteArray, trackDetails, methods.value::writeMp3Tags)
DownloadProgressFlow.emit( DownloadProgressFlow.replayCache.getOrElse(
DownloadProgressFlow.replayCache.getOrElse( 0
0 ) { hashMapOf() }.toMutableMap().apply {
) { hashMapOf() }.apply { set(trackDetails.title, DownloadStatus.Downloaded) } set(trackDetails.title, DownloadStatus.Downloaded)
) }
} }
else -> { mutableMapOf() }
} }
DownloadProgressFlow.emit(
map as HashMap<String, DownloadStatus>
)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()

@ -1 +1 @@
Subproject commit 41c6aca4938d13cc7364b1200bf6987c852dfdc2 Subproject commit 777e45a555bcb7a8a0713705cbf159d05a45adb0