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 3b2ed4988..f0516a744 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 @@ -327,6 +327,8 @@ private fun CourseOutlineUI( } } + CourseOutlineUIState.Error -> {} + CourseOutlineUIState.Loading -> {} } } diff --git a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineUIState.kt b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineUIState.kt index 389460442..381cb8401 100644 --- a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineUIState.kt +++ b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineUIState.kt @@ -17,5 +17,6 @@ sealed class CourseOutlineUIState { val useRelativeDates: Boolean, ) : CourseOutlineUIState() + data object Error : CourseOutlineUIState() data object Loading : CourseOutlineUIState() } 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 0acf4f64a..f59f6ec6e 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 @@ -221,6 +221,7 @@ class CourseOutlineViewModel( ) courseNotifier.send(CourseLoading(false)) } catch (e: Exception) { + _uiState.value = CourseOutlineUIState.Error if (e.isInternetError()) { _uiMessage.emit(UIMessage.SnackBarMessage(resourceManager.getString(R.string.core_error_no_connection))) } else { diff --git a/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt b/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt index 053d5a1f4..e5bbffe05 100644 --- a/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt @@ -150,34 +150,40 @@ class CourseVideoViewModel( fun getVideos() { viewModelScope.launch { - var courseStructure = interactor.getCourseStructureForVideos(courseId) - val blocks = courseStructure.blockData - if (blocks.isEmpty()) { + try { + var courseStructure = interactor.getCourseStructureForVideos(courseId) + val blocks = courseStructure.blockData + if (blocks.isEmpty()) { + _uiState.value = CourseVideosUIState.Empty( + message = resourceManager.getString(R.string.course_does_not_include_videos) + ) + } else { + setBlocks(courseStructure.blockData) + courseSubSections.clear() + courseSubSectionUnit.clear() + courseStructure = courseStructure.copy(blockData = sortBlocks(blocks)) + initDownloadModelsStatus() + + val courseSectionsState = + (_uiState.value as? CourseVideosUIState.CourseData)?.courseSectionsState.orEmpty() + + _uiState.value = + CourseVideosUIState.CourseData( + courseStructure = courseStructure, + downloadedState = getDownloadModelsStatus(), + courseSubSections = courseSubSections, + courseSectionsState = courseSectionsState, + subSectionsDownloadsCount = subSectionsDownloadsCount, + downloadModelsSize = getDownloadModelsSize(), + useRelativeDates = preferencesManager.isRelativeDatesEnabled + ) + } + courseNotifier.send(CourseLoading(false)) + } catch (e: Exception) { _uiState.value = CourseVideosUIState.Empty( message = resourceManager.getString(R.string.course_does_not_include_videos) ) - } else { - setBlocks(courseStructure.blockData) - courseSubSections.clear() - courseSubSectionUnit.clear() - courseStructure = courseStructure.copy(blockData = sortBlocks(blocks)) - initDownloadModelsStatus() - - val courseSectionsState = - (_uiState.value as? CourseVideosUIState.CourseData)?.courseSectionsState.orEmpty() - - _uiState.value = - CourseVideosUIState.CourseData( - courseStructure = courseStructure, - downloadedState = getDownloadModelsStatus(), - courseSubSections = courseSubSections, - courseSectionsState = courseSectionsState, - subSectionsDownloadsCount = subSectionsDownloadsCount, - downloadModelsSize = getDownloadModelsSize(), - useRelativeDates = preferencesManager.isRelativeDatesEnabled - ) } - courseNotifier.send(CourseLoading(false)) } } diff --git a/course/src/test/java/org/openedx/course/presentation/outline/CourseOutlineViewModelTest.kt b/course/src/test/java/org/openedx/course/presentation/outline/CourseOutlineViewModelTest.kt index 255cc6379..679dfedc9 100644 --- a/course/src/test/java/org/openedx/course/presentation/outline/CourseOutlineViewModelTest.kt +++ b/course/src/test/java/org/openedx/course/presentation/outline/CourseOutlineViewModelTest.kt @@ -281,7 +281,7 @@ class CourseOutlineViewModelTest { coVerify(exactly = 2) { interactor.getCourseStatus(any()) } assertEquals(noInternet, message.await()?.message) - assert(viewModel.uiState.value is CourseOutlineUIState.Loading) + assert(viewModel.uiState.value is CourseOutlineUIState.Error) } @Test @@ -319,7 +319,7 @@ class CourseOutlineViewModelTest { coVerify(exactly = 2) { interactor.getCourseStatus(any()) } assertEquals(somethingWrong, message.await()?.message) - assert(viewModel.uiState.value is CourseOutlineUIState.Loading) + assert(viewModel.uiState.value is CourseOutlineUIState.Error) } @Test