Skip to content

Commit eb64023

Browse files
feat: Course Home progress bar
1 parent ae777dd commit eb64023

File tree

13 files changed

+145
-14
lines changed

13 files changed

+145
-14
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName
44
import org.openedx.core.data.model.room.BlockDb
55
import org.openedx.core.data.model.room.CourseStructureEntity
66
import org.openedx.core.data.model.room.MediaDb
7+
import org.openedx.core.data.model.room.discovery.ProgressDb
78
import org.openedx.core.domain.model.CourseStructure
89
import org.openedx.core.utils.TimeUtils
910

@@ -35,7 +36,9 @@ data class CourseStructureModel(
3536
@SerializedName("certificate")
3637
val certificate: Certificate?,
3738
@SerializedName("is_self_paced")
38-
var isSelfPaced: Boolean?
39+
var isSelfPaced: Boolean?,
40+
@SerializedName("course_progress")
41+
val progress: Progress?,
3942
) {
4043
fun mapToDomain(): CourseStructure {
4144
return CourseStructure(
@@ -54,7 +57,8 @@ data class CourseStructureModel(
5457
coursewareAccess = coursewareAccess?.mapToDomain(),
5558
media = media?.mapToDomain(),
5659
certificate = certificate?.mapToDomain(),
57-
isSelfPaced = isSelfPaced ?: false
60+
isSelfPaced = isSelfPaced ?: false,
61+
progress = progress?.mapToDomain()
5862
)
5963
}
6064

@@ -73,7 +77,8 @@ data class CourseStructureModel(
7377
coursewareAccess = coursewareAccess?.mapToRoomEntity(),
7478
media = MediaDb.createFrom(media),
7579
certificate = certificate?.mapToRoomEntity(),
76-
isSelfPaced = isSelfPaced ?: false
80+
isSelfPaced = isSelfPaced ?: false,
81+
progress = progress?.mapToRoomEntity() ?: ProgressDb.DEFAULT_PROGRESS
7782
)
7883
}
7984
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.openedx.core.data.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
import org.openedx.core.data.model.room.discovery.ProgressDb
5+
6+
data class Progress(
7+
@SerializedName("assignments_completed")
8+
val assignmentsCompleted: Int?,
9+
@SerializedName("total_assignments_count")
10+
val totalAssignmentsCount: Int?
11+
) {
12+
fun mapToDomain(): org.openedx.core.domain.model.Progress {
13+
return org.openedx.core.domain.model.Progress(
14+
assignmentsCompleted = assignmentsCompleted ?: 0,
15+
totalAssignmentsCount = totalAssignmentsCount ?: 0
16+
)
17+
}
18+
19+
fun mapToRoomEntity() = ProgressDb(
20+
assignmentsCompleted = assignmentsCompleted ?: 0,
21+
totalAssignmentsCount = totalAssignmentsCount ?: 0
22+
)
23+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.room.Entity
66
import androidx.room.PrimaryKey
77
import org.openedx.core.data.model.room.discovery.CertificateDb
88
import org.openedx.core.data.model.room.discovery.CoursewareAccessDb
9+
import org.openedx.core.data.model.room.discovery.ProgressDb
910
import org.openedx.core.domain.model.CourseStructure
1011
import org.openedx.core.utils.TimeUtils
1112

@@ -39,7 +40,9 @@ data class CourseStructureEntity(
3940
@Embedded
4041
val certificate: CertificateDb?,
4142
@ColumnInfo("isSelfPaced")
42-
val isSelfPaced: Boolean
43+
val isSelfPaced: Boolean,
44+
@Embedded
45+
val progress: ProgressDb,
4346
) {
4447

4548
fun mapToDomain(): CourseStructure {
@@ -57,7 +60,8 @@ data class CourseStructureEntity(
5760
coursewareAccess?.mapToDomain(),
5861
media?.mapToDomain(),
5962
certificate?.mapToDomain(),
60-
isSelfPaced
63+
isSelfPaced,
64+
progress.mapToDomain()
6165
)
6266
}
6367

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import androidx.room.Embedded
55
import androidx.room.Entity
66
import androidx.room.PrimaryKey
77
import org.openedx.core.data.model.room.MediaDb
8-
import org.openedx.core.domain.model.*
8+
import org.openedx.core.domain.model.Certificate
9+
import org.openedx.core.domain.model.CourseSharingUtmParameters
10+
import org.openedx.core.domain.model.CoursewareAccess
11+
import org.openedx.core.domain.model.EnrolledCourse
12+
import org.openedx.core.domain.model.EnrolledCourseData
13+
import org.openedx.core.domain.model.Progress
914
import org.openedx.core.utils.TimeUtils
1015

1116
@Entity(tableName = "course_enrolled_table")
@@ -135,6 +140,19 @@ data class CoursewareAccessDb(
135140

136141
}
137142

143+
data class ProgressDb(
144+
@ColumnInfo("assignments_completed")
145+
val assignmentsCompleted: Int,
146+
@ColumnInfo("total_assignments_count")
147+
val totalAssignmentsCount: Int,
148+
) {
149+
companion object {
150+
val DEFAULT_PROGRESS = ProgressDb(0, 0)
151+
}
152+
153+
fun mapToDomain() = Progress(assignmentsCompleted, totalAssignmentsCount)
154+
}
155+
138156
data class CertificateDb(
139157
@ColumnInfo("certificateURL")
140158
val certificateURL: String?

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ data class CourseStructure(
1616
val coursewareAccess: CoursewareAccess?,
1717
val media: Media?,
1818
val certificate: Certificate?,
19-
val isSelfPaced: Boolean
19+
val isSelfPaced: Boolean,
20+
val progress: Progress?,
2021
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.openedx.core.domain.model
2+
3+
import android.os.Parcelable
4+
import kotlinx.parcelize.Parcelize
5+
6+
@Parcelize
7+
data class Progress(
8+
val assignmentsCompleted: Int,
9+
val totalAssignmentsCount: Int,
10+
) : Parcelable {
11+
fun getProgress(): Float = try {
12+
assignmentsCompleted.toFloat() / totalAssignmentsCount.toFloat()
13+
} catch (_: ArithmeticException) {
14+
0f
15+
}
16+
}

core/src/main/java/org/openedx/core/ui/theme/AppColors.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ data class AppColors(
5858
val courseHomeHeaderShade: Color,
5959
val courseHomeBackBtnBackground: Color,
6060

61-
val settingsTitleContent: Color
61+
val settingsTitleContent: Color,
62+
63+
val progressBarColor: Color,
64+
val progressBarBackgroundColor: Color
6265
) {
6366
val primary: Color get() = material.primary
6467
val primaryVariant: Color get() = material.primaryVariant

core/src/main/java/org/openedx/core/ui/theme/Theme.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ private val DarkColorPalette = AppColors(
7878
courseHomeHeaderShade = dark_course_home_header_shade,
7979
courseHomeBackBtnBackground = dark_course_home_back_btn_background,
8080

81-
settingsTitleContent = dark_settings_title_content
81+
settingsTitleContent = dark_settings_title_content,
82+
83+
progressBarColor = dark_progress_bar_color,
84+
progressBarBackgroundColor = dark_progress_bar_background_color
8285
)
8386

8487
private val LightColorPalette = AppColors(
@@ -149,7 +152,10 @@ private val LightColorPalette = AppColors(
149152
courseHomeHeaderShade = light_course_home_header_shade,
150153
courseHomeBackBtnBackground = light_course_home_back_btn_background,
151154

152-
settingsTitleContent = light_settings_title_content
155+
settingsTitleContent = light_settings_title_content,
156+
157+
progressBarColor = light_progress_bar_color,
158+
progressBarBackgroundColor = light_progress_bar_background_color
153159
)
154160

155161
val MaterialTheme.appColors: AppColors

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ val light_tab_selected_btn_content = Color.White
5656
val light_course_home_header_shade = Color(0xFFBABABA)
5757
val light_course_home_back_btn_background = Color.White
5858
val light_settings_title_content = Color.White
59+
val light_progress_bar_color = light_primary
60+
val light_progress_bar_background_color = Color(0xFF97A5BB)
5961

6062

61-
val dark_primary = Color(0xFF5478F9)
63+
val dark_primary = Color(0xFF3F68F8)
6264
val dark_primary_variant = Color(0xFF3700B3)
6365
val dark_secondary = Color(0xFF03DAC6)
6466
val dark_secondary_variant = Color(0xFF373E4F)
@@ -112,3 +114,5 @@ val dark_tab_selected_btn_content = Color.White
112114
val dark_course_home_header_shade = Color(0xFF999999)
113115
val dark_course_home_back_btn_background = Color.Black
114116
val dark_settings_title_content = Color.White
117+
val dark_progress_bar_color = light_primary
118+
val dark_progress_bar_background_color = Color(0xFF8E9BAE)

course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class CourseContainerViewModel(
168168
_showProgress.value = true
169169
viewModelScope.launch {
170170
try {
171-
val courseStructure = interactor.getCourseStructure(courseId)
171+
val courseStructure = interactor.getCourseStructure(courseId, true)
172172
courseName = courseStructure.name
173173
_organization = courseStructure.org
174174
_isSelfPaced = courseStructure.isSelfPaced

0 commit comments

Comments
 (0)