Skip to content

Commit d0288bd

Browse files
feat: added height limit and scroll to download dialog
1 parent f6b5b92 commit d0288bd

File tree

7 files changed

+54
-13
lines changed

7 files changed

+54
-13
lines changed

core/src/main/java/org/openedx/core/presentation/dialog/downloaddialog/DownloadConfirmDialogFragment.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
1010
import androidx.compose.foundation.layout.Row
1111
import androidx.compose.foundation.layout.Spacer
1212
import androidx.compose.foundation.layout.fillMaxWidth
13+
import androidx.compose.foundation.layout.heightIn
1314
import androidx.compose.foundation.layout.padding
1415
import androidx.compose.foundation.layout.size
1516
import androidx.compose.foundation.layout.width
@@ -62,8 +63,10 @@ class DownloadConfirmDialogFragment : DialogFragment(), DownloadDialog {
6263
setContent {
6364
OpenEdXTheme {
6465
val dialogType =
65-
requireArguments().parcelable<DownloadConfirmDialogType>(ARG_DIALOG_TYPE) ?: return@OpenEdXTheme
66-
val uiState = requireArguments().parcelable<DownloadDialogUIState>(ARG_UI_STATE) ?: return@OpenEdXTheme
66+
requireArguments().parcelable<DownloadConfirmDialogType>(ARG_DIALOG_TYPE)
67+
?: return@OpenEdXTheme
68+
val uiState = requireArguments().parcelable<DownloadDialogUIState>(ARG_UI_STATE)
69+
?: return@OpenEdXTheme
6770
val sizeSumString = uiState.sizeSum.toFileSize(1, false)
6871
val dialogData = when (dialogType) {
6972
DownloadConfirmDialogType.CONFIRM -> DownloadDialogResource(
@@ -150,7 +153,6 @@ private fun DownloadConfirmDialogView(
150153
Column(
151154
modifier = Modifier
152155
.fillMaxWidth()
153-
.verticalScroll(scrollState)
154156
.padding(20.dp),
155157
verticalArrangement = Arrangement.spacedBy(12.dp)
156158
) {
@@ -173,7 +175,11 @@ private fun DownloadConfirmDialogView(
173175
minSize = MaterialTheme.appTypography.titleLarge.fontSize.value - 1
174176
)
175177
}
176-
Column {
178+
Column(
179+
modifier = Modifier
180+
.heightIn(max = DownloadDialogManager.listMaxSize)
181+
.verticalScroll(scrollState)
182+
) {
177183
uiState.downloadDialogItems.forEach {
178184
DownloadDialogItem(downloadDialogItem = it)
179185
}

core/src/main/java/org/openedx/core/presentation/dialog/downloaddialog/DownloadDialogManager.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.openedx.core.presentation.dialog.downloaddialog
22

3+
import android.content.res.Configuration
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.platform.LocalConfiguration
6+
import androidx.compose.ui.unit.Dp
7+
import androidx.compose.ui.unit.dp
38
import androidx.fragment.app.FragmentManager
49
import kotlinx.coroutines.CoroutineScope
510
import kotlinx.coroutines.Dispatchers
@@ -14,6 +19,7 @@ import org.openedx.core.module.DownloadWorkerController
1419
import org.openedx.core.module.db.DownloadModel
1520
import org.openedx.core.system.StorageManager
1621
import org.openedx.core.system.connection.NetworkConnection
22+
import org.openedx.foundation.presentation.rememberWindowSize
1723

1824
interface DownloadDialogListener {
1925
fun onCancelClick()
@@ -34,6 +40,22 @@ class DownloadDialogManager(
3440
companion object {
3541
const val MAX_CELLULAR_SIZE = 104857600 // 100MB
3642
const val DOWNLOAD_SIZE_FACTOR = 2 // Multiplier to match required disk size
43+
44+
val listMaxSize: Dp
45+
@Composable
46+
get() {
47+
val configuration = LocalConfiguration.current
48+
val windowSize = rememberWindowSize()
49+
return when {
50+
configuration.orientation == Configuration.ORIENTATION_PORTRAIT || windowSize.isTablet -> {
51+
200.dp
52+
}
53+
54+
else -> {
55+
88.dp
56+
}
57+
}
58+
}
3759
}
3860

3961
private val uiState = MutableSharedFlow<DownloadDialogUIState>()

core/src/main/java/org/openedx/core/presentation/dialog/downloaddialog/DownloadErrorDialogFragment.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
1010
import androidx.compose.foundation.layout.Row
1111
import androidx.compose.foundation.layout.Spacer
1212
import androidx.compose.foundation.layout.fillMaxWidth
13+
import androidx.compose.foundation.layout.heightIn
1314
import androidx.compose.foundation.layout.padding
1415
import androidx.compose.foundation.layout.size
1516
import androidx.compose.foundation.layout.width
@@ -133,7 +134,6 @@ private fun DownloadErrorDialogView(
133134
Column(
134135
modifier = Modifier
135136
.fillMaxWidth()
136-
.verticalScroll(scrollState)
137137
.padding(20.dp),
138138
verticalArrangement = Arrangement.spacedBy(12.dp)
139139
) {
@@ -156,7 +156,11 @@ private fun DownloadErrorDialogView(
156156
minSize = MaterialTheme.appTypography.titleLarge.fontSize.value - 1
157157
)
158158
}
159-
Column {
159+
Column(
160+
modifier = Modifier
161+
.heightIn(max = DownloadDialogManager.listMaxSize)
162+
.verticalScroll(scrollState)
163+
) {
160164
uiState.downloadDialogItems.forEach {
161165
DownloadDialogItem(downloadDialogItem = it)
162166
}

core/src/main/java/org/openedx/core/presentation/dialog/downloaddialog/DownloadStorageErrorDialogFragment.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.Spacer
1818
import androidx.compose.foundation.layout.fillMaxHeight
1919
import androidx.compose.foundation.layout.fillMaxWidth
2020
import androidx.compose.foundation.layout.height
21+
import androidx.compose.foundation.layout.heightIn
2122
import androidx.compose.foundation.layout.padding
2223
import androidx.compose.foundation.layout.size
2324
import androidx.compose.foundation.layout.width
@@ -69,7 +70,8 @@ class DownloadStorageErrorDialogFragment : DialogFragment(), DownloadDialog {
6970
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
7071
setContent {
7172
OpenEdXTheme {
72-
val uiState = requireArguments().parcelable<DownloadDialogUIState>(ARG_UI_STATE) ?: return@OpenEdXTheme
73+
val uiState = requireArguments().parcelable<DownloadDialogUIState>(ARG_UI_STATE)
74+
?: return@OpenEdXTheme
7375
val downloadDialogResource = DownloadDialogResource(
7476
title = stringResource(id = R.string.core_device_storage_full),
7577
description = stringResource(id = R.string.core_download_device_storage_full_dialog_description),
@@ -119,7 +121,6 @@ private fun DownloadStorageErrorDialogView(
119121
Column(
120122
modifier = Modifier
121123
.fillMaxWidth()
122-
.verticalScroll(scrollState)
123124
.padding(20.dp),
124125
verticalArrangement = Arrangement.spacedBy(12.dp)
125126
) {
@@ -142,7 +143,11 @@ private fun DownloadStorageErrorDialogView(
142143
minSize = MaterialTheme.appTypography.titleLarge.fontSize.value - 1
143144
)
144145
}
145-
Column {
146+
Column(
147+
modifier = Modifier
148+
.heightIn(max = DownloadDialogManager.listMaxSize)
149+
.verticalScroll(scrollState)
150+
) {
146151
uiState.downloadDialogItems.forEach {
147152
DownloadDialogItem(downloadDialogItem = it.copy(size = it.size * DOWNLOAD_SIZE_FACTOR))
148153
}

course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class CourseOfflineViewModel(
131131
val downloadDialogItem = DownloadDialogItem(
132132
title = courseTitle,
133133
size = totalSize,
134-
icon = Icons.AutoMirrored.Outlined.InsertDriveFile
135134
)
136135
downloadDialogManager.showRemoveDownloadModelPopup(
137136
downloadDialogItem = downloadDialogItem,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fun DownloadsScreen(
173173
columns = GridCells.Fixed(2),
174174
verticalArrangement = Arrangement.spacedBy(20.dp),
175175
horizontalArrangement = Arrangement.spacedBy(20.dp),
176-
contentPadding = PaddingValues(bottom = 20.dp, top = 12.dp),
176+
contentPadding = PaddingValues(bottom = 46.dp, top = 12.dp),
177177
content = {
178178
items(uiState.downloadCoursePreviews) { item ->
179179
val downloadModels =
@@ -205,7 +205,7 @@ fun DownloadsScreen(
205205
} else {
206206
LazyColumn(
207207
modifier = contentWidth,
208-
contentPadding = PaddingValues(bottom = 20.dp, top = 12.dp),
208+
contentPadding = PaddingValues(bottom = 46.dp, top = 12.dp),
209209
verticalArrangement = Arrangement.spacedBy(20.dp)
210210
) {
211211
items(uiState.downloadCoursePreviews) { item ->

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ class DownloadsViewModel(
141141
.sumOf { it.size }
142142
val courseSize = _uiState.value.downloadCoursePreviews
143143
.find { it.id == courseId }?.totalSize ?: 0
144-
val isSizeMatch: Boolean = downloadedSize.toDouble() / courseSize >= 0.95
144+
val isSizeMatch: Boolean =
145+
downloadedSize.toDouble() / courseSize >= SIZE_MATCH_THRESHOLD
145146
determineCourseState(blockStates, isSizeMatch)
146147
}
147148
if (currentCourseState == DownloadedState.LOADING_COURSE_STRUCTURE &&
@@ -367,6 +368,10 @@ class DownloadsViewModel(
367368
private fun getCoursePreview(courseId: String): DownloadCoursePreview? {
368369
return _uiState.value.downloadCoursePreviews.find { it.id == courseId }
369370
}
371+
372+
companion object {
373+
const val SIZE_MATCH_THRESHOLD = 0.95
374+
}
370375
}
371376

372377
interface DownloadsViewActions {

0 commit comments

Comments
 (0)