diff --git a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt index 6ea080957..b65b3b62a 100644 --- a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt @@ -388,14 +388,17 @@ class CourseOutlineViewModel( } } - fun downloadBlocks(blocksIds: List, fragmentManager: FragmentManager, context: Context) { + fun downloadBlocks( + blocksIds: List, + fragmentManager: FragmentManager, + context: Context + ) { + if (blocksIds.find { isBlockDownloading(it) } != null) { + courseRouter.navigateToDownloadQueue(fm = fragmentManager) + return + } blocksIds.forEach { blockId -> - if (isBlockDownloading(blockId)) { - courseRouter.navigateToDownloadQueue( - fm = fragmentManager, - getDownloadableChildren(blockId) ?: arrayListOf() - ) - } else if (isBlockDownloaded(blockId)) { + if (isBlockDownloaded(blockId)) { removeDownloadModels(blockId) } else { saveDownloadModels( diff --git a/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt b/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt index c187af0ad..7135bb8c6 100644 --- a/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt +++ b/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt @@ -244,8 +244,7 @@ fun OfflineQueueCard( maxLines = 1 ) - val progress = progressValue.toFloat() / progressSize - + val progress = if (progressSize == 0L) 0f else progressValue.toFloat() / progressSize LinearProgressIndicator( modifier = Modifier .fillMaxWidth() diff --git a/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt b/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt index 49f3b6120..a5bf069cd 100644 --- a/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt @@ -214,14 +214,17 @@ class CourseVideoViewModel( return resultBlocks.toList() } - fun downloadBlocks(blocksIds: List, fragmentManager: FragmentManager, context: Context) { + fun downloadBlocks( + blocksIds: List, + fragmentManager: FragmentManager, + context: Context + ) { + if (blocksIds.find { isBlockDownloading(it) } != null) { + courseRouter.navigateToDownloadQueue(fm = fragmentManager) + return + } blocksIds.forEach { blockId -> - if (isBlockDownloading(blockId)) { - courseRouter.navigateToDownloadQueue( - fm = fragmentManager, - getDownloadableChildren(blockId) ?: arrayListOf() - ) - } else if (isBlockDownloaded(blockId)) { + if (isBlockDownloaded(blockId)) { removeDownloadModels(blockId) } else { saveDownloadModels(