Skip to content

Commit 1ac85bd

Browse files
fix: assignment tab UI
1 parent f8c29fb commit 1ac85bd

File tree

15 files changed

+516
-15
lines changed

15 files changed

+516
-15
lines changed

app/src/main/java/org/openedx/app/di/ScreenModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,11 @@ val screenModule = module {
536536
router = get()
537537
)
538538
}
539+
viewModel { (courseId: String, courseName: String) ->
540+
org.openedx.course.presentation.assignments.CourseAssignmentViewModel(
541+
courseId = courseId,
542+
courseName = courseName,
543+
interactor = get()
544+
)
545+
}
539546
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ data class AssignmentProgress(
1111
val numPointsEarned: Float?,
1212
@SerializedName("num_points_possible")
1313
val numPointsPossible: Float?,
14+
val label: String?
1415
) {
1516
fun mapToDomain() = AssignmentProgress(
1617
assignmentType = assignmentType ?: "",
1718
numPointsEarned = numPointsEarned ?: 0f,
18-
numPointsPossible = numPointsPossible ?: 0f
19+
numPointsPossible = numPointsPossible ?: 0f,
20+
label = label ?: ""
1921
)
2022

2123
fun mapToRoomEntity() = AssignmentProgressDb(
2224
assignmentType = assignmentType,
2325
numPointsEarned = numPointsEarned,
24-
numPointsPossible = numPointsPossible
26+
numPointsPossible = numPointsPossible,
27+
label = label
2528
)
2629
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,13 @@ data class AssignmentProgressDb(
230230
val numPointsEarned: Float?,
231231
@ColumnInfo("num_points_possible")
232232
val numPointsPossible: Float?,
233+
val label: String?
233234
) {
234235
fun mapToDomain() = DomainAssignmentProgress(
235236
assignmentType = assignmentType ?: "",
236237
numPointsEarned = numPointsEarned ?: 0f,
237-
numPointsPossible = numPointsPossible ?: 0f
238+
numPointsPossible = numPointsPossible ?: 0f,
239+
label = label ?: ""
238240
)
239241
}
240242

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package org.openedx.core.domain.model
22

33
import android.os.Parcelable
4+
import kotlinx.parcelize.IgnoredOnParcel
45
import kotlinx.parcelize.Parcelize
6+
import org.openedx.core.extension.safeDivBy
57

68
@Parcelize
79
data class AssignmentProgress(
810
val assignmentType: String,
911
val numPointsEarned: Float,
10-
val numPointsPossible: Float
11-
) : Parcelable
12+
val numPointsPossible: Float,
13+
val label: String
14+
) : Parcelable {
15+
16+
@IgnoredOnParcel
17+
val value: Float = numPointsEarned.toFloat().safeDivBy(numPointsPossible.toFloat())
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="5dp"
3+
android:height="5dp"
4+
android:viewportWidth="5"
5+
android:viewportHeight="5">
6+
<path
7+
android:pathData="M2.067,0.75C2.2594,0.4167 2.7406,0.4167 2.933,0.75L4.6651,3.75C4.8575,4.0833 4.617,4.5 4.232,4.5H0.7679C0.383,4.5 0.1425,4.0833 0.3349,3.75L2.067,0.75Z"
8+
android:fillColor="#3C68FF" />
9+
</vector>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:viewportWidth="16"
5+
android:viewportHeight="16">
6+
<path
7+
android:pathData="M7,4h5v7h-5z"
8+
android:fillColor="#19212F" />
9+
<path
10+
android:strokeWidth="1"
11+
android:pathData="M8,0.5C3.875,0.5 0.5,3.875 0.5,8C0.5,12.125 3.875,15.5 8,15.5C12.125,15.5 15.5,12.125 15.5,8C15.5,3.875 12.125,0.5 8,0.5ZM10.663,10.85L7.602,8.967C7.378,8.833 7.242,8.592 7.242,8.33V4.813C7.25,4.505 7.505,4.25 7.813,4.25C8.12,4.25 8.375,4.505 8.375,4.813V8.15L11.255,9.882C11.525,10.047 11.615,10.4 11.45,10.67C11.285,10.932 10.932,11.015 10.663,10.85Z"
12+
android:fillColor="#FFC94D"
13+
android:strokeColor="#19212F" />
14+
</vector>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.openedx.course.presentation.assignments
2+
3+
import org.openedx.core.domain.model.Block
4+
import org.openedx.core.domain.model.Progress
5+
6+
sealed class CourseAssignmentUIState {
7+
data class CourseData(
8+
val groupedAssignments: Map<String, List<Block>>,
9+
val progress: Progress
10+
) : CourseAssignmentUIState()
11+
12+
data object Error : CourseAssignmentUIState()
13+
data object Loading : CourseAssignmentUIState()
14+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.openedx.course.presentation.assignments
2+
3+
import androidx.lifecycle.ViewModel
4+
import androidx.lifecycle.viewModelScope
5+
import kotlinx.coroutines.flow.MutableStateFlow
6+
import kotlinx.coroutines.flow.StateFlow
7+
import kotlinx.coroutines.flow.asStateFlow
8+
import kotlinx.coroutines.launch
9+
import org.openedx.core.domain.model.CourseStructure
10+
import org.openedx.core.domain.model.Progress
11+
import org.openedx.course.domain.interactor.CourseInteractor
12+
13+
class CourseAssignmentViewModel(
14+
private val courseId: String,
15+
private val courseName: String,
16+
private val interactor: CourseInteractor
17+
) : ViewModel() {
18+
private val _uiState =
19+
MutableStateFlow<CourseAssignmentUIState>(CourseAssignmentUIState.Loading)
20+
val uiState: StateFlow<CourseAssignmentUIState> = _uiState.asStateFlow()
21+
22+
init {
23+
viewModelScope.launch {
24+
interactor.getCourseStructureFlow(courseId)
25+
.collect { courseStructure ->
26+
if (courseStructure != null) {
27+
updateAssignments(courseStructure)
28+
} else {
29+
_uiState.value = CourseAssignmentUIState.Error
30+
}
31+
}
32+
}
33+
}
34+
35+
private fun updateAssignments(courseStructure: CourseStructure) {
36+
val assignments = courseStructure.blockData
37+
.filter { !it.assignmentProgress?.assignmentType.isNullOrEmpty() }
38+
val grouped = assignments.groupBy { it.assignmentProgress?.assignmentType ?: "" }
39+
val completed = assignments.count { it.isCompleted() }
40+
val total = assignments.size
41+
val progress = Progress(completed, total)
42+
_uiState.value = CourseAssignmentUIState.CourseData(
43+
groupedAssignments = grouped,
44+
progress = progress
45+
)
46+
}
47+
}

0 commit comments

Comments
 (0)