@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.heightIn
1818import androidx.compose.foundation.layout.padding
1919import androidx.compose.foundation.layout.size
2020import androidx.compose.foundation.layout.width
21+ import androidx.compose.foundation.layout.widthIn
2122import androidx.compose.foundation.lazy.grid.GridCells
2223import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid
2324import androidx.compose.foundation.lazy.grid.items
@@ -46,6 +47,7 @@ import androidx.compose.runtime.LaunchedEffect
4647import androidx.compose.runtime.collectAsState
4748import androidx.compose.runtime.getValue
4849import androidx.compose.runtime.mutableStateOf
50+ import androidx.compose.runtime.remember
4951import androidx.compose.runtime.saveable.rememberSaveable
5052import androidx.compose.runtime.setValue
5153import androidx.compose.ui.Alignment
@@ -103,6 +105,7 @@ import org.openedx.dashboard.R
103105import org.openedx.foundation.extension.toImageLink
104106import org.openedx.foundation.presentation.UIMessage
105107import org.openedx.foundation.presentation.rememberWindowSize
108+ import org.openedx.foundation.presentation.windowSizeValue
106109import java.util.Date
107110import org.openedx.core.R as CoreR
108111
@@ -184,6 +187,7 @@ private fun DashboardGalleryView(
184187 onAction : (DashboardGalleryScreenAction ) -> Unit ,
185188 hasInternetConnection : Boolean
186189) {
190+ val windowSize = rememberWindowSize()
187191 val scaffoldState = rememberScaffoldState()
188192 val pullRefreshState = rememberPullRefreshState(
189193 refreshing = updating,
@@ -193,6 +197,24 @@ private fun DashboardGalleryView(
193197 mutableStateOf(false )
194198 }
195199
200+ val contentWidth by remember(key1 = windowSize) {
201+ mutableStateOf(
202+ windowSize.windowSizeValue(
203+ expanded = Modifier .widthIn(Dp .Unspecified , 560 .dp),
204+ compact = Modifier .fillMaxWidth(),
205+ )
206+ )
207+ }
208+
209+ val contentPadding by remember(key1 = windowSize) {
210+ mutableStateOf(
211+ windowSize.windowSizeValue(
212+ expanded = PaddingValues (0 .dp),
213+ compact = PaddingValues (horizontal = 16 .dp)
214+ )
215+ )
216+ }
217+
196218 Scaffold (
197219 scaffoldState = scaffoldState,
198220 modifier = Modifier .fillMaxSize(),
@@ -209,64 +231,66 @@ private fun DashboardGalleryView(
209231 color = MaterialTheme .appColors.background
210232 ) {
211233 Box (
212- Modifier .fillMaxSize()
234+ Modifier
235+ .fillMaxSize()
236+ .pullRefresh(pullRefreshState)
237+ .verticalScroll(rememberScrollState()),
213238 ) {
214- Box (
215- Modifier
216- .fillMaxSize()
217- .pullRefresh(pullRefreshState)
218- .verticalScroll(rememberScrollState()),
219- ) {
220- when (uiState) {
221- is DashboardGalleryUIState .Loading -> {
222- CircularProgressIndicator (
223- modifier = Modifier .align(Alignment .Center ),
224- color = MaterialTheme .appColors.primary
225- )
226- }
227-
228- is DashboardGalleryUIState .Courses -> {
229- UserCourses (
230- modifier = Modifier .fillMaxSize(),
231- userCourses = uiState.userCourses,
232- useRelativeDates = uiState.useRelativeDates,
233- apiHostUrl = apiHostUrl,
234- openCourse = {
235- onAction(DashboardGalleryScreenAction .OpenCourse (it))
236- },
237- onViewAllClick = {
238- onAction(DashboardGalleryScreenAction .ViewAll )
239- },
240- navigateToDates = {
241- onAction(DashboardGalleryScreenAction .NavigateToDates (it))
242- },
243- resumeBlockId = { course, blockId ->
244- onAction(DashboardGalleryScreenAction .OpenBlock (course, blockId))
245- }
246- )
247- }
239+ when (uiState) {
240+ is DashboardGalleryUIState .Loading -> {
241+ CircularProgressIndicator (
242+ modifier = Modifier .align(Alignment .Center ),
243+ color = MaterialTheme .appColors.primary
244+ )
245+ }
248246
249- is DashboardGalleryUIState .Empty -> {
250- NoCoursesInfo (
251- modifier = Modifier
252- .align(Alignment .Center )
253- )
254- FindACourseButton (
255- modifier = Modifier
256- .align(Alignment .BottomCenter ),
257- findACourseClick = {
258- onAction(DashboardGalleryScreenAction .NavigateToDiscovery )
259- }
260- )
261- }
247+ is DashboardGalleryUIState .Courses -> {
248+ UserCourses (
249+ modifier = contentWidth
250+ .fillMaxHeight()
251+ .padding(vertical = 12 .dp)
252+ .displayCutoutForLandscape()
253+ .align(Alignment .TopCenter ),
254+ contentPadding = contentPadding,
255+ userCourses = uiState.userCourses,
256+ useRelativeDates = uiState.useRelativeDates,
257+ apiHostUrl = apiHostUrl,
258+ openCourse = {
259+ onAction(DashboardGalleryScreenAction .OpenCourse (it))
260+ },
261+ onViewAllClick = {
262+ onAction(DashboardGalleryScreenAction .ViewAll )
263+ },
264+ navigateToDates = {
265+ onAction(DashboardGalleryScreenAction .NavigateToDates (it))
266+ },
267+ resumeBlockId = { course, blockId ->
268+ onAction(DashboardGalleryScreenAction .OpenBlock (course, blockId))
269+ }
270+ )
262271 }
263272
264- PullRefreshIndicator (
265- updating,
266- pullRefreshState,
267- Modifier .align(Alignment .TopCenter )
268- )
273+ is DashboardGalleryUIState .Empty -> {
274+ NoCoursesInfo (
275+ modifier = Modifier
276+ .align(Alignment .Center )
277+ )
278+ FindACourseButton (
279+ modifier = Modifier
280+ .align(Alignment .BottomCenter ),
281+ findACourseClick = {
282+ onAction(DashboardGalleryScreenAction .NavigateToDiscovery )
283+ }
284+ )
285+ }
269286 }
287+
288+ PullRefreshIndicator (
289+ updating,
290+ pullRefreshState,
291+ Modifier .align(Alignment .TopCenter )
292+ )
293+
270294 if (! isInternetConnectionShown && ! hasInternetConnection) {
271295 OfflineModeDialog (
272296 Modifier
@@ -290,6 +314,7 @@ private fun DashboardGalleryView(
290314private fun UserCourses (
291315 modifier : Modifier = Modifier ,
292316 userCourses : CourseEnrollments ,
317+ contentPadding : PaddingValues ,
293318 apiHostUrl : String ,
294319 useRelativeDates : Boolean ,
295320 openCourse : (EnrolledCourse ) -> Unit ,
@@ -299,11 +324,11 @@ private fun UserCourses(
299324) {
300325 Column (
301326 modifier = modifier
302- .padding(vertical = 12 .dp)
303327 ) {
304328 val primaryCourse = userCourses.primary
305329 if (primaryCourse != null ) {
306330 PrimaryCourseCard (
331+ modifier = Modifier .padding(contentPadding),
307332 primaryCourse = primaryCourse,
308333 apiHostUrl = apiHostUrl,
309334 navigateToDates = navigateToDates,
@@ -317,6 +342,7 @@ private fun UserCourses(
317342 courses = userCourses.enrollments.courses,
318343 hasNextPage = userCourses.enrollments.pagination.next.isNotEmpty(),
319344 apiHostUrl = apiHostUrl,
345+ contentPadding = contentPadding,
320346 onCourseClick = openCourse,
321347 onViewAllClick = onViewAllClick
322348 )
@@ -329,6 +355,7 @@ private fun SecondaryCourses(
329355 courses : List <EnrolledCourse >,
330356 hasNextPage : Boolean ,
331357 apiHostUrl : String ,
358+ contentPadding : PaddingValues ,
332359 onCourseClick : (EnrolledCourse ) -> Unit ,
333360 onViewAllClick : () -> Unit
334361) {
@@ -348,7 +375,7 @@ private fun SecondaryCourses(
348375 verticalArrangement = Arrangement .spacedBy(8 .dp)
349376 ) {
350377 TextIcon (
351- modifier = Modifier .padding(horizontal = 18 .dp ),
378+ modifier = Modifier .padding(contentPadding ),
352379 text = stringResource(R .string.dashboard_view_all_with_count, courses.size + 1 ),
353380 textStyle = MaterialTheme .appTypography.titleSmall,
354381 icon = Icons .AutoMirrored .Filled .KeyboardArrowRight ,
@@ -361,7 +388,7 @@ private fun SecondaryCourses(
361388 .fillMaxSize()
362389 .height(height),
363390 rows = GridCells .Fixed (rows),
364- contentPadding = PaddingValues (horizontal = 18 .dp) ,
391+ contentPadding = contentPadding ,
365392 content = {
366393 items(items) {
367394 CourseListItem (
@@ -526,6 +553,7 @@ private fun AssignmentItem(
526553
527554@Composable
528555private fun PrimaryCourseCard (
556+ modifier : Modifier = Modifier ,
529557 primaryCourse : EnrolledCourse ,
530558 apiHostUrl : String ,
531559 useRelativeDates : Boolean ,
@@ -535,8 +563,7 @@ private fun PrimaryCourseCard(
535563) {
536564 val orientation = LocalConfiguration .current.orientation
537565 Card (
538- modifier = Modifier
539- .padding(horizontal = 16 .dp)
566+ modifier = modifier
540567 .fillMaxWidth()
541568 .padding(2 .dp),
542569 backgroundColor = MaterialTheme .appColors.background,
@@ -709,7 +736,7 @@ private fun PrimaryCourseCaption(
709736 )
710737 val progress: Float = try {
711738 primaryCourse.progress.assignmentsCompleted.toFloat() /
712- primaryCourse.progress.totalAssignmentsCount.toFloat()
739+ primaryCourse.progress.totalAssignmentsCount.toFloat()
713740 } catch (_: ArithmeticException ) {
714741 0f
715742 }
0 commit comments