Skip to content

Commit 02b16f4

Browse files
fix: changes according review
1 parent dc9a9ed commit 02b16f4

File tree

7 files changed

+71
-48
lines changed

7 files changed

+71
-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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
<string name="core_no_course_content">No course content is currently available.</string>
175175
<string name="core_no_videos">No videos available for this course.</string>
176176
<string name="core_no_dates">Course dates are currently not available.</string>
177-
<string name="core_no_assignments">Course assignment are currently not available.</string>
177+
<string name="core_no_assignments">No assignments available for this course.</string>
178178
<string name="core_no_discussion">Unable to load discussions.\n Please try again later.</string>
179179
<string name="core_no_handouts">There are currently no handouts for this course.</string>
180180
<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: 6 additions & 2 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,7 +305,7 @@ 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
}
306310
val isDuePast = assignment.due != null && assignment.due!! > Date()
307311
val cardBorderColor = when {

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
@@ -286,27 +286,46 @@ fun CourseDashboard(
286286
scaffoldState = scaffoldState,
287287
backgroundColor = MaterialTheme.appColors.background,
288288
bottomBar = {
289-
if (CourseContainerTab.entries[pagerState.currentPage] == CourseContainerTab.CONTENT &&
290-
selectedContentTab == CourseContentTab.ASSIGNMENTS
291-
) {
292-
Column(
293-
modifier = Modifier.background(MaterialTheme.appColors.background),
294-
horizontalAlignment = Alignment.CenterHorizontally
289+
Box {
290+
if (CourseContainerTab.entries[pagerState.currentPage] == CourseContainerTab.CONTENT &&
291+
selectedContentTab == CourseContentTab.ASSIGNMENTS
295292
) {
296-
Divider(modifier = Modifier.fillMaxWidth())
297-
TextButton(
298-
onClick = {
299-
scrollToProgress(scope, pagerState)
300-
}
293+
Column(
294+
modifier = Modifier.background(MaterialTheme.appColors.background),
295+
horizontalAlignment = Alignment.CenterHorizontally
301296
) {
302-
IconText(
303-
text = stringResource(R.string.course_review_grading_policy),
304-
painter = painterResource(id = coreR.drawable.core_ic_assignment),
305-
color = MaterialTheme.appColors.primary,
306-
textStyle = MaterialTheme.appTypography.labelLarge
307-
)
297+
Divider(modifier = Modifier.fillMaxWidth())
298+
TextButton(
299+
onClick = {
300+
scrollToProgress(scope, pagerState)
301+
}
302+
) {
303+
IconText(
304+
text = stringResource(R.string.course_review_grading_policy),
305+
painter = painterResource(id = coreR.drawable.core_ic_assignment),
306+
color = MaterialTheme.appColors.primary,
307+
textStyle = MaterialTheme.appTypography.labelLarge
308+
)
309+
}
308310
}
309311
}
312+
var isInternetConnectionShown by rememberSaveable {
313+
mutableStateOf(false)
314+
}
315+
if (!isInternetConnectionShown && !viewModel.hasInternetConnection) {
316+
OfflineModeDialog(
317+
Modifier
318+
.fillMaxWidth()
319+
.align(Alignment.BottomCenter),
320+
onDismissCLick = {
321+
isInternetConnectionShown = true
322+
},
323+
onReloadClick = {
324+
isInternetConnectionShown = viewModel.hasInternetConnection
325+
onRefresh(pagerState.currentPage)
326+
}
327+
)
328+
}
310329
}
311330
}
312331
) { paddingValues ->
@@ -403,24 +422,6 @@ fun CourseDashboard(
403422
Modifier.align(Alignment.TopCenter)
404423
)
405424

406-
var isInternetConnectionShown by rememberSaveable {
407-
mutableStateOf(false)
408-
}
409-
if (!isInternetConnectionShown && !viewModel.hasInternetConnection) {
410-
OfflineModeDialog(
411-
Modifier
412-
.fillMaxWidth()
413-
.align(Alignment.BottomCenter),
414-
onDismissCLick = {
415-
isInternetConnectionShown = true
416-
},
417-
onReloadClick = {
418-
isInternetConnectionShown = viewModel.hasInternetConnection
419-
onRefresh(pagerState.currentPage)
420-
}
421-
)
422-
}
423-
424425
SnackbarHost(
425426
modifier = Modifier.align(Alignment.BottomStart),
426427
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: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.junit.Test
3030
import org.junit.rules.TestRule
3131
import org.openedx.core.BlockType
3232
import org.openedx.core.config.Config
33+
import org.openedx.core.data.model.room.VideoProgressEntity
3334
import org.openedx.core.data.storage.CorePreferences
3435
import org.openedx.core.domain.model.AssignmentProgress
3536
import org.openedx.core.domain.model.Block
@@ -148,6 +149,8 @@ class CourseVideoViewModelTest {
148149
)
149150
)
150151

152+
private val videoProgressMock = VideoProgressEntity("", 0L, 0L)
153+
151154
private val courseStructure = CourseStructure(
152155
root = "",
153156
blockData = blocks,
@@ -252,9 +255,13 @@ class CourseVideoViewModelTest {
252255
fun `getVideos success`() = runTest {
253256
every { config.getCourseUIConfig().isCourseDropdownNavigationEnabled } returns false
254257
coEvery { interactor.getCourseStructureForVideos(any()) } returns courseStructure
255-
every { downloadDao.getAllDataFlow() } returns flow { emit(emptyList()) }
258+
every { downloadDao.getAllDataFlow() } returns flow {
259+
repeat(5) {
260+
delay(10000)
261+
emit(emptyList())
262+
}
263+
}
256264
every { preferencesManager.videoSettings } returns VideoSettings.default
257-
258265
val viewModel = CourseVideoViewModel(
259266
"",
260267
config,
@@ -272,10 +279,14 @@ class CourseVideoViewModelTest {
272279
downloadHelper,
273280
)
274281

275-
viewModel.getVideos()
282+
val mockLifeCycleOwner: LifecycleOwner = mockk()
283+
val lifecycleRegistry = LifecycleRegistry(mockLifeCycleOwner)
284+
lifecycleRegistry.addObserver(viewModel)
285+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
286+
276287
advanceUntilIdle()
277288

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

280291
assert(viewModel.uiState.value is CourseVideoUIState.CourseData)
281292
}

0 commit comments

Comments
 (0)