@@ -25,6 +25,8 @@ import org.openedx.core.presentation.CoreAnalytics
2525import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogItem
2626import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogManager
2727import org.openedx.core.system.connection.NetworkConnection
28+ import org.openedx.core.system.notifier.CourseNotifier
29+ import org.openedx.core.system.notifier.CourseStructureGot
2830import org.openedx.course.domain.interactor.CourseInteractor
2931import org.openedx.foundation.extension.toFileSize
3032import org.openedx.foundation.utils.FileUtil
@@ -37,6 +39,7 @@ class CourseOfflineViewModel(
3739 private val downloadDialogManager : DownloadDialogManager ,
3840 private val fileUtil : FileUtil ,
3941 private val networkConnection : NetworkConnection ,
42+ private val courseNotifier : CourseNotifier ,
4043 coreAnalytics : CoreAnalytics ,
4144 downloadDao : DownloadDao ,
4245 workerController : DownloadWorkerController ,
@@ -71,11 +74,7 @@ class CourseOfflineViewModel(
7174 _uiState .update { it.copy(isDownloading = isDownloading) }
7275 }
7376 }
74-
75- viewModelScope.launch {
76- async { initDownloadFragment() }.await()
77- getOfflineData()
78- }
77+ collectCourseNotifier()
7978 }
8079
8180 fun downloadAllBlocks (fragmentManager : FragmentManager ) {
@@ -224,4 +223,17 @@ class CourseOfflineViewModel(
224223 }
225224 }
226225 }
226+
227+ private fun collectCourseNotifier () {
228+ viewModelScope.launch {
229+ courseNotifier.notifier.collect { event ->
230+ when (event) {
231+ is CourseStructureGot -> {
232+ async { initDownloadFragment() }.await()
233+ getOfflineData()
234+ }
235+ }
236+ }
237+ }
238+ }
227239}
0 commit comments