diff --git a/app/src/main/java/org/openedx/app/di/ScreenModule.kt b/app/src/main/java/org/openedx/app/di/ScreenModule.kt index 7f016ace9..25cf3fed4 100644 --- a/app/src/main/java/org/openedx/app/di/ScreenModule.kt +++ b/app/src/main/java/org/openedx/app/di/ScreenModule.kt @@ -494,6 +494,7 @@ val screenModule = module { get(), get(), get(), + get() ) } viewModel { (courseId: String) -> diff --git a/course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt b/course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt index 497ba799d..620b79012 100644 --- a/course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt @@ -25,6 +25,8 @@ import org.openedx.core.presentation.CoreAnalytics import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogItem import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogManager import org.openedx.core.system.connection.NetworkConnection +import org.openedx.core.system.notifier.CourseNotifier +import org.openedx.core.system.notifier.CourseStructureGot import org.openedx.course.domain.interactor.CourseInteractor import org.openedx.foundation.extension.toFileSize import org.openedx.foundation.utils.FileUtil @@ -37,6 +39,7 @@ class CourseOfflineViewModel( private val downloadDialogManager: DownloadDialogManager, private val fileUtil: FileUtil, private val networkConnection: NetworkConnection, + private val courseNotifier: CourseNotifier, coreAnalytics: CoreAnalytics, downloadDao: DownloadDao, workerController: DownloadWorkerController, @@ -71,11 +74,7 @@ class CourseOfflineViewModel( _uiState.update { it.copy(isDownloading = isDownloading) } } } - - viewModelScope.launch { - async { initDownloadFragment() }.await() - getOfflineData() - } + collectCourseNotifier() } fun downloadAllBlocks(fragmentManager: FragmentManager) { @@ -224,4 +223,17 @@ class CourseOfflineViewModel( } } } + + private fun collectCourseNotifier() { + viewModelScope.launch { + courseNotifier.notifier.collect { event -> + when (event) { + is CourseStructureGot -> { + async { initDownloadFragment() }.await() + getOfflineData() + } + } + } + } + } }