Skip to content

Commit 1a3826a

Browse files
authored
fix: set dataValue to true for CourseOutline (#404)
1 parent fa38468 commit 1a3826a

File tree

3 files changed

+22
-106
lines changed

3 files changed

+22
-106
lines changed

course/src/main/java/org/openedx/course/presentation/container/CourseContainerFragment.kt

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ import androidx.compose.ui.platform.ViewCompositionStrategy
5656
import androidx.compose.ui.res.painterResource
5757
import androidx.compose.ui.res.stringResource
5858
import androidx.compose.ui.text.style.TextAlign
59-
import androidx.compose.ui.tooling.preview.Preview
6059
import androidx.compose.ui.unit.dp
6160
import androidx.core.os.bundleOf
6261
import androidx.core.view.isVisible
6362
import androidx.fragment.app.Fragment
64-
import androidx.fragment.app.FragmentActivity
6563
import androidx.fragment.app.FragmentManager
6664
import androidx.lifecycle.lifecycleScope
6765
import 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
522519
private 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
606604
private 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-
}

course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class CourseContainerViewModel(
202202
delay(500L)
203203
courseNotifier.send(CourseOpenBlock(resumeBlockId))
204204
}
205+
_dataReady.value = true
205206
}
206207
} ?: run {
207208
_courseAccessStatus.value = CourseAccessError.UNKNOWN
@@ -276,14 +277,9 @@ class CourseContainerViewModel(
276277
viewModelScope.launch {
277278
try {
278279
interactor.getCourseStructure(courseId, isNeedRefresh = true)
279-
} catch (e: Exception) {
280-
if (e.isInternetError()) {
281-
_errorMessage.value =
282-
resourceManager.getString(CoreR.string.core_error_no_connection)
283-
} else {
284-
_errorMessage.value =
285-
resourceManager.getString(CoreR.string.core_error_unknown_error)
286-
}
280+
} catch (ignore: Exception) {
281+
_errorMessage.value =
282+
resourceManager.getString(CoreR.string.core_error_unknown_error)
287283
}
288284
_refreshing.value = false
289285
courseNotifier.send(CourseStructureUpdated(courseId))

course/src/test/java/org/openedx/course/presentation/container/CourseContainerViewModelTest.kt

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import org.openedx.course.presentation.CourseAnalyticsEvent
4747
import org.openedx.course.presentation.CourseRouter
4848
import org.openedx.course.utils.ImageProcessor
4949
import org.openedx.foundation.system.ResourceManager
50-
import java.net.UnknownHostException
5150
import java.util.Date
5251

5352
@OptIn(ExperimentalCoroutinesApi::class)
@@ -216,49 +215,6 @@ class CourseContainerViewModelTest {
216215
Dispatchers.resetMain()
217216
}
218217

219-
@Test
220-
fun `getCourseEnrollmentDetails internet connection exception`() = runTest {
221-
val viewModel = CourseContainerViewModel(
222-
"",
223-
"",
224-
"",
225-
config,
226-
interactor,
227-
resourceManager,
228-
courseNotifier,
229-
networkConnection,
230-
corePreferences,
231-
analytics,
232-
imageProcessor,
233-
calendarSyncScheduler,
234-
courseRouter,
235-
)
236-
every { networkConnection.isOnline() } returns true
237-
coEvery { interactor.getCourseStructure(any(), any()) } returns courseStructure
238-
coEvery { interactor.getEnrollmentDetails(any()) } throws UnknownHostException()
239-
every {
240-
analytics.logScreenEvent(
241-
CourseAnalyticsEvent.DASHBOARD.eventName,
242-
any()
243-
)
244-
} returns Unit
245-
viewModel.fetchCourseDetails()
246-
advanceUntilIdle()
247-
248-
coVerify(exactly = 1) { interactor.getEnrollmentDetails(any()) }
249-
verify(exactly = 1) {
250-
analytics.logScreenEvent(
251-
CourseAnalyticsEvent.DASHBOARD.eventName,
252-
any()
253-
)
254-
}
255-
256-
val message = viewModel.errorMessage.value
257-
assertEquals(noInternet, message)
258-
assert(!viewModel.refreshing.value)
259-
assert(viewModel.courseAccessStatus.value == null)
260-
}
261-
262218
@Test
263219
fun `getCourseEnrollmentDetails unknown exception`() = runTest {
264220
val viewModel = CourseContainerViewModel(
@@ -380,35 +336,6 @@ class CourseContainerViewModelTest {
380336
assert(viewModel.courseAccessStatus.value != null)
381337
}
382338

383-
@Test
384-
fun `updateData no internet connection exception`() = runTest {
385-
val viewModel = CourseContainerViewModel(
386-
"",
387-
"",
388-
"",
389-
config,
390-
interactor,
391-
resourceManager,
392-
courseNotifier,
393-
networkConnection,
394-
corePreferences,
395-
analytics,
396-
imageProcessor,
397-
calendarSyncScheduler,
398-
courseRouter
399-
)
400-
coEvery { interactor.getCourseStructure(any(), true) } throws UnknownHostException()
401-
coEvery { courseNotifier.send(CourseStructureUpdated("")) } returns Unit
402-
viewModel.updateData()
403-
advanceUntilIdle()
404-
405-
coVerify(exactly = 1) { interactor.getCourseStructure(any(), true) }
406-
407-
val message = viewModel.errorMessage.value
408-
assertEquals(noInternet, message)
409-
assert(!viewModel.refreshing.value)
410-
}
411-
412339
@Test
413340
fun `updateData unknown exception`() = runTest {
414341
val viewModel = CourseContainerViewModel(

0 commit comments

Comments
 (0)