Skip to content

Commit 185a09a

Browse files
fix: changes according code review
1 parent a20f38b commit 185a09a

File tree

18 files changed

+120
-215
lines changed

18 files changed

+120
-215
lines changed

app/src/main/java/org/openedx/app/room/AppDatabase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import androidx.room.RoomDatabase
66
import androidx.room.TypeConverters
77
import org.openedx.core.data.model.room.CourseCalendarEventEntity
88
import org.openedx.core.data.model.room.CourseCalendarStateEntity
9-
import org.openedx.core.data.model.room.CourseDatesResponseEntity
9+
import org.openedx.core.data.model.room.CourseDateEntity
1010
import org.openedx.core.data.model.room.CourseEnrollmentDetailsEntity
1111
import org.openedx.core.data.model.room.CourseStructureEntity
1212
import org.openedx.core.data.model.room.DownloadCoursePreview
@@ -37,7 +37,7 @@ const val DATABASE_NAME = "OpenEdX_db"
3737
CourseCalendarStateEntity::class,
3838
DownloadCoursePreview::class,
3939
CourseEnrollmentDetailsEntity::class,
40-
CourseDatesResponseEntity::class,
40+
CourseDateEntity::class,
4141
],
4242
autoMigrations = [
4343
AutoMigration(1, DATABASE_VERSION)

app/src/main/res/drawable/app_ic_dates_selector.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<selector xmlns:android="http://schemas.android.com/apk/res/android">
33
<item android:drawable="@drawable/app_ic_dates_cloud_fill" android:state_checked="true" />
44
<item android:drawable="@drawable/app_ic_dates_cloud_outline" />
5-
</selector>
5+
</selector>

core/src/main/java/org/openedx/core/data/api/CourseApi.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ interface CourseApi {
6464
@GET("/api/course_home/v1/dates/{course_id}")
6565
suspend fun getCourseDates(
6666
@Path("course_id") courseId: String,
67-
@Query("mobile") mobile: Boolean = true,
6867
): CourseDates
6968

7069
@POST("/api/course_experience/v1/reset_course_deadlines")
@@ -118,5 +117,5 @@ interface CourseApi {
118117
): CourseDatesResponse
119118

120119
@POST("/api/course_experience/v1/reset_all_relative_course_deadlines/")
121-
suspend fun shiftDueDate()
120+
suspend fun shiftAllDueDates()
122121
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ data class CourseDatesResponse(
5050
count = count,
5151
next = next,
5252
previous = previous,
53-
results = results
54-
.mapNotNull { it.mapToDomain() }
55-
.sortedBy { it.dueDate }
53+
results = results.mapNotNull { it.mapToDomain() }
5654
)
5755
}
5856
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.openedx.core.data.model.room
2+
3+
import androidx.room.ColumnInfo
4+
import androidx.room.Entity
5+
import androidx.room.PrimaryKey
6+
import org.openedx.core.data.model.CourseDate
7+
import org.openedx.core.utils.TimeUtils
8+
import org.openedx.core.domain.model.CourseDate as DomainCourseDate
9+
10+
@Entity(tableName = "course_dates_table")
11+
data class CourseDateEntity(
12+
@PrimaryKey(autoGenerate = true)
13+
@ColumnInfo("id")
14+
val id: Int,
15+
@ColumnInfo("first_component_block_id")
16+
val firstComponentBlockId: String?,
17+
@ColumnInfo("course_id")
18+
val courseId: String,
19+
@ColumnInfo("due_date")
20+
val dueDate: String?,
21+
@ColumnInfo("assignment_title")
22+
val assignmentTitle: String?,
23+
@ColumnInfo("learner_has_access")
24+
val learnerHasAccess: Boolean?,
25+
@ColumnInfo("relative")
26+
val relative: Boolean?,
27+
@ColumnInfo("course_name")
28+
val courseName: String?,
29+
) {
30+
31+
fun mapToDomain(): DomainCourseDate? {
32+
val dueDate = TimeUtils.iso8601ToDate(dueDate ?: "")
33+
return DomainCourseDate(
34+
courseId = courseId,
35+
firstComponentBlockId = firstComponentBlockId ?: "",
36+
dueDate = dueDate ?: return null,
37+
assignmentTitle = assignmentTitle ?: "",
38+
learnerHasAccess = learnerHasAccess ?: false,
39+
relative = relative ?: false,
40+
courseName = courseName ?: ""
41+
)
42+
}
43+
44+
companion object {
45+
fun createFrom(courseDate: CourseDate): CourseDateEntity {
46+
with(courseDate) {
47+
return CourseDateEntity(
48+
id = 0,
49+
courseId = courseId,
50+
firstComponentBlockId = firstComponentBlockId,
51+
dueDate = dueDate,
52+
assignmentTitle = assignmentTitle,
53+
learnerHasAccess = learnerHasAccess,
54+
relative = relative,
55+
courseName = courseName
56+
)
57+
}
58+
}
59+
}
60+
}

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

Lines changed: 0 additions & 97 deletions
This file was deleted.

core/src/main/java/org/openedx/core/presentation/dates/DatesUI.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.openedx.core.ui.theme.appColors
3535
import org.openedx.core.ui.theme.appTypography
3636
import org.openedx.core.utils.TimeUtils.formatToString
3737
import org.openedx.core.utils.clearTime
38+
import org.openedx.core.utils.isToday
3839

3940
@Composable
4041
private fun CourseDateBlockSectionGeneric(
@@ -261,13 +262,15 @@ private fun CourseDateItem(
261262
if (isMiddleChild) {
262263
Spacer(modifier = Modifier.height(20.dp))
263264
}
264-
val timeTitle = formatToString(context, dateBlock.dueDate, useRelativeDates)
265-
Text(
266-
text = timeTitle,
267-
style = MaterialTheme.appTypography.labelMedium,
268-
color = MaterialTheme.appColors.textDark,
269-
maxLines = 1,
270-
)
265+
if (!dateBlock.dueDate.isToday()) {
266+
val timeTitle = formatToString(context, dateBlock.dueDate, useRelativeDates)
267+
Text(
268+
text = timeTitle,
269+
style = MaterialTheme.appTypography.labelMedium,
270+
color = MaterialTheme.appColors.textDark,
271+
maxLines = 1,
272+
)
273+
}
271274
Row(
272275
modifier = Modifier
273276
.fillMaxWidth()

course/src/main/java/org/openedx/course/data/storage/CourseConverter.kt

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,11 @@ package org.openedx.course.data.storage
33
import androidx.room.TypeConverter
44
import com.google.gson.Gson
55
import org.openedx.core.data.model.room.BlockDb
6-
import org.openedx.core.data.model.room.CourseDateDB
7-
import org.openedx.core.data.model.room.VideoInfoDb
86
import org.openedx.core.data.model.room.discovery.CourseDateBlockDb
97
import org.openedx.foundation.extension.genericType
108

119
class CourseConverter {
1210

13-
@TypeConverter
14-
fun fromVideoDb(value: VideoInfoDb?): String {
15-
if (value == null) return ""
16-
val json = Gson().toJson(value)
17-
return json.toString()
18-
}
19-
20-
@TypeConverter
21-
fun toVideoDb(value: String): VideoInfoDb? {
22-
if (value.isEmpty()) return null
23-
return Gson().fromJson(value, VideoInfoDb::class.java)
24-
}
25-
2611
@TypeConverter
2712
fun fromListOfString(value: List<String>): String {
2813
val json = Gson().toJson(value)
@@ -47,18 +32,6 @@ class CourseConverter {
4732
return Gson().fromJson(value, type)
4833
}
4934

50-
@TypeConverter
51-
fun fromStringToMap(value: String?): Map<String, String> {
52-
val mapType = genericType<HashMap<String, String>>()
53-
return Gson().fromJson(value, mapType)
54-
}
55-
56-
@TypeConverter
57-
fun fromMapToString(map: Map<String, String>): String {
58-
val gson = Gson()
59-
return gson.toJson(map)
60-
}
61-
6235
@TypeConverter
6336
fun fromListOfCourseDateBlockDb(value: List<CourseDateBlockDb>): String {
6437
val json = Gson().toJson(value)
@@ -70,16 +43,4 @@ class CourseConverter {
7043
val type = genericType<List<CourseDateBlockDb>>()
7144
return Gson().fromJson(value, type)
7245
}
73-
74-
@TypeConverter
75-
fun fromListOfCourseDateDB(value: List<CourseDateDB>): String {
76-
val json = Gson().toJson(value)
77-
return json.toString()
78-
}
79-
80-
@TypeConverter
81-
fun toListOfCourseDateDB(value: String): List<CourseDateDB> {
82-
val type = genericType<List<CourseDateDB>>()
83-
return Gson().fromJson(value, type)
84-
}
8546
}

dates/proguard-rules.pro

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
# Add project specific ProGuard rules here.
2-
# You can control the set of applied configuration files using the
3-
# proguardFiles setting in build.gradle.
4-
#
5-
# For more details, see
6-
# http://developer.android.com/guide/developing/tools/proguard.html
7-
8-
# If your project uses WebView with JS, uncomment the following
9-
# and specify the fully qualified class name to the JavaScript interface
10-
# class:
11-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12-
# public *;
13-
#}
14-
15-
# Uncomment this to preserve the line number information for
16-
# debugging stack traces.
17-
#-keepattributes SourceFile,LineNumberTable
18-
19-
# If you keep the line number information, uncomment this to
20-
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
1+
# Prevent shrinking, optimization, and obfuscation of the library when consumed by other modules.
2+
# This ensures that all classes and methods remain available for use by the consumer of the library.
3+
# Disabling these steps at the library level is important because the main app module will handle
4+
# shrinking, optimization, and obfuscation for the entire application, including this library.
5+
-dontshrink
6+
-dontoptimize
7+
-dontobfuscate
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.openedx.dates.data.repository
22

33
import org.openedx.core.data.api.CourseApi
4-
import org.openedx.core.data.model.room.CourseDatesResponseEntity
4+
import org.openedx.core.data.model.room.CourseDateEntity
55
import org.openedx.core.data.storage.CorePreferences
66
import org.openedx.core.domain.model.CourseDate
77
import org.openedx.core.domain.model.CourseDatesResponse
@@ -18,23 +18,21 @@ class DatesRepository(
1818
if (page == 1) {
1919
dao.clearCachedData()
2020
}
21-
dao.insertCourseDateResponses(CourseDatesResponseEntity.createFrom(response))
21+
dao.insertCourseDates(response.results.map { CourseDateEntity.createFrom(it) })
2222
return response.mapToDomain()
2323
}
2424

2525
suspend fun getUserDatesFromCache(): List<CourseDate> {
26-
return dao.getCourseDateResponses()
27-
.map { it.mapToDomain() }
28-
.map { it.results }
29-
.flatten()
30-
.sortedBy { it.dueDate }
26+
return dao.getCourseDates().mapNotNull { it.mapToDomain() }
3127
}
3228

33-
suspend fun preloadFirstPageCachedDates(): CourseDatesResponse? {
34-
return dao.getCourseDateResponses()
35-
.find { it.previous == null }
36-
?.mapToDomain()
29+
suspend fun preloadFirstPageCachedDates(): List<CourseDate> {
30+
return dao.getCourseDates(PAGE_SIZE).mapNotNull { it.mapToDomain() }
3731
}
3832

39-
suspend fun shiftDueDate() = api.shiftDueDate()
33+
suspend fun shiftAllDueDates() = api.shiftAllDueDates()
34+
35+
companion object {
36+
private const val PAGE_SIZE = 20
37+
}
4038
}

0 commit comments

Comments
 (0)