Skip to content

Commit a6a85e2

Browse files
feat: changes according PR feedback
1 parent 5e1b11f commit a6a85e2

File tree

10 files changed

+70
-45
lines changed

10 files changed

+70
-45
lines changed

app/schemas/org.openedx.app.room.AppDatabase/4.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 4,
5-
"identityHash": "488bd2b78e977fef626afb28014c80f2",
5+
"identityHash": "7ea446decde04c9c16700cb3981703c2",
66
"entities": [
77
{
88
"tableName": "course_discovery_table",
@@ -1008,7 +1008,7 @@
10081008
},
10091009
{
10101010
"tableName": "video_progress_table",
1011-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`block_id` TEXT NOT NULL, `video_url` TEXT NOT NULL, `video_time` INTEGER NOT NULL, `duration` INTEGER NOT NULL, PRIMARY KEY(`block_id`))",
1011+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`block_id` TEXT NOT NULL, `video_url` TEXT NOT NULL, `video_time` INTEGER, `duration` INTEGER, PRIMARY KEY(`block_id`))",
10121012
"fields": [
10131013
{
10141014
"fieldPath": "blockId",
@@ -1026,13 +1026,13 @@
10261026
"fieldPath": "videoTime",
10271027
"columnName": "video_time",
10281028
"affinity": "INTEGER",
1029-
"notNull": true
1029+
"notNull": false
10301030
},
10311031
{
10321032
"fieldPath": "duration",
10331033
"columnName": "duration",
10341034
"affinity": "INTEGER",
1035-
"notNull": true
1035+
"notNull": false
10361036
}
10371037
],
10381038
"primaryKey": {
@@ -1230,7 +1230,7 @@
12301230
"views": [],
12311231
"setupQueries": [
12321232
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
1233-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '488bd2b78e977fef626afb28014c80f2')"
1233+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7ea446decde04c9c16700cb3981703c2')"
12341234
]
12351235
}
12361236
}

core/src/main/java/org/openedx/core/data/model/room/VideoProgressEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ data class VideoProgressEntity(
1212
@ColumnInfo("video_url")
1313
val videoUrl: String,
1414
@ColumnInfo("video_time")
15-
val videoTime: Long,
15+
val videoTime: Long?,
1616
@ColumnInfo("duration")
17-
val duration: Long,
17+
val duration: Long?,
1818
)

