@@ -56,12 +56,10 @@ import androidx.compose.ui.platform.ViewCompositionStrategy
5656import androidx.compose.ui.res.painterResource
5757import androidx.compose.ui.res.stringResource
5858import androidx.compose.ui.text.style.TextAlign
59- import androidx.compose.ui.tooling.preview.Preview
6059import androidx.compose.ui.unit.dp
6160import androidx.core.os.bundleOf
6261import androidx.core.view.isVisible
6362import androidx.fragment.app.Fragment
64- import androidx.fragment.app.FragmentActivity
6563import androidx.fragment.app.FragmentManager
6664import androidx.lifecycle.lifecycleScope
6765import com.google.android.material.snackbar.Snackbar
@@ -164,10 +162,7 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
164162 }
165163 }
166164 viewModel.errorMessage.observe(viewLifecycleOwner) {
167- snackBar = Snackbar .make(binding.root, it, Snackbar .LENGTH_INDEFINITE )
168- .setAction(org.openedx.core.R .string.core_error_try_again) {
169- viewModel.fetchCourseDetails()
170- }
165+ snackBar = Snackbar .make(binding.root, it, Snackbar .LENGTH_SHORT )
171166 snackBar?.show()
172167 }
173168 viewLifecycleOwner.lifecycleScope.launch {
@@ -180,6 +175,8 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
180175 private fun onRefresh (currentPage : Int ) {
181176 if (viewModel.courseAccessStatus.value == CourseAccessError .NONE ) {
182177 viewModel.onRefresh(CourseContainerTab .entries[currentPage])
178+ } else {
179+ viewModel.fetchCourseDetails()
183180 }
184181 }
185182
@@ -390,7 +387,7 @@ fun CourseDashboard(
390387 isInternetConnectionShown = true
391388 },
392389 onReloadClick = {
393- isInternetConnectionShown = true
390+ isInternetConnectionShown = viewModel.hasInternetConnection
394391 onRefresh(pagerState.currentPage)
395392 }
396393 )
@@ -520,7 +517,7 @@ private fun DashboardPager(
520517
521518@Composable
522519private fun CourseAccessErrorView (
523- viewModel : CourseContainerViewModel ? ,
520+ viewModel : CourseContainerViewModel ,
524521 accessError : CourseAccessError ? ,
525522 fragmentManager : FragmentManager ,
526523) {
@@ -532,7 +529,7 @@ private fun CourseAccessErrorView(
532529 R .string.course_error_expired_not_upgradeable_title,
533530 TimeUtils .getCourseAccessFormattedDate(
534531 LocalContext .current,
535- viewModel? .courseDetails?.courseAccessDetails?.auditAccessExpires ? : Date ()
532+ viewModel.courseDetails?.courseAccessDetails?.auditAccessExpires ? : Date ()
536533 )
537534 )
538535 }
@@ -541,7 +538,7 @@ private fun CourseAccessErrorView(
541538 icon = painterResource(id = R .drawable.course_ic_calendar)
542539 message = stringResource(
543540 R .string.course_error_not_started_title,
544- viewModel? .courseDetails?.courseInfoOverview?.startDisplay ? : " "
541+ viewModel.courseDetails?.courseInfoOverview?.startDisplay ? : " "
545542 )
546543 }
547544
@@ -595,6 +592,7 @@ private fun CourseAccessErrorView(
595592 )
596593 }
597594 SetupCourseAccessErrorButtons (
595+ viewModel = viewModel,
598596 accessError = accessError,
599597 fragmentManager = fragmentManager,
600598 )
@@ -604,20 +602,29 @@ private fun CourseAccessErrorView(
604602
605603@Composable
606604private fun SetupCourseAccessErrorButtons (
605+ viewModel : CourseContainerViewModel ,
607606 accessError : CourseAccessError ? ,
608607 fragmentManager : FragmentManager ,
609608) {
610609 when (accessError) {
611610 CourseAccessError .AUDIT_EXPIRED_NOT_UPGRADABLE ,
612611 CourseAccessError .NOT_YET_STARTED ,
613- CourseAccessError .UNKNOWN ,
614612 -> {
615613 OpenEdXButton (
616614 text = stringResource(R .string.course_label_back),
617615 onClick = { fragmentManager.popBackStack() },
618616 )
619617 }
620618
619+ CourseAccessError .UNKNOWN -> {
620+ if (viewModel.hasInternetConnection) {
621+ OpenEdXButton (
622+ text = stringResource(R .string.course_label_back),
623+ onClick = { fragmentManager.popBackStack() },
624+ )
625+ }
626+ }
627+
621628 else -> {}
622629 }
623630}
@@ -628,17 +635,3 @@ private fun scrollToDates(scope: CoroutineScope, pagerState: PagerState) {
628635 pagerState.animateScrollToPage(CourseContainerTab .entries.indexOf(CourseContainerTab .DATES ))
629636 }
630637}
631-
632- @Preview(uiMode = Configuration .UI_MODE_NIGHT_NO )
633- @Preview(uiMode = Configuration .UI_MODE_NIGHT_YES )
634- @Composable
635- private fun CourseAccessErrorViewPreview () {
636- val context = LocalContext .current
637- OpenEdXTheme {
638- CourseAccessErrorView (
639- viewModel = null ,
640- accessError = CourseAccessError .AUDIT_EXPIRED_NOT_UPGRADABLE ,
641- fragmentManager = (context as ? FragmentActivity )?.supportFragmentManager!!
642- )
643- }
644- }
0 commit comments