From 661dd1ada44f1fcecdcd7f0632014d845432e958 Mon Sep 17 00:00:00 2001 From: shabinder Date: Tue, 4 May 2021 17:10:31 +0530 Subject: [PATCH] Download Progress State Updates Fixes --- .../com.shabinder.common.di/IOSActual.kt | 40 ++++++++++--------- spotiflyer-ios | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt b/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt index 4030dc19..41a8475e 100644 --- a/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt +++ b/common/dependency-injection/src/iosMain/kotlin/com.shabinder.common.di/IOSActual.kt @@ -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,32 +67,35 @@ 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 = when (it) { is DownloadResult.Error -> { - DownloadProgressFlow.emit( - DownloadProgressFlow.replayCache.getOrElse( - 0 - ) { hashMapOf() }.apply { set(trackDetails.title, DownloadStatus.Failed) } - ) + DownloadProgressFlow.replayCache.getOrElse( + 0 + ) { 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)) - } - ) + DownloadProgressFlow.replayCache.getOrElse( + 0 + ) { 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) } - ) + DownloadProgressFlow.replayCache.getOrElse( + 0 + ) { hashMapOf() }.toMutableMap().apply { + set(trackDetails.title, DownloadStatus.Downloaded) + } } + else -> { mutableMapOf() } } + DownloadProgressFlow.emit( + map as HashMap + ) } } catch (e: Exception) { e.printStackTrace() diff --git a/spotiflyer-ios b/spotiflyer-ios index 41c6aca4..777e45a5 160000 --- a/spotiflyer-ios +++ b/spotiflyer-ios @@ -1 +1 @@ -Subproject commit 41c6aca4938d13cc7364b1200bf6987c852dfdc2 +Subproject commit 777e45a555bcb7a8a0713705cbf159d05a45adb0