Skip to content

Commit 3ff18de

Browse files
fix: update download page after getting course structure on outline page
1 parent 6333891 commit 3ff18de

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

app/src/main/java/org/openedx/app/di/ScreenModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ val screenModule = module {
525525
fileUtil = get(),
526526
analytics = get(),
527527
discoveryNotifier = get(),
528+
courseNotifier = get(),
528529
router = get()
529530
)
530531
}

core/src/main/java/org/openedx/core/system/notifier/CourseNotifier.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class CourseNotifier {
1212

1313
suspend fun send(event: CourseVideoPositionChanged) = channel.emit(event)
1414
suspend fun send(event: CourseStructureUpdated) = channel.emit(event)
15+
suspend fun send(event: CourseStructureGot) = channel.emit(event)
1516
suspend fun send(event: CourseSubtitleLanguageChanged) = channel.emit(event)
1617
suspend fun send(event: CourseSectionChanged) = channel.emit(event)
1718
suspend fun send(event: CourseCompletionSet) = channel.emit(event)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.openedx.core.system.notifier
2+
3+
class CourseStructureGot(
4+
val courseId: String
5+
) : CourseEvent

course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.openedx.course.presentation.container
33
import android.graphics.Bitmap
44
import android.graphics.drawable.BitmapDrawable
55
import android.os.Build
6+
import androidx.core.graphics.createBitmap
67
import androidx.lifecycle.LiveData
78
import androidx.lifecycle.MutableLiveData
89
import androidx.lifecycle.viewModelScope
@@ -35,6 +36,7 @@ import org.openedx.core.system.notifier.CourseDatesShifted
3536
import org.openedx.core.system.notifier.CourseLoading
3637
import org.openedx.core.system.notifier.CourseNotifier
3738
import org.openedx.core.system.notifier.CourseOpenBlock
39+
import org.openedx.core.system.notifier.CourseStructureGot
3840
import org.openedx.core.system.notifier.CourseStructureUpdated
3941
import org.openedx.core.system.notifier.RefreshDates
4042
import org.openedx.core.system.notifier.RefreshDiscussions
@@ -116,7 +118,7 @@ class CourseContainerViewModel(
116118
val calendarSyncUIState: StateFlow<CalendarSyncUIState> =
117119
_calendarSyncUIState.asStateFlow()
118120

119-
private var _courseImage = MutableStateFlow(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888))
121+
private var _courseImage = MutableStateFlow(createBitmap(1, 1))
120122
val courseImage: StateFlow<Bitmap> = _courseImage.asStateFlow()
121123

122124
val hasInternetConnection: Boolean
@@ -187,6 +189,7 @@ class CourseContainerViewModel(
187189
courseStructure != null -> handleCourseStructureOnly(courseStructure)
188190
else -> _courseAccessStatus.value = CourseAccessError.UNKNOWN
189191
}
192+
courseNotifier.send(CourseStructureGot(courseId))
190193
}
191194
}
192195
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogItem
3636
import org.openedx.core.presentation.dialog.downloaddialog.DownloadDialogManager
3737
import org.openedx.core.system.connection.NetworkConnection
3838
import org.openedx.core.system.notifier.CourseDashboardUpdate
39+
import org.openedx.core.system.notifier.CourseNotifier
40+
import org.openedx.core.system.notifier.CourseStructureGot
41+
import org.openedx.core.system.notifier.CourseStructureUpdated
3942
import org.openedx.core.system.notifier.DiscoveryNotifier
4043
import org.openedx.downloads.domain.interactor.DownloadInteractor
4144
import org.openedx.downloads.presentation.DownloadsRouter
@@ -54,6 +57,7 @@ class DownloadsViewModel(
5457
private val config: Config,
5558
private val analytics: DownloadsAnalytics,
5659
private val discoveryNotifier: DiscoveryNotifier,
60+
private val courseNotifier: CourseNotifier,
5761
private val router: DownloadsRouter,
5862
preferencesManager: CorePreferences,
5963
coreAnalytics: CoreAnalytics,
@@ -86,6 +90,7 @@ class DownloadsViewModel(
8690
observeCourseDashboardUpdates()
8791
observeDownloadingModels()
8892
observeDownloadModelsStatus()
93+
observeCourseStructureUpdates()
8994
}
9095

9196
private fun observeCourseDashboardUpdates() {
@@ -98,6 +103,22 @@ class DownloadsViewModel(
98103
}
99104
}
100105

106+
private fun observeCourseStructureUpdates() {
107+
viewModelScope.launch {
108+
courseNotifier.notifier.collect { notifier ->
109+
when (notifier) {
110+
is CourseStructureGot -> {
111+
fetchDownloads(refresh = true)
112+
}
113+
114+
is CourseStructureUpdated -> {
115+
fetchDownloads(refresh = true)
116+
}
117+
}
118+
}
119+
}
120+
}
121+
101122
private fun observeDownloadingModels() {
102123
viewModelScope.launch {
103124
downloadingModelsFlow.collect { downloadModels ->

0 commit comments

Comments
 (0)