Skip to content

Commit 0b254f7

Browse files
fix: AllEnrolledCoursesView and DashboardGalleryView tablet layout paddings (#433)
1 parent 943381b commit 0b254f7

File tree

4 files changed

+132
-101
lines changed

4 files changed

+132
-101
lines changed

dashboard/src/main/java/org/openedx/courses/presentation/AllEnrolledCoursesView.kt

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private fun AllEnrolledCoursesView(
230230
val contentWidth by remember(key1 = windowSize) {
231231
mutableStateOf(
232232
windowSize.windowSizeValue(
233-
expanded = Modifier.widthIn(Dp.Unspecified, 650.dp),
233+
expanded = Modifier.widthIn(Dp.Unspecified, 560.dp),
234234
compact = Modifier.fillMaxWidth(),
235235
)
236236
)
@@ -274,7 +274,9 @@ private fun AllEnrolledCoursesView(
274274
Header(
275275
modifier = Modifier
276276
.padding(
277-
start = contentPaddings.calculateStartPadding(layoutDirection),
277+
start = contentPaddings.calculateStartPadding(
278+
layoutDirection
279+
),
278280
end = contentPaddings.calculateEndPadding(layoutDirection)
279281
),
280282
onSearchClick = {
@@ -305,50 +307,52 @@ private fun AllEnrolledCoursesView(
305307

306308
!state.courses.isNullOrEmpty() -> {
307309
Box(
308-
modifier = Modifier
309-
.fillMaxSize()
310-
.padding(contentPaddings),
311-
contentAlignment = Alignment.Center
310+
modifier = Modifier.fillMaxSize(),
311+
contentAlignment = Alignment.TopCenter
312312
) {
313-
Column(
314-
modifier = Modifier.fillMaxWidth(),
315-
horizontalAlignment = Alignment.CenterHorizontally
316-
) {
317-
LazyVerticalGrid(
318-
modifier = Modifier
319-
.fillMaxHeight(),
320-
state = scrollState,
321-
columns = GridCells.Fixed(columns),
322-
verticalArrangement = Arrangement.spacedBy(12.dp),
323-
horizontalArrangement = Arrangement.spacedBy(12.dp),
324-
content = {
325-
items(state.courses) { course ->
326-
CourseItem(
327-
course = course,
328-
apiHostUrl = apiHostUrl,
329-
onClick = {
330-
onAction(AllEnrolledCoursesAction.OpenCourse(it))
331-
}
332-
)
333-
}
334-
item(span = { GridItemSpan(columns) }) {
335-
if (state.canLoadMore) {
336-
Box(
337-
modifier = Modifier
338-
.fillMaxWidth()
339-
.height(180.dp),
340-
contentAlignment = Alignment.Center
341-
) {
342-
CircularProgressIndicator(
343-
color = MaterialTheme.appColors.primary
313+
LazyVerticalGrid(
314+
modifier = Modifier
315+
.fillMaxHeight(),
316+
state = scrollState,
317+
columns = GridCells.Fixed(columns),
318+
verticalArrangement = Arrangement.spacedBy(12.dp),
319+
horizontalArrangement = Arrangement.spacedBy(12.dp),
320+
contentPadding = contentPaddings,
321+
content = {
322+
items(state.courses) { course ->
323+
CourseItem(
324+
course = course,
325+
apiHostUrl = apiHostUrl,
326+
onClick = {
327+
onAction(
328+
AllEnrolledCoursesAction.OpenCourse(
329+
it
344330
)
345-
}
331+
)
332+
}
333+
)
334+
}
335+
item(span = { GridItemSpan(columns) }) {
336+
if (state.canLoadMore) {
337+
Box(
338+
modifier = Modifier
339+
.fillMaxWidth()
340+
.height(180.dp),
341+
contentAlignment = Alignment.Center
342+
) {
343+
CircularProgressIndicator(
344+
color = MaterialTheme.appColors.primary
345+
)
346346
}
347347
}
348348
}
349+
}
350+
)
351+
if (scrollState.shouldLoadMore(
352+
firstVisibleIndex,
353+
LOAD_MORE_THRESHOLD
349354
)
350-
}
351-
if (scrollState.shouldLoadMore(firstVisibleIndex, LOAD_MORE_THRESHOLD)) {
355+
) {
352356
onAction(AllEnrolledCoursesAction.EndOfPage)
353357
}
354358
}

dashboard/src/main/java/org/openedx/courses/presentation/DashboardGalleryView.kt

Lines changed: 86 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.heightIn
1818
import androidx.compose.foundation.layout.padding
1919
import androidx.compose.foundation.layout.size
2020
import androidx.compose.foundation.layout.width
21+
import androidx.compose.foundation.layout.widthIn
2122
import androidx.compose.foundation.lazy.grid.GridCells
2223
import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid
2324
import androidx.compose.foundation.lazy.grid.items
@@ -46,6 +47,7 @@ import androidx.compose.runtime.LaunchedEffect
4647
import androidx.compose.runtime.collectAsState
4748
import androidx.compose.runtime.getValue
4849
import androidx.compose.runtime.mutableStateOf
50+
import androidx.compose.runtime.remember
4951
import androidx.compose.runtime.saveable.rememberSaveable
5052
import androidx.compose.runtime.setValue
5153
import androidx.compose.ui.Alignment
@@ -103,6 +105,7 @@ import org.openedx.dashboard.R
103105
import org.openedx.foundation.extension.toImageLink
104106
import org.openedx.foundation.presentation.UIMessage
105107
import org.openedx.foundation.presentation.rememberWindowSize
108+
import org.openedx.foundation.presentation.windowSizeValue
106109
import java.util.Date
107110
import 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(
290314
private 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
528555
private 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
}

downloads/src/main/java/org/openedx/downloads/presentation/download/DownloadsViewModel.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.compose.material.icons.Icons
44
import androidx.compose.material.icons.filled.School
55
import androidx.fragment.app.FragmentManager
66
import androidx.lifecycle.viewModelScope
7-
import kotlinx.coroutines.Dispatchers
87
import kotlinx.coroutines.Job
98
import kotlinx.coroutines.flow.MutableSharedFlow
109
import kotlinx.coroutines.flow.MutableStateFlow
@@ -171,7 +170,7 @@ class DownloadsViewModel(
171170
}
172171

173172
private fun fetchDownloads(refresh: Boolean) {
174-
viewModelScope.launch(Dispatchers.IO) {
173+
viewModelScope.launch {
175174
updateLoadingState(isLoading = !refresh, isRefreshing = refresh)
176175
interactor.getDownloadCoursesPreview(refresh)
177176
.onCompletion {

downloads/src/test/java/org/openedx/downloads/DownloadsViewModelTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class DownloadsViewModelTest {
265265
workerController,
266266
downloadHelper
267267
)
268+
advanceUntilIdle()
268269
val fragmentManager = mockk<FragmentManager>(relaxed = true)
269270
viewModel.downloadCourse(fragmentManager, "course1")
270271
advanceUntilIdle()

0 commit comments

Comments
 (0)