Skip to content

Commit 2939813

Browse files
fix: connected data to assignment tab UI
1 parent 1ac85bd commit 2939813

File tree

15 files changed

+354
-99
lines changed

15 files changed

+354
-99
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.openedx.core.presentation.settings.video.VideoQualityViewModel
1818
import org.openedx.core.repository.CalendarRepository
1919
import org.openedx.course.data.repository.CourseRepository
2020
import org.openedx.course.domain.interactor.CourseInteractor
21+
import org.openedx.course.presentation.assignments.CourseAssignmentViewModel
2122
import org.openedx.course.presentation.container.CourseContainerViewModel
2223
import org.openedx.course.presentation.dates.CourseDatesViewModel
2324
import org.openedx.course.presentation.handouts.HandoutsViewModel
@@ -537,10 +538,11 @@ val screenModule = module {
537538
)
538539
}
539540
viewModel { (courseId: String, courseName: String) ->
540-
org.openedx.course.presentation.assignments.CourseAssignmentViewModel(
541+
CourseAssignmentViewModel(
541542
courseId = courseId,
542543
courseName = courseName,
543-
interactor = get()
544+
interactor = get(),
545+
courseRouter = get()
544546
)
545547
}
546548
}

core/src/main/java/org/openedx/core/NoContentScreenType.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ enum class NoContentScreenType(
1616
iconResId = R.drawable.core_ic_no_content,
1717
messageResId = R.string.core_no_dates
1818
),
19+
COURSE_ASSIGNMENT(
20+
iconResId = R.drawable.core_ic_no_content,
21+
messageResId = R.string.core_no_assignments
22+
),
1923
COURSE_DISCUSSIONS(
2024
iconResId = R.drawable.core_ic_no_content,
2125
messageResId = R.string.core_no_discussion

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ data class AssignmentProgress(
1111
val numPointsEarned: Float?,
1212
@SerializedName("num_points_possible")
1313
val numPointsPossible: Float?,
14+
@SerializedName("short_label")
1415
val label: String?
1516
) {
16-
fun mapToDomain() = AssignmentProgress(
17+
fun mapToDomain(displayName: String) = AssignmentProgress(
1718
assignmentType = assignmentType ?: "",
1819
numPointsEarned = numPointsEarned ?: 0f,
1920
numPointsPossible = numPointsPossible ?: 0f,
20-
label = label ?: ""
21+
label = label ?: displayName.take(5)
2122
)
2223

2324
fun mapToRoomEntity() = AssignmentProgressDb(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data class Block(
6565
blockCounts = blockCounts?.mapToDomain()!!,
6666
completion = completion ?: 0.0,
6767
containsGatedContent = containsGatedContent ?: false,
68-
assignmentProgress = assignmentProgress?.mapToDomain(),
68+
assignmentProgress = assignmentProgress?.mapToDomain(displayName.orEmpty()),
6969
due = TimeUtils.iso8601ToDate(due.orEmpty()),
7070
offlineDownload = offlineDownload?.mapToDomain()
7171
)

core/src/main/java/org/openedx/core/utils/PreviewHelper.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ object PreviewHelper {
3030
retriever.setDataSource(videoUrl, HashMap())
3131
}
3232
return retriever.getFrameAtTime(0)
33-
} catch (_: Exception) {
33+
} catch (e: Exception) {
34+
// Log the exception for debugging but don't crash
35+
e.printStackTrace()
3436
return null
3537
} finally {
36-
retriever.release()
38+
try {
39+
retriever.release()
40+
} catch (e: Exception) {
41+
// Ignore release exceptions
42+
e.printStackTrace()
43+
}
3744
}
3845
}
3946

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="18dp"
3+
android:height="18dp"
4+
android:viewportWidth="18"
5+
android:viewportHeight="18">
6+
<path
7+
android:pathData="M12,5H12.01"
8+
android:strokeLineJoin="round"
9+
android:strokeWidth="1.75"
10+
android:fillColor="#00000000"
11+
android:strokeColor="#3C68FF"
12+
android:strokeLineCap="round" />
13+
<path
14+
android:pathData="M1,4C1,3.204 1.316,2.441 1.879,1.879C2.441,1.316 3.204,1 4,1H14C14.796,1 15.559,1.316 16.121,1.879C16.684,2.441 17,3.204 17,4V14C17,14.796 16.684,15.559 16.121,16.121C15.559,16.684 14.796,17 14,17H4C3.204,17 2.441,16.684 1.879,16.121C1.316,15.559 1,14.796 1,14V4Z"
15+
android:strokeLineJoin="round"
16+
android:strokeWidth="1.75"
17+
android:fillColor="#00000000"
18+
android:strokeColor="#3C68FF"
19+
android:strokeLineCap="round" />
20+
<path
21+
android:pathData="M1,12L5,8C5.456,7.561 5.973,7.33 6.5,7.33C7.027,7.33 7.544,7.561 8,8L13,13"
22+
android:strokeLineJoin="round"
23+
android:strokeWidth="1.75"
24+
android:fillColor="#00000000"
25+
android:strokeColor="#3C68FF"
26+
android:strokeLineCap="round" />
27+
<path
28+
android:pathData="M11,11L12,10C12.456,9.561 12.973,9.33 13.5,9.33C14.027,9.33 14.544,9.561 15,10L17,12"
29+
android:strokeLineJoin="round"
30+
android:strokeWidth="1.75"
31+
android:fillColor="#00000000"
32+
android:strokeColor="#3C68FF"
33+
android:strokeLineCap="round" />
34+
</vector>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@
152152
<string name="core_message_calendar_out_of_date" tools:ignore="MissingTranslation">Your course dates have been shifted and your course calendar is no longer up to date with your new schedule.</string>
153153
<string name="core_label_update_now" tools:ignore="MissingTranslation">Update Now</string>
154154
<string name="core_label_remove_course_calendar" tools:ignore="MissingTranslation">Remove Course Calendar</string>
155-
156155
<!-- endregion -->
157156

158157
<string name="core_no_course_content">No course content is currently available.</string>
159158
<string name="core_no_videos">No videos available for this course.</string>
160159
<string name="core_no_dates">Course dates are currently not available.</string>
161160
<string name="core_no_progress">This course does not contain exams or graded assignments.</string>
161+
<string name="core_no_assignments">Course assignment are currently not available.</string>
162162
<string name="core_no_discussion">Unable to load discussions.\n Please try again later.</string>
163163
<string name="core_no_handouts">There are currently no handouts for this course.</string>
164164
<string name="core_no_announcements">There are currently no announcements for this course.</string>
@@ -213,7 +213,6 @@
213213
<string name="core_explore_other_parts_when_reconnect">Explore other parts of this course or view this when you reconnect.</string>
214214
<string name="core_not_downloaded">This component is not downloaded</string>
215215
<string name="core_explore_other_parts_when_reconnect_or_download">Explore other parts of this course or download this when you reconnect.</string>
216-
217216
<string name="core_authorization">Authorization</string>
218217
<string name="core_authorization_request">Please enter the system to continue with course enrollment.</string>
219218
</resources>

course/src/main/java/org/openedx/course/presentation/assignments/CourseAssignmentUIState.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sealed class CourseAssignmentUIState {
88
val groupedAssignments: Map<String, List<Block>>,
99
val progress: Progress
1010
) : CourseAssignmentUIState()
11-
12-
data object Error : CourseAssignmentUIState()
11+
data object Empty : CourseAssignmentUIState()
1312
data object Loading : CourseAssignmentUIState()
14-
}
13+
}

