Skip to content

Commit a80ed4d

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

File tree

21 files changed

+178
-99
lines changed

21 files changed

+178
-99
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
)

core/src/main/java/org/openedx/core/domain/model/CourseProgress.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ data class CourseProgress(
7878
}
7979
}
8080

81+
fun getCompletedAssignmentCount(
82+
policy: GradingPolicy.AssignmentPolicy,
83+
courseStructure: CourseStructure? = null
84+
): Int {
85+
val assignments = getAssignmentSections(policy.type)
86+
return courseStructure?.blockData
87+
?.filter { it.id in assignments.map { assignment -> assignment.blockKey } }
88+
?.filter { it.isCompleted() }
89+
?.size ?: 0
90+
}
91+
8192
data class CertificateData(
8293
val certStatus: String,
8394
val certWebViewUrl: String,

core/src/openedx/org/openedx/core/ui/theme/Colors.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ val light_settings_title_content = Color.White
7575
val light_progress_bar_color = light_success_green
7676
val light_progress_bar_background_color = Color(0xFFCCD4E0)
7777
val light_grade_progress_bar_color = Color.Black
78-
val light_grade_progress_bar_background = light_background
78+
val light_grade_progress_bar_background = Color(0xFFCCD4E0)
7979
val light_assignment_card_border = Color(0xFFCCD4E0)
8080

8181
val dark_primary = Color(0xFF3F68F8)

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/AssignmentsHomePagerCardContent.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.compose.runtime.Composable
2525
import androidx.compose.ui.Alignment
2626
import androidx.compose.ui.Modifier
2727
import androidx.compose.ui.draw.clip
28+
import androidx.compose.ui.graphics.Color
2829
import androidx.compose.ui.res.stringResource
2930
import androidx.compose.ui.semantics.semantics
3031
import androidx.compose.ui.text.font.FontWeight
@@ -128,7 +129,8 @@ fun AssignmentsHomePagerCardContent(
128129
AssignmentCard(
129130
assignment = firstIncompleteAssignment,
130131
sectionName = getBlockParent(firstIncompleteAssignment.id)?.displayName ?: "",
131-
onAssignmentClick = onAssignmentClick
132+
onAssignmentClick = onAssignmentClick,
133+
background = MaterialTheme.appColors.background,
132134
)
133135
} else {
134136
CaughtUpMessage(
@@ -150,7 +152,8 @@ fun AssignmentsHomePagerCardContent(
150152
private fun AssignmentCard(
151153
assignment: Block,
152154
sectionName: String,
153-
onAssignmentClick: (Block) -> Unit
155+
onAssignmentClick: (Block) -> Unit,
156+
background: Color = MaterialTheme.appColors.surface
154157
) {
155158
val isDuePast = assignment.due != null && assignment.due!! < Date()
156159

@@ -199,7 +202,7 @@ private fun AssignmentCard(
199202
modifier = Modifier
200203
.fillMaxWidth()
201204
.clickable { onAssignmentClick(assignment) },
202-
backgroundColor = MaterialTheme.appColors.surface,
205+
backgroundColor = background,
203206
border = BorderStroke(1.dp, MaterialTheme.appColors.cardViewBorder),
204207
shape = RoundedCornerShape(8.dp),
205208
elevation = 0.dp

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ fun CourseCompletionHomePagerCardContent(
110110
downloadedStateMap = uiState.downloadedState,
111111
onSubSectionClick = onSubSectionClick,
112112
onDownloadClick = onDownloadClick,
113-
progress = progress
113+
progress = progress,
114+
background = MaterialTheme.appColors.background
114115
)
115116
}
116117

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import org.openedx.foundation.presentation.UIMessage
7171
import org.openedx.foundation.presentation.WindowSize
7272
import org.openedx.foundation.presentation.WindowType
7373
import org.openedx.foundation.presentation.windowSizeValue
74+
import org.openedx.core.R as coreR
7475

7576
@Composable
7677
fun CourseHomeScreen(
@@ -414,14 +415,25 @@ fun CaughtUpMessage(
414415
modifier: Modifier = Modifier,
415416
message: String,
416417
) {
417-
Text(
418-
modifier = modifier
419-
.fillMaxWidth(),
420-
text = message,
421-
color = MaterialTheme.appColors.textPrimary,
422-
style = MaterialTheme.appTypography.bodyLarge,
423-
textAlign = TextAlign.Center
424-
)
418+
Column(
419+
modifier = Modifier.fillMaxWidth(),
420+
horizontalAlignment = Alignment.CenterHorizontally,
421+
) {
422+
Icon(
423+
modifier = Modifier.size(48.dp),
424+
painter = painterResource(coreR.drawable.core_ic_check),
425+
contentDescription = null,
426+
tint = MaterialTheme.appColors.successGreen
427+
)
428+
Text(
429+
modifier = modifier
430+
.fillMaxWidth(),
431+
text = message,
432+
color = MaterialTheme.appColors.textPrimary,
433+
style = MaterialTheme.appTypography.bodyLarge,
434+
textAlign = TextAlign.Center
435+
)
436+
}
425437
}
426438

427439
@Preview(uiMode = UI_MODE_NIGHT_NO)

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
}

0 commit comments

Comments
 (0)