course/src/main/java/org/openedx/course/data/repository/CourseRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class CourseRepository(
254254

255255
suspend fun getVideoProgress(blockId: String): VideoProgressEntity {
256256
return courseDao.getVideoProgressByBlockId(blockId)
257-
?: VideoProgressEntity(blockId, "", 0L, 0L)
257+
?: VideoProgressEntity(blockId, "", null, null)
258258
}
259259

260260
fun getCourseProgress(

course/src/main/java/org/openedx/course/presentation/home/CourseHomeUIState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sealed class CourseHomeUIState {
2222
val courseVideos: Map<String, List<Block>>,
2323
val courseAssignments: List<Block>,
2424
val videoPreview: VideoPreview?,
25-
val videoProgress: Float,
25+
val videoProgress: Float?,
2626
) : CourseHomeUIState()
2727

2828
data object Error : CourseHomeUIState()

course/src/main/java/org/openedx/course/presentation/home/CourseHomeViewModel.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.openedx.core.domain.model.CourseStructure
2626
import org.openedx.core.extension.getChapterBlocks
2727
import org.openedx.core.extension.getSequentialBlocks
2828
import org.openedx.core.extension.getVerticalBlocks
29+
import org.openedx.core.extension.safeDivBy
2930
import org.openedx.core.module.DownloadWorkerController
3031
import org.openedx.core.module.db.DownloadDao
3132
import org.openedx.core.module.download.BaseDownloadViewModel
@@ -233,9 +234,14 @@ class CourseHomeViewModel(
233234
val videoProgress = if (firstIncompleteVideo != null) {
234235
try {
235236
val videoProgressEntity = interactor.getVideoProgress(firstIncompleteVideo.id)
236-
val progress =
237-
videoProgressEntity.videoTime.toFloat() / videoProgressEntity.duration.toFloat()
238-
progress.coerceIn(0f, 1f)
237+
val videoTime = videoProgressEntity.videoTime?.toFloat()
238+
val videoDuration = videoProgressEntity.duration?.toFloat()
239+
val progress = if (videoTime != null && videoDuration != null) {
240+
videoTime.safeDivBy(videoDuration)
241+
} else {
242+
null
243+
}
244+
progress?.coerceIn(0f, 1f)
239245
} catch (_: Exception) {
240246
0f
241247
}

course/src/main/java/org/openedx/course/presentation/home/VideosHomePagerCardContent.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ fun VideosHomePagerCardContent(
5252
val completedVideos = allVideos.count { it.isCompleted() }
5353
val totalVideos = allVideos.size
5454
val firstIncompleteVideo = allVideos.find { !it.isCompleted() }
55+
val videoProgress = uiState.videoProgress ?: if (firstIncompleteVideo?.isCompleted() ?: false) {
56+
1f
57+
} else {
58+
0f
59+
}
5560

5661
Column(
5762
modifier = Modifier
@@ -139,7 +144,7 @@ fun VideosHomePagerCardContent(
139144
.height(180.dp),
140145
videoBlock = firstIncompleteVideo,
141146
preview = uiState.videoPreview,
142-
progress = uiState.videoProgress,
147+
progress = videoProgress,
143148
onClick = {
144149
onVideoClick(firstIncompleteVideo)
145150
},

course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ fun CourseVideoSection(
618618
block: Block,
619619
videoBlocks: List<Block>,
620620
preview: Map<String, VideoPreview?>,
621-
progress: Map<String, Float>,
621+
progress: Map<String, Float?>,
622622
downloadedStateMap: Map<String, DownloadedState>,
623623
onVideoClick: (Block) -> Unit,
624624
onDownloadClick: (blocksIds: List<String>) -> Unit,
@@ -632,6 +632,8 @@ fun CourseVideoSection(
632632
filteredStatuses.any { it.isWaitingOrDownloading } -> DownloadedState.DOWNLOADING
633633
else -> DownloadedState.NOT_DOWNLOADED
634634
}
635+
val videoCardWidth = 192.dp
636+
val rowHorizontalArrangement = 8.dp
635637

636638
LaunchedEffect(Unit) {
637639
try {
@@ -655,23 +657,29 @@ fun CourseVideoSection(
655657
)
656658
LazyRow(
657659
state = state,
658-
horizontalArrangement = Arrangement.spacedBy(8.dp),
660+
horizontalArrangement = Arrangement.spacedBy(rowHorizontalArrangement),
659661
contentPadding = PaddingValues(
660662
top = 8.dp,
661663
bottom = 16.dp,
662664
start = 16.dp,
663-
end = 16.dp,
665+
end = videoCardWidth + rowHorizontalArrangement,
664666
)
665667
) {
666668
items(videoBlocks) { block ->
669+
val localProgress = progress[block.id]
670+
val progress = localProgress ?: if (block.isCompleted()) {
671+
1f
672+
} else {
673+
0f
674+
}
667675
CourseVideoItem(
668676
modifier = Modifier
669-
.width(192.dp)
677+
.width(videoCardWidth)
670678
.height(108.dp)
671679
.clip(MaterialTheme.appShapes.videoPreviewShape),
672680
videoBlock = block,
673681
preview = preview[block.id],
674-
progress = progress[block.id] ?: 0f,
682+
progress = progress,
675683
onClick = {
676684
onVideoClick(block)
677685
}
@@ -758,12 +766,13 @@ fun CourseVideoItem(
758766
)
759767

760768
// Progress bar (bottom)
761-
if (progress > 0.0f) {
762-
Box(
763-
modifier = Modifier
764-
.align(Alignment.BottomCenter),
765-
contentAlignment = Alignment.Center
766-
) {
769+
Box(
770+
modifier = Modifier
771+
.fillMaxWidth()
772+
.align(Alignment.BottomCenter),
773+
contentAlignment = Alignment.Center
774+
) {
775+
if (progress > 0.0f) {
767776
LinearProgressIndicator(
768777
modifier = progressModifier
769778
.fillMaxWidth()
@@ -776,23 +785,23 @@ fun CourseVideoItem(
776785
},
777786
backgroundColor = MaterialTheme.appColors.progressBarBackgroundColor
778787
)
779-
if (videoBlock.isCompleted()) {
780-
Image(
781-
modifier = Modifier
782-
.align(Alignment.BottomEnd)
783-
.size(16.dp)
784-
.offset(x = 1.dp),
785-
painter = painterResource(id = coreR.drawable.ic_core_check),
786-
contentDescription = stringResource(R.string.course_accessibility_video_watched),
787-
)
788-
} else {
789-
Box(
790-
modifier = Modifier
791-
.align(Alignment.BottomEnd)
792-
.size(16.dp)
793-
.offset(x = 1.dp),
794-
)
795-
}
788+
}
789+
if (videoBlock.isCompleted()) {
790+
Image(
791+
modifier = Modifier
792+
.align(Alignment.BottomEnd)
793+
.size(16.dp)
794+
.offset(x = 1.dp),
795+
painter = painterResource(id = coreR.drawable.ic_core_check),
796+
contentDescription = stringResource(R.string.course_accessibility_video_watched),
797+
)
798+
} else {
799+
Box(
800+
modifier = Modifier
801+
.align(Alignment.BottomEnd)
802+
.size(16.dp)
803+
.offset(x = 1.dp),
804+
)
796805
}
797806
}
798807
}

course/src/main/java/org/openedx/course/presentation/videos/CourseContentVideoScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private fun CourseVideosUI(
182182
null
183183
},
184184
description = stringResource(
185-
R.string.course_completed,
185+
R.string.course_completed_of,
186186
progress.completed,
187187
progress.total
188188
)

course/src/main/java/org/openedx/course/presentation/videos/CourseVideoUIState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sealed class CourseVideoUIState {
1515
val downloadModelsSize: DownloadModelsSize,
1616
val isCompletedSectionsShown: Boolean,
1717
val videoPreview: Map<String, VideoPreview?>,
18-
val videoProgress: Map<String, Float>,
18+
val videoProgress: Map<String, Float?>,
1919
) : CourseVideoUIState()
2020

2121
data object Empty : CourseVideoUIState()

course/src/main/java/org/openedx/course/presentation/videos/CourseVideoViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,13 @@ class CourseVideoViewModel(
149149
initDownloadModelsStatus()
150150
val videoProgress = courseVideos.values.flatten().associate { block ->
151151
val videoProgressEntity = interactor.getVideoProgress(block.id)
152-
val progress = videoProgressEntity.videoTime.toFloat()
153-
.safeDivBy(videoProgressEntity.duration.toFloat())
152+
val videoTime = videoProgressEntity.videoTime?.toFloat()
153+
val videoDuration = videoProgressEntity.duration?.toFloat()
154+
val progress = if (videoTime != null && videoDuration != null) {
155+
videoTime.safeDivBy(videoDuration)
156+
} else {
157+
null
158+
}
154159
block.id to progress
155160
}
156161
val isCompletedSectionsShown =

0 commit comments

Comments
 (0)