Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -385,4 +387,21 @@ class CourseOutlineViewModel(
)
}
}

fun downloadBlocks(blocksIds: List<String>, 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
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -619,7 +620,7 @@ fun CourseSection(
arrowDegrees = arrowRotation,
downloadedState = downloadedState,
onDownloadClick = {
onDownloadClick(downloadedStateMap.keys.toList())
onDownloadClick(downloadBlockIds)
}
)
courseSubSections?.forEach { subSectionBlock ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down Expand Up @@ -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<String>) -> Unit,
Expand Down Expand Up @@ -636,7 +627,6 @@ private fun CourseVideosScreenPreview() {
)
),
courseTitle = "",
onItemClick = { },
onExpandClick = { },
onSubSectionClick = { },
videoSettings = VideoSettings.default,
Expand All @@ -660,7 +650,6 @@ private fun CourseVideosScreenEmptyPreview() {
"This course does not include any videos."
),
courseTitle = "",
onItemClick = { },
onExpandClick = { },
onSubSectionClick = { },
videoSettings = VideoSettings.default,
Expand Down Expand Up @@ -695,7 +684,6 @@ private fun CourseVideosScreenTabletPreview() {
)
),
courseTitle = "",
onItemClick = { },
onExpandClick = { },
onSubSectionClick = { },
videoSettings = VideoSettings.default,
Expand Down