Skip to content

Commit 47a5ba0

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

File tree

21 files changed

+185
-120
lines changed

21 files changed

+185
-120
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: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ data class CourseProgress(
2828
val requiredGrade = gradingPolicy?.gradeRange?.values?.firstOrNull() ?: 0f
2929
val requiredGradePercent = (requiredGrade * 100f).toInt()
3030

31-
fun getEarnedAssignmentProblems(
32-
policy: GradingPolicy.AssignmentPolicy
33-
) = sectionScores
34-
.flatMap { section ->
35-
section.subsections.filter { it.assignmentType == policy.type }
36-
}.sumOf { subsection ->
37-
subsection.problemScores.sumOf { it.earned }
38-
}
39-
40-
fun getPossibleAssignmentProblems(
41-
policy: GradingPolicy.AssignmentPolicy
42-
) = sectionScores
43-
.flatMap { section ->
44-
section.subsections.filter { it.assignmentType == policy.type }
45-
}.sumOf { subsection ->
46-
subsection.problemScores.sumOf { it.possible }
47-
}
48-
4931
fun getAssignmentGradedPercent(type: String): Float {
5032
val assignmentSections = getAssignmentSections(type)
5133
if (assignmentSections.isEmpty()) return 0f
@@ -71,13 +53,24 @@ data class CourseProgress(
7153
}
7254

7355
fun getNotEmptyGradingPolicies() = gradingPolicy?.assignmentPolicies?.mapNotNull {
74-
if (getPossibleAssignmentProblems(it) > 0) {
56+
if (getAssignmentSections(it.type).isNotEmpty()) {
7557
it
7658
} else {
7759
null
7860
}
7961
}
8062

63+
fun getCompletedAssignmentCount(
64+
policy: GradingPolicy.AssignmentPolicy,
65+
courseStructure: CourseStructure? = null
66+
): Int {
67+
val assignments = getAssignmentSections(policy.type)
68+
return courseStructure?.blockData
69+
?.filter { it.id in assignments.map { assignment -> assignment.blockKey } }
70+
?.filter { it.isCompleted() }
71+
?.size ?: 0
72+
}
73+
8174
data class CertificateData(
8275
val certStatus: String,
8376
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: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.openedx.course.presentation.home
33
import android.content.res.Configuration.UI_MODE_NIGHT_NO
44
import android.content.res.Configuration.UI_MODE_NIGHT_YES
55
import androidx.compose.foundation.BorderStroke
6+
import androidx.compose.foundation.layout.Arrangement
67
import androidx.compose.foundation.layout.Box
78
import androidx.compose.foundation.layout.Column
89
import androidx.compose.foundation.layout.PaddingValues
@@ -41,6 +42,7 @@ import androidx.compose.ui.platform.AndroidUriHandler
4142
import androidx.compose.ui.platform.LocalContext
4243
import androidx.compose.ui.res.painterResource
4344
import androidx.compose.ui.res.stringResource
45+
import androidx.compose.ui.text.font.FontWeight
4446
import androidx.compose.ui.text.style.TextAlign
4547
import androidx.compose.ui.tooling.preview.Devices
4648
import androidx.compose.ui.tooling.preview.Preview
@@ -71,6 +73,7 @@ import org.openedx.foundation.presentation.UIMessage
7173
import org.openedx.foundation.presentation.WindowSize
7274
import org.openedx.foundation.presentation.WindowType
7375
import org.openedx.foundation.presentation.windowSizeValue
76+
import org.openedx.core.R as coreR
7477

7578
@Composable
7679
fun CourseHomeScreen(
@@ -414,14 +417,27 @@ fun CaughtUpMessage(
414417
modifier: Modifier = Modifier,
415418
message: String,
416419
) {
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-
)
420+
Column(
421+
modifier = Modifier.fillMaxWidth(),
422+
horizontalAlignment = Alignment.CenterHorizontally,
423+
verticalArrangement = Arrangement.spacedBy(8.dp)
424+
) {
425+
Icon(
426+
modifier = Modifier.size(48.dp),
427+
painter = painterResource(coreR.drawable.core_ic_check),
428+
contentDescription = null,
429+
tint = MaterialTheme.appColors.successGreen
430+
)
431+
Text(
432+
modifier = modifier
433+
.fillMaxWidth(),
434+
text = message,
435+
color = MaterialTheme.appColors.textPrimary,
436+
style = MaterialTheme.appTypography.bodyLarge,
437+
fontWeight = FontWeight.SemiBold,
438+
textAlign = TextAlign.Center
439+
)
440+
}
425441
}
426442

427443
@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)