Skip to content

Commit

Permalink
fix: crash when internet disconnected right after opening a course
Browse files Browse the repository at this point in the history
  • Loading branch information
dixidroid committed Aug 8, 2024
1 parent d174b9f commit 19755ee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ private fun CourseOutlineUI(
}
}

CourseOutlineUIState.Error -> {
NoContentScreen(noContentScreenType = NoContentScreenType.COURSE_OUTLINE)
}

CourseOutlineUIState.Loading -> {
CircularProgress()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ sealed class CourseOutlineUIState {
val datesBannerInfo: CourseDatesBannerInfo,
) : CourseOutlineUIState()

data object Error : CourseOutlineUIState()
data object Loading : CourseOutlineUIState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class CourseOutlineViewModel(
datesBannerInfo = datesBannerInfo
)
} catch (e: Exception) {
_uiState.value = CourseOutlineUIState.Error
if (e.isInternetError()) {
_uiMessage.emit(UIMessage.SnackBarMessage(resourceManager.getString(R.string.core_error_no_connection)))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,31 @@ 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
} 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, getDownloadModelsStatus(), courseSubSections,
courseSectionsState, subSectionsDownloadsCount, getDownloadModelsSize()
)
}
courseNotifier.send(CourseLoading(false))
} catch (e: Exception) {
_uiState.value = CourseVideosUIState.Empty
} 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, getDownloadModelsStatus(), courseSubSections,
courseSectionsState, subSectionsDownloadsCount, getDownloadModelsSize()
)
}
courseNotifier.send(CourseLoading(false))
}
}

Expand Down

0 comments on commit 19755ee

Please sign in to comment.