Skip to content

Commit 8703fd2

Browse files
feat: color coding
1 parent da8c768 commit 8703fd2

File tree

7 files changed

+42
-42
lines changed

7 files changed

+42
-42
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 3,
5-
"identityHash": "d6028101c7598e8d1c5dedfcfc73d304",
5+
"identityHash": "bcf7a22441e12e4c8b6fb332754827bf",
66
"entities": [
77
{
88
"tableName": "course_discovery_table",
@@ -1008,7 +1008,7 @@
10081008
},
10091009
{
10101010
"tableName": "course_progress_table",
1011-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseId` TEXT NOT NULL, `verifiedMode` TEXT NOT NULL, `accessExpiration` TEXT NOT NULL, `creditCourseRequirements` TEXT NOT NULL, `end` TEXT NOT NULL, `enrollmentMode` TEXT NOT NULL, `hasScheduledContent` INTEGER NOT NULL, `sectionScores` TEXT NOT NULL, `studioUrl` TEXT NOT NULL, `username` TEXT NOT NULL, `userHasPassingGrade` INTEGER NOT NULL, `disableProgressGraph` INTEGER NOT NULL, `assignment_colors` TEXT, `certificate_certStatus` TEXT, `certificate_certWebViewUrl` TEXT, `certificate_downloadUrl` TEXT, `certificate_certificateAvailableDate` TEXT, `completion_completeCount` INTEGER, `completion_incompleteCount` INTEGER, `completion_lockedCount` INTEGER, `grade_letterGrade` TEXT, `grade_percent` REAL, `grade_isPassing` INTEGER, `grading_assignmentPolicies` TEXT, `grading_gradeRange` TEXT, `verification_link` TEXT, `verification_status` TEXT, `verification_statusDate` TEXT, PRIMARY KEY(`courseId`))",
1011+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`courseId` TEXT NOT NULL, `verifiedMode` TEXT NOT NULL, `accessExpiration` TEXT NOT NULL, `creditCourseRequirements` TEXT NOT NULL, `end` TEXT NOT NULL, `enrollmentMode` TEXT NOT NULL, `hasScheduledContent` INTEGER NOT NULL, `sectionScores` TEXT NOT NULL, `studioUrl` TEXT NOT NULL, `username` TEXT NOT NULL, `userHasPassingGrade` INTEGER NOT NULL, `disableProgressGraph` INTEGER NOT NULL, `certificate_certStatus` TEXT, `certificate_certWebViewUrl` TEXT, `certificate_downloadUrl` TEXT, `certificate_certificateAvailableDate` TEXT, `completion_completeCount` INTEGER, `completion_incompleteCount` INTEGER, `completion_lockedCount` INTEGER, `grade_letterGrade` TEXT, `grade_percent` REAL, `grade_isPassing` INTEGER, `grading_assignmentPolicies` TEXT, `grading_gradeRange` TEXT, `grading_assignmentColors` TEXT, `verification_link` TEXT, `verification_status` TEXT, `verification_statusDate` TEXT, PRIMARY KEY(`courseId`))",
10121012
"fields": [
10131013
{
10141014
"fieldPath": "courseId",
@@ -1082,12 +1082,6 @@
10821082
"affinity": "INTEGER",
10831083
"notNull": true
10841084
},
1085-
{
1086-
"fieldPath": "assignmentColors",
1087-
"columnName": "assignment_colors",
1088-
"affinity": "TEXT",
1089-
"notNull": false
1090-
},
10911085
{
10921086
"fieldPath": "certificateData.certStatus",
10931087
"columnName": "certificate_certStatus",
@@ -1160,6 +1154,12 @@
11601154
"affinity": "TEXT",
11611155
"notNull": false
11621156
},
1157+
{
1158+
"fieldPath": "gradingPolicy.assignmentColors",
1159+
"columnName": "grading_assignmentColors",
1160+
"affinity": "TEXT",
1161+
"notNull": false
1162+
},
11631163
{
11641164
"fieldPath": "verificationData.link",
11651165
"columnName": "verification_link",
@@ -1192,7 +1192,7 @@
11921192
"views": [],
11931193
"setupQueries": [
11941194
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
1195-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd6028101c7598e8d1c5dedfcfc73d304')"
1195+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bcf7a22441e12e4c8b6fb332754827bf')"
11961196
]
11971197
}
11981198
}

core/src/main/java/org/openedx/core/data/model/CourseProgressResponse.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ data class CourseProgressResponse(
2929
@SerializedName("user_has_passing_grade") val userHasPassingGrade: Boolean?,
3030
@SerializedName("verification_data") val verificationData: VerificationData?,
3131
@SerializedName("disable_progress_graph") val disableProgressGraph: Boolean?,
32-
@SerializedName("assignment_colors") val assignmentColors: List<String>?
3332
) {
3433
data class CertificateData(
3534
@SerializedName("cert_status") val certStatus: String?,
@@ -90,16 +89,21 @@ data class CourseProgressResponse(
9089

9190
data class GradingPolicy(
9291
@SerializedName("assignment_policies") val assignmentPolicies: List<AssignmentPolicy>?,
93-
@SerializedName("grade_range") val gradeRange: Map<String, Float>?
92+
@SerializedName("grade_range") val gradeRange: Map<String, Float>?,
93+
@SerializedName("assignment_colors") val assignmentColors: List<String>?
9494
) {
9595
fun mapToRoomEntity() = GradingPolicyDb(
9696
assignmentPolicies = assignmentPolicies?.map { it.mapToRoomEntity() } ?: emptyList(),
97-
gradeRange = gradeRange ?: emptyMap()
97+
gradeRange = gradeRange ?: emptyMap(),
98+
assignmentColors = assignmentColors ?: emptyList()
9899
)
99100

100101
fun mapToDomain() = CourseProgress.GradingPolicy(
101102
assignmentPolicies = assignmentPolicies?.map { it.mapToDomain() } ?: emptyList(),
102-
gradeRange = gradeRange ?: emptyMap()
103+
gradeRange = gradeRange ?: emptyMap(),
104+
assignmentColors = assignmentColors?.map { colorString ->
105+
Color(colorString.toColorInt())
106+
} ?: emptyList()
103107
)
104108
data class AssignmentPolicy(
105109
@SerializedName("num_droppable") val numDroppable: Int?,
@@ -238,9 +242,6 @@ data class CourseProgressResponse(
238242
userHasPassingGrade = userHasPassingGrade ?: false,
239243
verificationData = verificationData?.mapToDomain(),
240244
disableProgressGraph = disableProgressGraph ?: false,
241-
assignmentColors = assignmentColors?.map { colorString ->
242-
Color(colorString.toColorInt())
243-
} ?: listOf()
244245
)
245246
}
246247

@@ -263,7 +264,6 @@ data class CourseProgressResponse(
263264
userHasPassingGrade = userHasPassingGrade ?: false,
264265
verificationData = verificationData?.mapToRoomEntity(),
265266
disableProgressGraph = disableProgressGraph ?: false,
266-
assignmentColors = assignmentColors,
267267
)
268268
}
269269
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ data class CourseProgressEntity(
4545
val verificationData: VerificationDataDb?,
4646
@ColumnInfo("disableProgressGraph")
4747
val disableProgressGraph: Boolean,
48-
@ColumnInfo("assignment_colors")
49-
val assignmentColors: List<String>?
5048
) {
5149
fun mapToDomain(): CourseProgress {
5250
return CourseProgress(
@@ -66,9 +64,6 @@ data class CourseProgressEntity(
6664
userHasPassingGrade = userHasPassingGrade,
6765
verificationData = verificationData?.mapToDomain(),
6866
disableProgressGraph = disableProgressGraph,
69-
assignmentColors = assignmentColors?.map { colorString ->
70-
Color(colorString.toColorInt())
71-
} ?: listOf()
7267
)
7368
}
7469
}
@@ -125,11 +120,16 @@ data class GradingPolicyDb(
125120
@ColumnInfo("assignmentPolicies")
126121
val assignmentPolicies: List<AssignmentPolicyDb>,
127122
@ColumnInfo("gradeRange")
128-
val gradeRange: Map<String, Float>
123+
val gradeRange: Map<String, Float>,
124+
@ColumnInfo("assignmentColors")
125+
val assignmentColors: List<String>
129126
) {
130127
fun mapToDomain() = CourseProgress.GradingPolicy(
131128
assignmentPolicies = assignmentPolicies.map { it.mapToDomain() },
132-
gradeRange = gradeRange
129+
gradeRange = gradeRange,
130+
assignmentColors = assignmentColors.map { colorString ->
131+
Color(colorString.toColorInt())
132+
}
133133
)
134134
data class AssignmentPolicyDb(
135135
@ColumnInfo("numDroppable")

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.compose.ui.graphics.Color
55
data class CourseProgress(
66
val verifiedMode: String,
77
val accessExpiration: String,
8-
val assignmentColors: List<Color>,
98
val certificateData: CertificateData?,
109
val completionSummary: CompletionSummary?,
1110
val courseGrade: CourseGrade?,
@@ -47,13 +46,15 @@ data class CourseProgress(
4746
subsection.problemScores.sumOf { it.possible }
4847
}
4948

50-
fun getAssignmentGradedPercent(type: String) = sectionScores
51-
.flatMap { it.subsections }
52-
.filter { it.assignmentType == type }
53-
.sumOf { it.percentGraded }
49+
fun getAssignmentGradedPercent(type: String): Float {
50+
val assignmentSections = sectionScores
51+
.flatMap { it.subsections }
52+
.filter { it.assignmentType == type }
53+
return assignmentSections.sumOf { it.percentGraded }.toFloat() / assignmentSections.size
54+
}
5455

5556
fun getAssignmentWeightedGradedPercent(assignmentPolicy: GradingPolicy.AssignmentPolicy): Float {
56-
return (assignmentPolicy.weight * getAssignmentGradedPercent(assignmentPolicy.type) * 100.0).toFloat()
57+
return (assignmentPolicy.weight * getAssignmentGradedPercent(assignmentPolicy.type) * 100f).toFloat()
5758
}
5859

5960
fun getTotalWeightPercent() =
@@ -87,7 +88,8 @@ data class CourseProgress(
8788

8889
data class GradingPolicy(
8990
val assignmentPolicies: List<AssignmentPolicy>,
90-
val gradeRange: Map<String, Float>
91+
val gradeRange: Map<String, Float>,
92+
val assignmentColors: List<Color>,
9193
) {
9294
data class AssignmentPolicy(
9395
val numDroppable: Int,

course/src/main/java/org/openedx/course/presentation/progress/CourseProgressScreen.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ import org.openedx.foundation.presentation.UIMessage
6767
import org.openedx.foundation.presentation.WindowSize
6868
import org.openedx.foundation.presentation.windowSizeValue
6969

70-
const val EMPTY_STATE_VIEW_HEIGHT = 0.4f
71-
7270
@Composable
7371
fun CourseProgressScreen(
7472
windowSize: WindowSize,
@@ -149,8 +147,8 @@ private fun CourseProgressContent(
149147
AssignmentTypeRow(
150148
progress = uiState.progress,
151149
policy = policy,
152-
color = if (uiState.progress.assignmentColors.isNotEmpty()) {
153-
uiState.progress.assignmentColors[index % uiState.progress.assignmentColors.size]
150+
color = if (gradingPolicy.assignmentColors.isNotEmpty()) {
151+
gradingPolicy.assignmentColors[index % gradingPolicy.assignmentColors.size]
154152
} else {
155153
MaterialTheme.appColors.primary
156154
}
@@ -170,8 +168,8 @@ private fun CourseProgressContent(
170168
item {
171169
Box(
172170
modifier = Modifier
173-
.fillParentMaxHeight(EMPTY_STATE_VIEW_HEIGHT)
174-
.fillMaxWidth(),
171+
.fillMaxSize()
172+
.padding(top = 60.dp),
175173
contentAlignment = Alignment.Center
176174
) {
177175
NoGradesView()
@@ -317,7 +315,7 @@ private fun OverallGradeView(
317315
)
318316
) {
319317
gradingPolicy.assignmentPolicies.forEach { assignmentPolicy ->
320-
val assignmentColors = progress.assignmentColors
318+
val assignmentColors = gradingPolicy.assignmentColors
321319
val color = if (assignmentColors.isNotEmpty()) {
322320
assignmentColors[
323321
gradingPolicy.assignmentPolicies.indexOf(
@@ -394,7 +392,7 @@ private fun OverallGradeView(
394392
Text(
395393
text = stringResource(
396394
R.string.course_progress_required_grade_percent,
397-
progress.requiredGradePercent
395+
progress.requiredGradePercent.toString()
398396
),
399397
style = MaterialTheme.appTypography.labelLarge,
400398
color = MaterialTheme.appColors.textDark,

course/src/main/java/org/openedx/course/presentation/progress/CourseProgressViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import kotlinx.coroutines.flow.asStateFlow
1111
import kotlinx.coroutines.flow.catch
1212
import kotlinx.coroutines.flow.collectLatest
1313
import kotlinx.coroutines.launch
14-
import org.openedx.core.system.notifier.CourseCompletionSet
1514
import org.openedx.core.system.notifier.CourseLoading
1615
import org.openedx.core.system.notifier.CourseNotifier
16+
import org.openedx.core.system.notifier.CourseStructureUpdated
1717
import org.openedx.core.system.notifier.RefreshProgress
1818
import org.openedx.course.domain.interactor.CourseInteractor
1919
import org.openedx.foundation.presentation.BaseViewModel
@@ -64,7 +64,7 @@ class CourseProgressViewModel(
6464
viewModelScope.launch {
6565
courseNotifier.notifier.collect { event ->
6666
when (event) {
67-
is RefreshProgress, is CourseCompletionSet -> loadCourseProgress(true)
67+
is RefreshProgress, is CourseStructureUpdated -> loadCourseProgress(true)
6868
}
6969
}
7070
}

course/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<string name="course_progress_overall_title">Overall Grade</string>
4242
<string name="course_progress_overall_description">This represents your weighted grade against the grade needed to pass this course.</string>
4343
<string name="course_progress_current_overall">Current Overall Weighted Grade:</string>
44-
<string name="course_progress_required_grade_percent">A weighted grade of %1$d%% is required to pass this course</string>
44+
<string name="course_progress_required_grade_percent">A weighted grade of %1$s%% is required to pass this course</string>
4545
<string name="course_progress_grade_details">Grade Details</string>
4646
<string name="course_progress_assignment_type">Assignment Type</string>
4747
<string name="course_progress_current_max">Current / Max %</string>

0 commit comments

Comments
 (0)