Skip to content

Commit d448f57

Browse files
fix: changes according code review
1 parent e11db3c commit d448f57

File tree

22 files changed

+125
-219
lines changed

22 files changed

+125
-219
lines changed

app/src/main/java/org/openedx/app/MainFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import org.openedx.core.presentation.dialog.appupgrade.AppUpgradeDialogFragment
2626
import org.openedx.core.presentation.global.appupgrade.AppUpgradeRecommendedBox
2727
import org.openedx.core.presentation.global.appupgrade.UpgradeRequiredFragment
2828
import org.openedx.core.presentation.global.viewBinding
29-
import org.openedx.dates.presentation.dates.DatesFragment
3029
import org.openedx.core.system.notifier.app.AppUpgradeEvent
30+
import org.openedx.dates.presentation.dates.DatesFragment
3131
import org.openedx.discovery.presentation.DiscoveryRouter
3232
import org.openedx.downloads.presentation.download.DownloadsFragment
3333
import org.openedx.learn.presentation.LearnFragment
@@ -180,6 +180,7 @@ class MainFragment : Fragment(R.layout.fragment_main) {
180180
} else {
181181
R.id.fragmentLearn
182182
}
183+
183184
HomeTab.DATES.name -> R.id.fragmentDates
184185
HomeTab.PROFILE.name -> R.id.fragmentProfile
185186
else -> R.id.fragmentLearn

app/src/main/java/org/openedx/app/data/networking/HeadersInterceptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class HeadersInterceptor(
2525
addHeader("Accept", "application/json")
2626

2727
val httpAgent = System.getProperty("http.agent") ?: ""
28-
addHeader("User-Agent", "$httpAgent ${appData.versionName}")
28+
addHeader("User-Agent", "$httpAgent ${appData.appUserAgent}")
2929
}.build()
3030
)
3131
}

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
}

0 commit comments

Comments
 (0)