Skip to content

Commit 12f3d75

Browse files
fix: handle NoCachedDataException (#460)
1 parent 4df0b02 commit 12f3d75

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

app/src/main/java/org/openedx/app/di/ScreenModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ val screenModule = module {
494494
get(),
495495
get(),
496496
get(),
497+
get()
497498
)
498499
}
499500
viewModel { (courseId: String) ->

course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import org.openedx.core.presentation.CoreAnalytics
2525
import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogItem
2626
import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogManager
2727
import org.openedx.core.system.connection.NetworkConnection
28+
import org.openedx.core.system.notifier.CourseNotifier
29+
import org.openedx.core.system.notifier.CourseStructureGot
2830
import org.openedx.course.domain.interactor.CourseInteractor
2931
import org.openedx.foundation.extension.toFileSize
3032
import 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

Comments
 (0)