course/src/main/java/org/openedx/course/presentation/assignments/CourseAssignmentViewModel.kt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import androidx.lifecycle.viewModelScope
55
import kotlinx.coroutines.flow.MutableStateFlow
66
import kotlinx.coroutines.flow.StateFlow
77
import kotlinx.coroutines.flow.asStateFlow
8+
import kotlinx.coroutines.flow.catch
89
import kotlinx.coroutines.launch
910
import org.openedx.core.domain.model.CourseStructure
1011
import org.openedx.core.domain.model.Progress
1112
import org.openedx.course.domain.interactor.CourseInteractor
13+
import org.openedx.course.presentation.CourseRouter
1214

1315
class CourseAssignmentViewModel(
14-
private val courseId: String,
16+
val courseId: String,
17+
val courseRouter: CourseRouter,
1518
private val courseName: String,
16-
private val interactor: CourseInteractor
19+
private val interactor: CourseInteractor,
1720
) : ViewModel() {
1821
private val _uiState =
1922
MutableStateFlow<CourseAssignmentUIState>(CourseAssignmentUIState.Loading)
@@ -22,11 +25,14 @@ class CourseAssignmentViewModel(
2225
init {
2326
viewModelScope.launch {
2427
interactor.getCourseStructureFlow(courseId)
28+
.catch {
29+
_uiState.value = CourseAssignmentUIState.Empty
30+
}
2531
.collect { courseStructure ->
2632
if (courseStructure != null) {
2733
updateAssignments(courseStructure)
2834
} else {
29-
_uiState.value = CourseAssignmentUIState.Error
35+
_uiState.value = CourseAssignmentUIState.Empty
3036
}
3137
}
3238
}
@@ -35,13 +41,17 @@ class CourseAssignmentViewModel(
3541
private fun updateAssignments(courseStructure: CourseStructure) {
3642
val assignments = courseStructure.blockData
3743
.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-
)
44+
if (assignments.isEmpty()) {
45+
_uiState.value = CourseAssignmentUIState.Empty
46+
} else {
47+
val grouped = assignments.groupBy { it.assignmentProgress?.assignmentType ?: "" }
48+
val completed = assignments.count { it.isCompleted() }
49+
val total = assignments.size
50+
val progress = Progress(completed, total)
51+
_uiState.value = CourseAssignmentUIState.CourseData(
52+
groupedAssignments = grouped,
53+
progress = progress
54+
)
55+
}
4656
}
47-
}
57+
}

0 commit comments

Comments
 (0)