Skip to content

Commit 2ce9ceb

Browse files
feat: added empty states
1 parent 87da809 commit 2ce9ceb

File tree

8 files changed

+214
-159
lines changed

8 files changed

+214
-159
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import androidx.compose.foundation.layout.widthIn
2121
import androidx.compose.foundation.lazy.LazyColumn
2222
import androidx.compose.foundation.lazy.LazyRow
2323
import androidx.compose.foundation.lazy.items
24+
import androidx.compose.foundation.rememberScrollState
25+
import androidx.compose.foundation.verticalScroll
2426
import androidx.compose.material.Card
2527
import androidx.compose.material.CircularProgressIndicator
2628
import androidx.compose.material.Divider
@@ -132,6 +134,7 @@ private fun CourseContentAssignmentScreen(
132134

133135
is CourseAssignmentUIState.Empty -> {
134136
CourseContentAssignmentEmptyState(
137+
modifier = Modifier.verticalScroll(rememberScrollState()),
135138
onReturnToCourseClick = onNavigateToHome
136139
)
137140
}

course/src/main/java/org/openedx/course/presentation/contenttab/ContentTabEmptyState.kt

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
88
import androidx.compose.foundation.layout.height
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.layout.size
11-
import androidx.compose.foundation.rememberScrollState
12-
import androidx.compose.foundation.verticalScroll
1311
import androidx.compose.material.Icon
1412
import androidx.compose.material.MaterialTheme
1513
import androidx.compose.material.Text
@@ -34,15 +32,16 @@ import org.openedx.course.R
3432

3533
@Composable
3634
fun ContentTabEmptyState(
35+
modifier: Modifier = Modifier,
3736
message: String,
38-
onReturnToCourseClick: () -> Unit
37+
onReturnToCourseClick: () -> Unit,
38+
showReturnButton: Boolean = true
3939
) {
4040
val configuration = LocalConfiguration.current
4141
Column(
42-
modifier = Modifier
42+
modifier = modifier
4343
.fillMaxWidth()
44-
.padding(vertical = 24.dp)
45-
.verticalScroll(rememberScrollState()),
44+
.padding(vertical = 24.dp),
4645
verticalArrangement = Arrangement.Center,
4746
horizontalAlignment = Alignment.CenterHorizontally
4847
) {
@@ -64,59 +63,93 @@ fun ContentTabEmptyState(
6463
fontWeight = FontWeight.Medium,
6564
textAlign = TextAlign.Center
6665
)
67-
Spacer(Modifier.height(16.dp))
68-
OpenEdXButton(
69-
modifier = Modifier
70-
.fillMaxWidth()
71-
.padding(horizontal = 24.dp),
72-
textColor = MaterialTheme.appColors.secondaryButtonText,
73-
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
74-
onClick = onReturnToCourseClick
75-
) {
76-
IconText(
77-
text = stringResource(id = R.string.course_return_to_course_home),
78-
icon = Icons.AutoMirrored.Filled.ArrowBack,
79-
color = MaterialTheme.appColors.secondaryButtonText,
80-
textStyle = MaterialTheme.appTypography.labelLarge
81-
)
66+
if (showReturnButton) {
67+
Spacer(Modifier.height(16.dp))
68+
OpenEdXButton(
69+
modifier = Modifier
70+
.fillMaxWidth()
71+
.padding(horizontal = 24.dp),
72+
textColor = MaterialTheme.appColors.secondaryButtonText,
73+
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
74+
onClick = onReturnToCourseClick
75+
) {
76+
IconText(
77+
text = stringResource(id = R.string.course_return_to_course_home),
78+
icon = Icons.AutoMirrored.Filled.ArrowBack,
79+
color = MaterialTheme.appColors.secondaryButtonText,
80+
textStyle = MaterialTheme.appTypography.labelLarge
81+
)
82+
}
8283
}
8384
}
8485
}
8586

8687
@Composable
8788
fun CourseContentAllEmptyState(
88-
onReturnToCourseClick: () -> Unit
89+
modifier: Modifier = Modifier,
90+
onReturnToCourseClick: () -> Unit,
91+
showReturnButton: Boolean = true
8992
) {
9093
ContentTabEmptyState(
94+
modifier = modifier,
9195
message = stringResource(id = org.openedx.core.R.string.core_no_course_content),
92-
onReturnToCourseClick = onReturnToCourseClick
96+
onReturnToCourseClick = onReturnToCourseClick,
97+
showReturnButton = showReturnButton
9398
)
9499
}
95100

96101
@Composable
97102
fun CourseContentVideoEmptyState(
98-
onReturnToCourseClick: () -> Unit
103+
modifier: Modifier = Modifier,
104+
onReturnToCourseClick: () -> Unit,
105+
showReturnButton: Boolean = true
99106
) {
100107
ContentTabEmptyState(
108+
modifier = modifier,
101109
message = stringResource(id = org.openedx.core.R.string.core_no_videos),
102-
onReturnToCourseClick = onReturnToCourseClick
110+
onReturnToCourseClick = onReturnToCourseClick,
111+
showReturnButton = showReturnButton
103112
)
104113
}
105114

106115
@Composable
107116
fun CourseContentAssignmentEmptyState(
108-
onReturnToCourseClick: () -> Unit
117+
modifier: Modifier = Modifier,
118+
onReturnToCourseClick: () -> Unit,
119+
showReturnButton: Boolean = true
109120
) {
110121
ContentTabEmptyState(
122+
modifier = modifier,
111123
message = stringResource(id = org.openedx.core.R.string.core_no_assignments),
112-
onReturnToCourseClick = onReturnToCourseClick
124+
onReturnToCourseClick = onReturnToCourseClick,
125+
showReturnButton = showReturnButton
126+
)
127+
}
128+
129+
@Composable
130+
fun CourseHomeGradesEmptyState(
131+
modifier: Modifier = Modifier,
132+
) {
133+
ContentTabEmptyState(
134+
modifier = modifier,
135+
message = stringResource(id = R.string.course_progress_no_assignments),
136+
onReturnToCourseClick = {},
137+
showReturnButton = false
113138
)
114139
}
115140

116141
@Preview
117142
@Composable
118143
private fun CourseContentAllEmptyStatePreview() {
119144
OpenEdXTheme {
120-
CourseContentAllEmptyState({})
145+
CourseContentAllEmptyState(onReturnToCourseClick = {})
146+
}
147+
}
148+
149+
@Preview
150+
@Composable
151+
private fun CourseHomeGradesEmptyStatePreview() {
152+
OpenEdXTheme {
153+
CourseHomeGradesEmptyState()
121154
}
122155
}

course/src/main/java/org/openedx/course/presentation/home/AssignmentsHomePagerCardContent.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.openedx.core.ui.theme.appColors
3333
import org.openedx.core.ui.theme.appTypography
3434
import org.openedx.core.utils.TimeUtils
3535
import org.openedx.course.R
36+
import org.openedx.course.presentation.contenttab.CourseContentAssignmentEmptyState
3637
import java.util.Date
3738
import org.openedx.core.R as coreR
3839

@@ -42,6 +43,14 @@ fun AssignmentsHomePagerCardContent(
4243
onAssignmentClick: (Block) -> Unit,
4344
onViewAllAssignmentsClick: () -> Unit
4445
) {
46+
if (uiState.courseAssignments.isEmpty()) {
47+
CourseContentAssignmentEmptyState(
48+
onReturnToCourseClick = {},
49+
showReturnButton = false
50+
)
51+
return
52+
}
53+
4554
val completedAssignments = uiState.courseAssignments.count { it.isCompleted() }
4655
val totalAssignments = uiState.courseAssignments.size
4756
val firstIncompleteAssignment = uiState.courseAssignments.find { !it.isCompleted() }

0 commit comments

Comments
 (0)