Skip to content

Commit 5587659

Browse files
fix: remove course size
1 parent efa6d85 commit 5587659

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.openedx.core.R
2222
import org.openedx.core.config.Config
2323
import org.openedx.core.data.storage.CorePreferences
2424
import org.openedx.core.domain.model.CourseStructure
25+
import org.openedx.core.domain.model.DownloadCoursePreview
2526
import org.openedx.core.module.DownloadWorkerController
2627
import org.openedx.core.module.db.DownloadDao
2728
import org.openedx.core.module.db.DownloadedState
@@ -225,11 +226,11 @@ class DownloadsViewModel(
225226
fun removeDownloads(fragmentManager: FragmentManager, courseId: String) {
226227
logEvent(DownloadsAnalyticsEvent.REMOVE_DOWNLOAD_CLICKED)
227228
viewModelScope.launch {
228-
val downloadModels =
229-
interactor.getDownloadModels().first().filter { it.courseId == courseId }
229+
val downloadModels = interactor.getDownloadModels().first().filter {
230+
it.courseId == courseId && it.downloadedState == DownloadedState.DOWNLOADED
231+
}
230232
val totalSize = downloadModels.sumOf { it.size }
231-
val title =
232-
_uiState.value.downloadCoursePreviews.find { it.id == courseId }?.name.orEmpty()
233+
val title = getCoursePreview(courseId)?.name.orEmpty()
233234
val downloadDialogItem = DownloadDialogItem(
234235
title = title,
235236
size = totalSize,
@@ -261,8 +262,7 @@ class DownloadsViewModel(
261262
}
262263

263264
private fun showDownloadPopup(fragmentManager: FragmentManager, courseId: String) {
264-
val coursePreview =
265-
_uiState.value.downloadCoursePreviews.find { it.id == courseId } ?: return
265+
val coursePreview = getCoursePreview(courseId) ?: return
266266
downloadDialogManager.showPopup(
267267
coursePreview = coursePreview,
268268
isBlocksDownloaded = false,
@@ -304,8 +304,7 @@ class DownloadsViewModel(
304304
}
305305

306306
fun navigateToCourseOutline(fm: FragmentManager, courseId: String) {
307-
val coursePreview =
308-
_uiState.value.downloadCoursePreviews.find { it.id == courseId } ?: return
307+
val coursePreview = getCoursePreview(courseId) ?: return
309308
router.navigateToCourseOutline(
310309
fm = fm,
311310
courseId = coursePreview.id,
@@ -329,6 +328,10 @@ class DownloadsViewModel(
329328
)
330329
}
331330
}
331+
332+
private fun getCoursePreview(courseId: String): DownloadCoursePreview? {
333+
return _uiState.value.downloadCoursePreviews.find { it.id == courseId }
334+
}
332335
}
333336

334337
interface DownloadsViewActions {

0 commit comments

Comments
 (0)