Skip to content

Commit bf564c8

Browse files
fix: changes according review
1 parent 7cc4182 commit bf564c8

File tree

7 files changed

+69
-48
lines changed

7 files changed

+69
-48
lines changed

core/src/main/java/org/openedx/core/ui/ComposeCommon.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
1919
import androidx.compose.foundation.layout.height
2020
import androidx.compose.foundation.layout.padding
2121
import androidx.compose.foundation.layout.size
22+
import androidx.compose.foundation.layout.sizeIn
2223
import androidx.compose.foundation.layout.width
2324
import androidx.compose.foundation.layout.widthIn
2425
import androidx.compose.foundation.lazy.LazyColumn
@@ -1142,7 +1143,11 @@ fun NoContentScreen(message: String, icon: Painter) {
11421143
horizontalAlignment = Alignment.CenterHorizontally
11431144
) {
11441145
Icon(
1145-
modifier = Modifier.size(80.dp),
1146+
modifier = Modifier
1147+
.sizeIn(
1148+
maxWidth = 80.dp,
1149+
maxHeight = 80.dp
1150+
),
11461151
painter = icon,
11471152
contentDescription = null,
11481153
tint = MaterialTheme.appColors.progressBarBackgroundColor,

core/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
<string name="core_no_dates">Course dates are currently not available.</string>
162162
<string name="core_no_progress">This course does not contain exams or graded assignments.</string>
163163
<string name="core_no_assignments">Course assignment are currently not available.</string>
164+
<string name="core_no_assignments">No assignments available for this course.</string>
164165
<string name="core_no_discussion">Unable to load discussions.\n Please try again later.</string>
165166
<string name="core_no_handouts">There are currently no handouts for this course.</string>
166167
<string name="core_no_announcements">There are currently no announcements for this course.</string>

course/src/main/java/org/openedx/course/presentation/assignments/CourseAssignmentViewModel.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,18 @@ class CourseAssignmentViewModel(
3939

4040
private fun collectData() {
4141
viewModelScope.launch {
42-
val courseProgressFlow = interactor.getCourseProgress(courseId, true)
42+
val courseProgressFlow = interactor.getCourseProgress(courseId, false)
4343
val courseStructureFlow = interactor.getCourseStructureFlow(courseId)
44-
.catch {
45-
_uiState.value = CourseAssignmentUIState.Empty
46-
}
4744

4845
combine(
4946
courseProgressFlow,
5047
courseStructureFlow
5148
) { courseProgress, courseStructure ->
5249
courseProgress to courseStructure
5350
}.catch {
54-
_uiState.value = CourseAssignmentUIState.Empty
51+
if (_uiState.value !is CourseAssignmentUIState.CourseData) {
52+
_uiState.value = CourseAssignmentUIState.Empty
53+
}
5554
}.collect { (courseProgress, courseStructure) ->
5655
if (courseStructure != null) {
5756
updateAssignments(courseStructure, courseProgress)

course/src/main/java/org/openedx/course/presentation/assignments/CourseContentAssignmentScreen.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private const val ASSIGNMENT_BUTTON_CARD_BACKGROUND_ALPHA = 0.5f
8080
private const val COMPLETED_ASSIGNMENTS_COUNT = 1
8181
private const val COMPLETED_ASSIGNMENTS_COUNT_TABLET = 2
8282
private const val TOTAL_ASSIGNMENTS_COUNT = 3
83+
private const val SHORT_LABEL_PREFIX_SIZE = 3
8384

8485
@Composable
8586
fun CourseContentAssignmentScreen(
@@ -119,7 +120,10 @@ private fun CourseContentAssignmentScreen(
119120

120121
when (uiState) {
121122
is CourseAssignmentUIState.Loading -> {
122-
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
123+
Box(
124+
modifier = Modifier.fillMaxSize(),
125+
contentAlignment = Alignment.Center
126+
) {
123127
CircularProgressIndicator()
124128
}
125129
}
@@ -301,9 +305,9 @@ private fun AssignmentGroupSection(
301305
@Composable
302306
private fun AssignmentButton(assignment: Block, isSelected: Boolean, onClick: () -> Unit) {
303307
val label = assignment.assignmentProgress?.label?.split(" ").let {
304-
it?.first()?.take(3) + it?.last()
308+
it?.first()?.take(SHORT_LABEL_PREFIX_SIZE) + it?.last()
305309
}
306-
val isDuePast = assignment.due != null && assignment.due!! > Date()
310+
val isDuePast = assignment.due != null && assignment.due!! < Date()
307311
val cardBorderColor = when {
308312
isSelected -> MaterialTheme.appColors.primary
309313
assignment.isCompleted() -> MaterialTheme.appColors.successGreen

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -289,27 +289,46 @@ fun CourseDashboard(
289289
scaffoldState = scaffoldState,
290290
backgroundColor = MaterialTheme.appColors.background,
291291
bottomBar = {
292-
if (CourseContainerTab.entries[pagerState.currentPage] == CourseContainerTab.CONTENT &&
293-
selectedContentTab == CourseContentTab.ASSIGNMENTS
294-
) {
295-
Column(
296-
modifier = Modifier.background(MaterialTheme.appColors.background),
297-
horizontalAlignment = Alignment.CenterHorizontally
292+
Box {
293+
if (CourseContainerTab.entries[pagerState.currentPage] == CourseContainerTab.CONTENT &&
294+
selectedContentTab == CourseContentTab.ASSIGNMENTS
298295
) {
299-
Divider(modifier = Modifier.fillMaxWidth())
300-
TextButton(
301-
onClick = {
302-
scrollToProgress(scope, pagerState)
303-
}
296+
Column(
297+
modifier = Modifier.background(MaterialTheme.appColors.background),
298+
horizontalAlignment = Alignment.CenterHorizontally
304299
) {
305-
IconText(
306-
text = stringResource(R.string.course_review_grading_policy),
307-
painter = painterResource(id = coreR.drawable.core_ic_assignment),
308-
color = MaterialTheme.appColors.primary,
309-
textStyle = MaterialTheme.appTypography.labelLarge
310-
)
300+
Divider(modifier = Modifier.fillMaxWidth())
301+
TextButton(
302+
onClick = {
303+
scrollToProgress(scope, pagerState)
304+
}
305+
) {
306+
IconText(
307+
text = stringResource(R.string.course_review_grading_policy),
308+
painter = painterResource(id = coreR.drawable.core_ic_assignment),
309+
color = MaterialTheme.appColors.primary,
310+
textStyle = MaterialTheme.appTypography.labelLarge
311+
)
312+
}
311313
}
312314
}
315+
var isInternetConnectionShown by rememberSaveable {
316+
mutableStateOf(false)
317+
}
318+
if (!isInternetConnectionShown && !viewModel.hasInternetConnection) {
319+
OfflineModeDialog(
320+
Modifier
321+
.fillMaxWidth()
322+
.align(Alignment.BottomCenter),
323+
onDismissCLick = {
324+
isInternetConnectionShown = true
325+
},
326+
onReloadClick = {
327+
isInternetConnectionShown = viewModel.hasInternetConnection
328+
onRefresh(pagerState.currentPage)
329+
}
330+
)
331+
}
313332
}
314333
}
315334
) { paddingValues ->
@@ -406,24 +425,6 @@ fun CourseDashboard(
406425
Modifier.align(Alignment.TopCenter)
407426
)
408427

409-
var isInternetConnectionShown by rememberSaveable {
410-
mutableStateOf(false)
411-
}
412-
if (!isInternetConnectionShown && !viewModel.hasInternetConnection) {
413-
OfflineModeDialog(
414-
Modifier
415-
.fillMaxWidth()
416-
.align(Alignment.BottomCenter),
417-
onDismissCLick = {
418-
isInternetConnectionShown = true
419-
},
420-
onReloadClick = {
421-
isInternetConnectionShown = viewModel.hasInternetConnection
422-
onRefresh(pagerState.currentPage)
423-
}
424-
)
425-
}
426-
427428
SnackbarHost(
428429
modifier = Modifier.align(Alignment.BottomStart),
429430
hostState = snackState

course/src/test/java/org/openedx/course/presentation/unit/video/VideoUnitViewModelTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class VideoUnitViewModelTest {
5757
@Test
5858
fun `markBlockCompleted exception`() = runTest {
5959
val viewModel = VideoUnitViewModel(
60+
"",
6061
"",
6162
courseRepository,
6263
notifier,
@@ -96,6 +97,7 @@ class VideoUnitViewModelTest {
9697
@Test
9798
fun `markBlockCompleted success`() = runTest {
9899
val viewModel = VideoUnitViewModel(
100+
"",
99101
"",
100102
courseRepository,
101103
notifier,
@@ -135,6 +137,7 @@ class VideoUnitViewModelTest {
135137
@Test
136138
fun `CourseVideoPositionChanged notifier test`() = runTest {
137139
val viewModel = VideoUnitViewModel(
140+
"",
138141
"",
139142
courseRepository,
140143
notifier,

course/src/test/java/org/openedx/course/presentation/videos/CourseVideoViewModelTest.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,13 @@ class CourseVideoViewModelTest {
252252
fun `getVideos success`() = runTest {
253253
every { config.getCourseUIConfig().isCourseDropdownNavigationEnabled } returns false
254254
coEvery { interactor.getCourseStructureForVideos(any()) } returns courseStructure
255-
every { downloadDao.getAllDataFlow() } returns flow { emit(emptyList()) }
255+
every { downloadDao.getAllDataFlow() } returns flow {
256+
repeat(5) {
257+
delay(10000)
258+
emit(emptyList())
259+
}
260+
}
256261
every { preferencesManager.videoSettings } returns VideoSettings.default
257-
258262
val viewModel = CourseVideoViewModel(
259263
"",
260264
config,
@@ -272,10 +276,14 @@ class CourseVideoViewModelTest {
272276
downloadHelper,
273277
)
274278

275-
viewModel.getVideos()
279+
val mockLifeCycleOwner: LifecycleOwner = mockk()
280+
val lifecycleRegistry = LifecycleRegistry(mockLifeCycleOwner)
281+
lifecycleRegistry.addObserver(viewModel)
282+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
283+
276284
advanceUntilIdle()
277285

278-
coVerify(exactly = 2) { interactor.getCourseStructureForVideos(any()) }
286+
coVerify(exactly = 1) { interactor.getCourseStructureForVideos(any()) }
279287

280288
assert(viewModel.uiState.value is CourseVideoUIState.CourseData)
281289
}

0 commit comments

Comments
 (0)