Skip to content

Commit

Permalink
fix: Support pull to refresh for empty dashboard (#375)
Browse files Browse the repository at this point in the history
This change adds support for pull to refresh when the course list is empty.
  • Loading branch information
xitij2000 authored Oct 29, 2024
1 parent 1daedbe commit e2ee565
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
Expand All @@ -35,6 +37,7 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.AccessTime
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
Expand Down Expand Up @@ -305,7 +308,7 @@ internal fun DashboardListView(
is DashboardUIState.Empty -> {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
contentAlignment = Alignment.Center,
) {
Column(
Modifier
Expand Down Expand Up @@ -475,13 +478,18 @@ private fun CourseItem(

@Composable
private fun EmptyState() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Column(
Modifier.width(185.dp),
horizontalAlignment = Alignment.CenterHorizontally
Modifier
.fillMaxSize()
.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Icon(
painter = painterResource(id = R.drawable.dashboard_ic_empty),
Expand All @@ -499,6 +507,13 @@ private fun EmptyState() {
textAlign = TextAlign.Center
)
}
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(id = R.string.dashboard_pull_to_refresh),
color = MaterialTheme.appColors.textSecondary,
style = MaterialTheme.appTypography.labelSmall,
textAlign = TextAlign.Center
)
}
}

Expand Down Expand Up @@ -577,6 +592,29 @@ private fun DashboardListViewTabletPreview() {
}
}


@Preview(uiMode = UI_MODE_NIGHT_NO)
@Preview(uiMode = UI_MODE_NIGHT_YES)
@Composable
private fun EmptyStatePreview() {
OpenEdXTheme {
DashboardListView(
windowSize = WindowSize(WindowType.Compact, WindowType.Compact),
apiHostUrl = "http://localhost:8000",
state = DashboardUIState.Empty,
uiMessage = null,
onSwipeRefresh = {},
onItemClick = {},
onReloadClick = {},
hasInternetConnection = true,
refreshing = false,
canLoadMore = false,
paginationCallback = {},
appUpgradeParameters = AppUpdateState.AppUpgradeParameters()
)
}
}

private val mockCourseAssignments = CourseAssignments(null, emptyList())
private val mockCourseEnrolled = EnrolledCourse(
auditAccessExpires = Date(),
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="dashboard_all_courses_empty_description">You are not currently enrolled in any courses, would you like to explore the course catalog?</string>
<string name="dashboard_find_a_course">Find a Course</string>
<string name="dashboard_no_status_courses">No %1$s Courses</string>
<string name="dashboard_pull_to_refresh">Swipe down to refresh</string>

<plurals name="dashboard_past_due_assignment">
<item quantity="one">%1$d Past Due Assignment</item>
Expand Down

0 comments on commit e2ee565

Please sign in to comment.