Skip to content

Commit b4e6241

Browse files
feat: show loading course structure state
1 parent 60c7e13 commit b4e6241

File tree

22 files changed

+226
-165
lines changed

22 files changed

+226
-165
lines changed

app/src/main/java/org/openedx/app/MainFragment.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class MainFragment : Fragment(R.layout.fragment_main) {
4040
}
4141
}
4242

43+
@Suppress("LongMethod", "CyclomaticComplexMethod")
4344
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
4445
super.onViewCreated(view, savedInstanceState)
4546

@@ -124,7 +125,12 @@ class MainFragment : Fragment(R.layout.fragment_main) {
124125
val initialMenuId = when (openTabArg) {
125126
HomeTab.LEARN.name, HomeTab.PROGRAMS.name -> R.id.fragmentLearn
126127
HomeTab.DISCOVER.name -> R.id.fragmentDiscover
127-
HomeTab.DOWNLOADS.name -> if (viewModel.isDownloadsFragmentEnabled) R.id.fragmentDownloads else R.id.fragmentLearn
128+
HomeTab.DOWNLOADS.name -> if (viewModel.isDownloadsFragmentEnabled) {
129+
R.id.fragmentDownloads
130+
} else {
131+
R.id.fragmentLearn
132+
}
133+
128134
HomeTab.PROFILE.name -> R.id.fragmentProfile
129135
else -> R.id.fragmentLearn
130136
}
@@ -133,7 +139,6 @@ class MainFragment : Fragment(R.layout.fragment_main) {
133139
requireArguments().remove(ARG_OPEN_TAB)
134140
}
135141

136-
@Suppress("MagicNumber")
137142
private fun initViewPager(tabList: List<Pair<Int, Fragment>>) {
138143
binding.viewPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
139144
binding.viewPager.offscreenPageLimit = tabList.size

app/src/main/java/org/openedx/app/room/AppDatabase.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const val DATABASE_NAME = "OpenEdX_db"
3434
CourseCalendarEventEntity::class,
3535
CourseCalendarStateEntity::class,
3636
DownloadCoursePreview::class,
37-
CourseCalendarStateEntity::class,
3837
CourseEnrollmentDetailsEntity::class
3938
],
4039
autoMigrations = [

core/src/main/java/org/openedx/core/module/db/DownloadModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ data class DownloadModel(
1717
) : Parcelable
1818

1919
enum class DownloadedState {
20-
WAITING, DOWNLOADING, DOWNLOADED, NOT_DOWNLOADED;
20+
WAITING, DOWNLOADING, DOWNLOADED, NOT_DOWNLOADED, LOADING_COURSE_STRUCTURE;
2121

2222
val isWaitingOrDownloading: Boolean
2323
get() {
24-
return this == WAITING || this == DOWNLOADING
24+
return this == WAITING || this == DOWNLOADING || this == LOADING_COURSE_STRUCTURE
2525
}
2626

2727
val isDownloaded: Boolean

core/src/main/java/org/openedx/core/module/download/BaseDownloadViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ abstract class BaseDownloadViewModel(
6565
updateParentStatus(parentId, children.size, downloadingCount, downloadedCount)
6666
}
6767

68-
// downloadingModelsList = models.filter { it.downloadedState.isWaitingOrDownloading }
6968
_downloadingModelsFlow.emit(models)
7069
}
7170

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ import org.openedx.foundation.extension.toFileSize
4848
import org.openedx.foundation.system.PreviewFragmentManager
4949
import androidx.compose.ui.graphics.Color as ComposeColor
5050

51-
class DownloadConfirmDialogFragment : DialogFragment() {
51+
class DownloadConfirmDialogFragment : DialogFragment(), DownloadDialog {
52+
53+
override var listener: DownloadDialogListener? = null
5254

5355
override fun onCreateView(
5456
inflater: LayoutInflater,
@@ -67,24 +69,24 @@ class DownloadConfirmDialogFragment : DialogFragment() {
6769
DownloadConfirmDialogType.CONFIRM -> DownloadDialogResource(
6870
title = stringResource(id = R.string.course_confirm_download),
6971
description = stringResource(
70-
id = R.string.course_download_confirm_dialog_description,
72+
id = R.string.core_download_confirm_dialog_description,
7173
sizeSumString
7274
),
7375
)
7476

7577
DownloadConfirmDialogType.DOWNLOAD_ON_CELLULAR -> DownloadDialogResource(
76-
title = stringResource(id = R.string.course_download_on_cellural),
78+
title = stringResource(id = R.string.core_download_on_cellural),
7779
description = stringResource(
78-
id = R.string.course_download_on_cellural_dialog_description,
80+
id = R.string.core_download_on_cellural_dialog_description,
7981
sizeSumString
8082
),
8183
icon = painterResource(id = R.drawable.core_ic_warning),
8284
)
8385

8486
DownloadConfirmDialogType.REMOVE -> DownloadDialogResource(
85-
title = stringResource(id = R.string.course_download_remove_offline_content),
87+
title = stringResource(id = R.string.core_download_remove_offline_content),
8688
description = stringResource(
87-
id = R.string.course_download_remove_dialog_description,
89+
id = R.string.core_download_remove_dialog_description,
8890
sizeSumString
8991
)
9092
)
@@ -104,6 +106,7 @@ class DownloadConfirmDialogFragment : DialogFragment() {
104106
},
105107
onCancelClick = {
106108
dismiss()
109+
listener?.onCancel()
107110
}
108111
)
109112
}
@@ -186,14 +189,14 @@ private fun DownloadConfirmDialogView(
186189
val onClick: () -> Unit
187190
when (dialogType) {
188191
DownloadConfirmDialogType.REMOVE -> {
189-
buttonText = stringResource(id = R.string.course_remove)
192+
buttonText = stringResource(id = R.string.core_remove)
190193
buttonIcon = Icons.Rounded.Delete
191194
buttonColor = MaterialTheme.appColors.error
192195
onClick = onRemoveClick
193196
}
194197

195198
else -> {
196-
buttonText = stringResource(id = R.string.course_download)
199+
buttonText = stringResource(id = R.string.core_download)
197200
buttonIcon = Icons.Outlined.CloudDownload
198201
buttonColor = MaterialTheme.appColors.secondaryButtonBackground
199202
onClick = onConfirmClick

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import org.openedx.core.module.db.DownloadModel
1414
import org.openedx.core.system.StorageManager
1515
import org.openedx.core.system.connection.NetworkConnection
1616

17+
interface DownloadDialogListener {
18+
fun onCancel()
19+
}
20+
21+
interface DownloadDialog {
22+
var listener: DownloadDialogListener?
23+
}
24+
1725
class DownloadDialogManager(
1826
private val networkConnection: NetworkConnection,
1927
private val corePreferences: CorePreferences,
@@ -76,6 +84,12 @@ class DownloadDialogManager(
7684
else -> null
7785
}
7886

87+
val dialogListener = object : DownloadDialogListener {
88+
override fun onCancel() {
89+
state.onDismissClick()
90+
}
91+
}
92+
dialog?.listener = dialogListener
7993
dialog?.show(state.fragmentManager, dialog::class.java.simpleName) ?: state.saveDownloadModels()
8094
}
8195
}
@@ -89,6 +103,7 @@ class DownloadDialogManager(
89103
fragmentManager: FragmentManager,
90104
removeDownloadModels: (blockId: String, courseId: String) -> Unit,
91105
saveDownloadModels: (blockId: String) -> Unit,
106+
onDismissClick: () -> Unit = {},
92107
) {
93108
createDownloadItems(
94109
subSectionsBlocks = subSectionsBlocks,
@@ -97,7 +112,8 @@ class DownloadDialogManager(
97112
isBlocksDownloaded = isBlocksDownloaded,
98113
onlyVideoBlocks = onlyVideoBlocks,
99114
removeDownloadModels = removeDownloadModels,
100-
saveDownloadModels = saveDownloadModels
115+
saveDownloadModels = saveDownloadModels,
116+
onDismissClick = onDismissClick
101117
)
102118
}
103119

@@ -190,6 +206,7 @@ class DownloadDialogManager(
190206
onlyVideoBlocks: Boolean,
191207
removeDownloadModels: (blockId: String, courseId: String) -> Unit,
192208
saveDownloadModels: (blockId: String) -> Unit,
209+
onDismissClick: () -> Unit = {},
193210
) {
194211
coroutineScope.launch {
195212
val courseStructure = interactor.getCourseStructure(courseId, false)
@@ -223,7 +240,8 @@ class DownloadDialogManager(
223240
)
224241
}
225242
},
226-
saveDownloadModels = { subSectionsBlocks.forEach { saveDownloadModels(it.id) } }
243+
saveDownloadModels = { subSectionsBlocks.forEach { saveDownloadModels(it.id) } },
244+
onDismissClick = onDismissClick,
227245
)
228246
)
229247
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ data class DownloadDialogUIState(
1313
val isDownloadFailed: Boolean,
1414
val fragmentManager: @RawValue FragmentManager,
1515
val removeDownloadModels: () -> Unit,
16-
val saveDownloadModels: () -> Unit
16+
val saveDownloadModels: () -> Unit,
17+
val onDismissClick: () -> Unit = {},
1718
) : Parcelable

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ import org.openedx.core.ui.theme.appTypography
4141
import org.openedx.foundation.extension.parcelable
4242
import org.openedx.foundation.system.PreviewFragmentManager
4343

44-
class DownloadErrorDialogFragment : DialogFragment() {
44+
class DownloadErrorDialogFragment : DialogFragment(), DownloadDialog {
45+
46+
override var listener: DownloadDialogListener? = null
4547

4648
override fun onCreateView(
4749
inflater: LayoutInflater,
@@ -58,19 +60,19 @@ class DownloadErrorDialogFragment : DialogFragment() {
5860
val downloadDialogResource = when (dialogType) {
5961
DownloadErrorDialogType.NO_CONNECTION -> DownloadDialogResource(
6062
title = stringResource(id = R.string.core_no_internet_connection),
61-
description = stringResource(id = R.string.course_download_no_internet_dialog_description),
63+
description = stringResource(id = R.string.core_download_no_internet_dialog_description),
6264
icon = painterResource(id = R.drawable.core_ic_error),
6365
)
6466

6567
DownloadErrorDialogType.WIFI_REQUIRED -> DownloadDialogResource(
66-
title = stringResource(id = R.string.course_wifi_required),
67-
description = stringResource(id = R.string.course_download_wifi_required_dialog_description),
68+
title = stringResource(id = R.string.core_wifi_required),
69+
description = stringResource(id = R.string.core_download_wifi_required_dialog_description),
6870
icon = painterResource(id = R.drawable.core_ic_error),
6971
)
7072

7173
DownloadErrorDialogType.DOWNLOAD_FAILED -> DownloadDialogResource(
72-
title = stringResource(id = R.string.course_download_failed),
73-
description = stringResource(id = R.string.course_download_failed_dialog_description),
74+
title = stringResource(id = R.string.core_download_failed),
75+
description = stringResource(id = R.string.core_download_failed_dialog_description),
7476
icon = painterResource(id = R.drawable.core_ic_error),
7577
)
7678
}
@@ -85,6 +87,7 @@ class DownloadErrorDialogFragment : DialogFragment() {
8587
},
8688
onCancelClick = {
8789
dismiss()
90+
listener?.onCancel()
8891
}
8992
)
9093
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ import org.openedx.foundation.extension.parcelable
5656
import org.openedx.foundation.extension.toFileSize
5757
import org.openedx.foundation.system.PreviewFragmentManager
5858

59-
class DownloadStorageErrorDialogFragment : DialogFragment() {
59+
class DownloadStorageErrorDialogFragment : DialogFragment(), DownloadDialog {
60+
61+
override var listener: DownloadDialogListener? = null
6062

6163
override fun onCreateView(
6264
inflater: LayoutInflater,
@@ -69,8 +71,8 @@ class DownloadStorageErrorDialogFragment : DialogFragment() {
6971
OpenEdXTheme {
7072
val uiState = requireArguments().parcelable<DownloadDialogUIState>(ARG_UI_STATE) ?: return@OpenEdXTheme
7173
val downloadDialogResource = DownloadDialogResource(
72-
title = stringResource(id = R.string.course_device_storage_full),
73-
description = stringResource(id = R.string.course_download_device_storage_full_dialog_description),
74+
title = stringResource(id = R.string.core_device_storage_full),
75+
description = stringResource(id = R.string.core_download_device_storage_full_dialog_description),
7476
icon = painterResource(id = R.drawable.core_ic_error),
7577
)
7678

@@ -79,6 +81,7 @@ class DownloadStorageErrorDialogFragment : DialogFragment() {
7981
downloadDialogResource = downloadDialogResource,
8082
onCancelClick = {
8183
dismiss()
84+
listener?.onCancel()
8285
}
8386
)
8487
}
@@ -241,7 +244,7 @@ private fun StorageBar(
241244
) {
242245
Text(
243246
text = stringResource(
244-
R.string.course_used_free_storage,
247+
R.string.core_used_free_storage,
245248
usedSpace.toFileSize(1, false),
246249
freeSpace.toFileSize(1, false)
247250
),

0 commit comments

Comments
 (0)