diff --git a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineScreen.kt b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineScreen.kt index 1a29819f2..1f31b32de 100644 --- a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineScreen.kt +++ b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineScreen.kt @@ -65,7 +65,6 @@ import org.openedx.core.ui.theme.OpenEdXTheme import org.openedx.core.ui.theme.appColors import org.openedx.core.ui.theme.appTypography import org.openedx.core.ui.windowSizeValue -import org.openedx.core.utils.FileUtil import org.openedx.course.R import org.openedx.course.presentation.ui.CourseDatesBanner import org.openedx.course.presentation.ui.CourseDatesBannerTablet @@ -138,21 +137,11 @@ fun CourseOutlineScreen( ) }, onDownloadClick = { blocksIds -> - blocksIds.forEach { blockId -> - if (viewModel.isBlockDownloading(blockId)) { - viewModel.courseRouter.navigateToDownloadQueue( - fm = fragmentManager, - viewModel.getDownloadableChildren(blockId) - ?: arrayListOf() - ) - } else if (viewModel.isBlockDownloaded(blockId)) { - viewModel.removeDownloadModels(blockId) - } else { - viewModel.saveDownloadModels( - FileUtil(context).getExternalAppDir().path, blockId - ) - } - } + viewModel.downloadBlocks( + blocksIds = blocksIds, + fragmentManager = fragmentManager, + context = context + ) }, onResetDatesClick = { viewModel.resetCourseDatesBanner( 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 602c7d2fa..6ea080957 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 @@ -1,5 +1,6 @@ package org.openedx.course.presentation.outline +import android.content.Context import androidx.fragment.app.FragmentManager import androidx.lifecycle.viewModelScope import kotlinx.coroutines.flow.MutableSharedFlow @@ -36,6 +37,7 @@ import org.openedx.core.system.notifier.CourseLoading import org.openedx.core.system.notifier.CourseNotifier import org.openedx.core.system.notifier.CourseOpenBlock import org.openedx.core.system.notifier.CourseStructureUpdated +import org.openedx.core.utils.FileUtil import org.openedx.course.domain.interactor.CourseInteractor import org.openedx.course.presentation.CourseAnalytics import org.openedx.course.presentation.CourseAnalyticsEvent @@ -385,4 +387,21 @@ class CourseOutlineViewModel( ) } } + + fun downloadBlocks(blocksIds: List, fragmentManager: FragmentManager, context: Context) { + blocksIds.forEach { blockId -> + if (isBlockDownloading(blockId)) { + courseRouter.navigateToDownloadQueue( + fm = fragmentManager, + getDownloadableChildren(blockId) ?: arrayListOf() + ) + } else if (isBlockDownloaded(blockId)) { + removeDownloadModels(blockId) + } else { + saveDownloadModels( + FileUtil(context).getExternalAppDir().path, blockId + ) + } + } + } } 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 27da57afb..7d8729fac 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 @@ -595,14 +595,15 @@ fun CourseSection( val arrowRotation by animateFloatAsState( targetValue = if (courseSectionsState == true) -90f else 90f, label = "" ) - val sectionIds = courseSubSections?.map { it.id }.orEmpty() - val filteredStatuses = downloadedStateMap.filterKeys { it in sectionIds }.values + val subSectionIds = courseSubSections?.map { it.id }.orEmpty() + val filteredStatuses = downloadedStateMap.filterKeys { it in subSectionIds }.values val downloadedState = when { filteredStatuses.isEmpty() -> null filteredStatuses.all { it.isDownloaded } -> DownloadedState.DOWNLOADED filteredStatuses.any { it.isWaitingOrDownloading } -> DownloadedState.DOWNLOADING else -> DownloadedState.NOT_DOWNLOADED } + val downloadBlockIds = downloadedStateMap.keys.filter { it in block.descendants } Column(modifier = modifier .clip(MaterialTheme.appShapes.cardShape) @@ -619,7 +620,7 @@ fun CourseSection( arrowDegrees = arrowRotation, downloadedState = downloadedState, onDownloadClick = { - onDownloadClick(downloadedStateMap.keys.toList()) + onDownloadClick(downloadBlockIds) } ) courseSubSections?.forEach { subSectionBlock -> diff --git a/course/src/main/java/org/openedx/course/presentation/ui/CourseVideosUI.kt b/course/src/main/java/org/openedx/course/presentation/ui/CourseVideosUI.kt index 7beb0f91d..1a406181d 100644 --- a/course/src/main/java/org/openedx/course/presentation/ui/CourseVideosUI.kt +++ b/course/src/main/java/org/openedx/course/presentation/ui/CourseVideosUI.kt @@ -99,14 +99,6 @@ fun CourseVideosScreen( uiMessage = uiMessage, courseTitle = viewModel.courseTitle, videoSettings = videoSettings, - onItemClick = { block -> - viewModel.courseRouter.navigateToCourseSubsections( - fm = fragmentManager, - courseId = viewModel.courseId, - subSectionId = block.id, - mode = CourseViewMode.VIDEOS - ) - }, onExpandClick = { block -> viewModel.switchCourseSections(block.id) }, @@ -166,7 +158,6 @@ private fun CourseVideosUI( uiMessage: UIMessage?, courseTitle: String, videoSettings: VideoSettings, - onItemClick: (Block) -> Unit, onExpandClick: (Block) -> Unit, onSubSectionClick: (Block) -> Unit, onDownloadClick: (blocksIds: List) -> Unit, @@ -636,7 +627,6 @@ private fun CourseVideosScreenPreview() { ) ), courseTitle = "", - onItemClick = { }, onExpandClick = { }, onSubSectionClick = { }, videoSettings = VideoSettings.default, @@ -660,7 +650,6 @@ private fun CourseVideosScreenEmptyPreview() { "This course does not include any videos." ), courseTitle = "", - onItemClick = { }, onExpandClick = { }, onSubSectionClick = { }, videoSettings = VideoSettings.default, @@ -695,7 +684,6 @@ private fun CourseVideosScreenTabletPreview() { ) ), courseTitle = "", - onItemClick = { }, onExpandClick = { }, onSubSectionClick = { }, videoSettings = VideoSettings.default,