From ba305a09c6e09a9806bea389155b937b756d6c69 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 8 Jul 2024 12:27:54 +0200 Subject: [PATCH] fix: show only one screen with all downloadable content (#352) --- .../outline/CourseOutlineViewModel.kt | 17 ++++++++++------- .../openedx/course/presentation/ui/CourseUI.kt | 3 +-- .../presentation/videos/CourseVideoViewModel.kt | 17 ++++++++++------- 3 files changed, 21 insertions(+), 16 deletions(-) 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(