Skip to content

Commit 515a4d9

Browse files
feat: color coding, detekt fixes
1 parent 2939813 commit 515a4d9

File tree

31 files changed

+348
-88
lines changed

31 files changed

+348
-88
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ val screenModule = module {
542542
courseId = courseId,
543543
courseName = courseName,
544544
interactor = get(),
545-
courseRouter = get()
545+
courseRouter = get(),
546+
courseNotifier = get(),
547+
analytics = get()
546548
)
547549
}
548550
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.google.gson.annotations.SerializedName
44
import org.openedx.core.data.model.room.AssignmentProgressDb
55
import org.openedx.core.domain.model.AssignmentProgress
66

7+
private const val DEFAULT_LABEL_LENGTH = 5
8+
79
data class AssignmentProgress(
810
@SerializedName("assignment_type")
911
val assignmentType: String?,
@@ -18,7 +20,7 @@ data class AssignmentProgress(
1820
assignmentType = assignmentType ?: "",
1921
numPointsEarned = numPointsEarned ?: 0f,
2022
numPointsPossible = numPointsPossible ?: 0f,
21-
label = label ?: displayName.take(5)
23+
label = label ?: displayName.take(DEFAULT_LABEL_LENGTH)
2224
)
2325

2426
fun mapToRoomEntity() = AssignmentProgressDb(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ data class CourseProgressResponse(
157157
displayName = displayName ?: "",
158158
subsections = subsections?.map { it.mapToDomain() } ?: emptyList()
159159
)
160+
160161
data class Subsection(
161162
@SerializedName("assignment_type") val assignmentType: String?,
162163
@SerializedName("block_key") val blockKey: String?,
@@ -203,6 +204,7 @@ data class CourseProgressResponse(
203204
showGrades = showGrades ?: false,
204205
url = url ?: ""
205206
)
207+
206208
data class ProblemScore(
207209
@SerializedName("earned") val earned: Double?,
208210
@SerializedName("possible") val possible: Double?

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ data class GradingPolicyDb(
131131
Color(colorString.toColorInt())
132132
}
133133
)
134+
134135
data class AssignmentPolicyDb(
135136
@ColumnInfo("numDroppable")
136137
val numDroppable: Int,
@@ -163,6 +164,7 @@ data class SectionScoreDb(
163164
displayName = displayName,
164165
subsections = subsections.map { it.mapToDomain() }
165166
)
167+
166168
data class SubsectionDb(
167169
@ColumnInfo("assignmentType")
168170
val assignmentType: String,
@@ -206,6 +208,7 @@ data class SectionScoreDb(
206208
showGrades = showGrades,
207209
url = url
208210
)
211+
209212
data class ProblemScoreDb(
210213
@ColumnInfo("earned")
211214
val earned: Double,

core/src/main/java/org/openedx/core/data/storage/CourseDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ interface CourseDao {
4242
suspend fun getCourseEnrollmentDetailsById(id: String): CourseEnrollmentDetailsEntity?
4343

4444

45+
@Query("DELETE FROM course_progress_table")
46+
suspend fun clearCourseProgressData()
47+
4548
@Insert(onConflict = OnConflictStrategy.REPLACE)
4649
suspend fun insertVideoProgressEntity(vararg videoProgressEntity: VideoProgressEntity)
4750

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ data class AssignmentProgress(
1414
) : Parcelable {
1515

1616
@IgnoredOnParcel
17-
val value: Float = numPointsEarned.toFloat().safeDivBy(numPointsPossible.toFloat())
17+
val value: Float = numPointsEarned.safeDivBy(numPointsPossible)
18+
19+
override fun toString(): String {
20+
return "${numPointsEarned.toInt()}/${numPointsPossible.toInt()}"
21+
}
1822
}

core/src/main/java/org/openedx/core/module/download/BaseDownloadViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ abstract class BaseDownloadViewModel(
3434
private val _downloadModelsStatusFlow = MutableSharedFlow<HashMap<String, DownloadedState>>()
3535
protected val downloadModelsStatusFlow = _downloadModelsStatusFlow.asSharedFlow()
3636

37-
private var downloadingModelsList = listOf<DownloadModel>()
3837
private val _downloadingModelsFlow = MutableSharedFlow<List<DownloadModel>>()
3938
protected val downloadingModelsFlow = _downloadingModelsFlow.asSharedFlow()
4039

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,31 @@ object PreviewHelper {
1212

1313
private fun extractYouTubeVideoId(url: String): String {
1414
val regex = Regex(
15-
"^(?:https?://)?(?:www\\.)?(?:youtube\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)|.*[?&]v=)|youtu\\.be/)([^\"&?/\\s]{11})",
15+
"^(?:https?://)?(?:www\\.)?(?:youtube\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)|.*[?&]v=)|youtu\\.be/)" +
16+
"([^\"&?/\\s]{11})",
1617
RegexOption.IGNORE_CASE
1718
)
1819
val matchResult = regex.find(url)
1920
return matchResult?.groups?.get(1)?.value ?: ""
2021
}
2122

22-
2323
fun getVideoFrameBitmap(isOnline: Boolean, videoUrl: String): Bitmap? {
24+
if (!isOnline && !isLocalFile(videoUrl)) {
25+
return null
26+
}
27+
2428
val retriever = MediaMetadataRetriever()
25-
try {
26-
if (!isOnline && !isLocalFile(videoUrl)) return null
29+
return try {
2730
if (isLocalFile(videoUrl)) {
2831
retriever.setDataSource(videoUrl)
2932
} else {
3033
retriever.setDataSource(videoUrl, HashMap())
3134
}
32-
return retriever.getFrameAtTime(0)
35+
retriever.getFrameAtTime(0)
3336
} catch (e: Exception) {
3437
// Log the exception for debugging but don't crash
3538
e.printStackTrace()
36-
return null
39+
null
3740
} finally {
3841
try {
3942
retriever.release()
@@ -47,4 +50,4 @@ object PreviewHelper {
4750
private fun isLocalFile(url: String): Boolean {
4851
return url.startsWith("/") || url.startsWith("file://")
4952
}
50-
}
53+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ object TimeUtils {
7777
}
7878
}
7979
}
80+
fun formatToDueInString(context: Context, date: Date): String {
81+
val now = Calendar.getInstance()
82+
val dueDate = Calendar.getInstance().apply { time = date }
83+
now.set(Calendar.HOUR_OF_DAY, 0)
84+
now.set(Calendar.MINUTE, 0)
85+
now.set(Calendar.SECOND, 0)
86+
now.set(Calendar.MILLISECOND, 0)
87+
dueDate.set(Calendar.HOUR_OF_DAY, 0)
88+
dueDate.set(Calendar.MINUTE, 0)
89+
dueDate.set(Calendar.SECOND, 0)
90+
dueDate.set(Calendar.MILLISECOND, 0)
91+
val daysDifference =
92+
((dueDate.timeInMillis - now.timeInMillis) / (24 * 60 * 60 * 1000)).toInt()
93+
return when {
94+
daysDifference < 0 -> context.getString(R.string.core_date_type_past_due)
95+
daysDifference == 0 -> context.getString(R.string.core_date_type_today)
96+
else -> context.getString(R.string.core_date_format_due_in_days, daysDifference)
97+
}
98+
}
8099

81100
fun getCurrentTime(): Long {
82101
return Calendar.getInstance().timeInMillis

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@
8787
<string name="core_date_type_completed" tools:ignore="MissingTranslation">Completed</string>
8888
<string name="core_date_type_past_due" tools:ignore="MissingTranslation">Past Due</string>
8989
<string name="core_date_type_today" tools:ignore="MissingTranslation">Today</string>
90+
<string name="core_date_type_tomorrow" tools:ignore="MissingTranslation">Due Tomorrow</string>
9091
<string name="core_date_type_this_week" tools:ignore="MissingTranslation">This Week</string>
9192
<string name="core_date_type_next_week" tools:ignore="MissingTranslation">Next Week</string>
9293
<string name="core_date_type_upcoming" tools:ignore="MissingTranslation">Upcoming</string>
9394
<string name="core_date_type_none" tools:ignore="MissingTranslation">None</string>
9495
<string name="core_date_format_assignment_due" tools:ignore="MissingTranslation">Due %1$s</string>
96+
<string name="core_date_format_due_in_days" tools:ignore="MissingTranslation">Due in %1$d days</string>
9597
<plurals name="core_date_items_hidden" tools:ignore="MissingTranslation">
9698
<item quantity="one">%d Item Hidden</item>
9799
<item quantity="other">%d Items Hidden</item>

0 commit comments

Comments
 (0)