Skip to content

Commit aa832e2

Browse files
authored
feat: Course Dates Banner (#197)
Fixes: LEARNER-9730
1 parent 5e7cab0 commit aa832e2

File tree

22 files changed

+452
-109
lines changed

22 files changed

+452
-109
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,15 @@ val screenModule = module {
207207
get()
208208
)
209209
}
210-
viewModel { (courseId: String) -> CourseDatesViewModel(courseId, get(), get(), get()) }
210+
viewModel { (courseId: String, isSelfPaced: Boolean) ->
211+
CourseDatesViewModel(
212+
courseId,
213+
isSelfPaced,
214+
get(),
215+
get(),
216+
get()
217+
)
218+
}
211219
viewModel { (courseId: String, handoutsType: String) ->
212220
HandoutsViewModel(
213221
courseId,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ object ApiConstants {
2323
const val AUTH_TYPE_GOOGLE = "google-oauth2"
2424
const val AUTH_TYPE_FB = "facebook"
2525
const val AUTH_TYPE_MICROSOFT = "azuread-oauth2"
26+
27+
const val COURSE_KEY = "course_key"
2628
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ interface CourseApi {
6868
@GET("/api/course_home/v1/dates/{course_id}")
6969
suspend fun getCourseDates(@Path("course_id") courseId: String): CourseDates
7070

71+
@POST("/api/course_experience/v1/reset_course_deadlines")
72+
suspend fun resetCourseDates(@Body courseBody: Map<String, String>): ResetCourseDates
73+
7174
@GET("/api/mobile/v1/course_info/{course_id}/handouts")
7275
suspend fun getHandouts(@Path("course_id") courseId: String): HandoutsModel
7376

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.openedx.core.data.model
22

33
import com.google.gson.annotations.SerializedName
4+
import org.openedx.core.domain.model.CourseDatesBannerInfo
5+
import org.openedx.core.domain.model.CourseDatesResult
46
import org.openedx.core.domain.model.DatesSection
57
import org.openedx.core.utils.TimeUtils
68
import org.openedx.core.utils.addDays
@@ -10,22 +12,27 @@ import java.util.Date
1012
import org.openedx.core.domain.model.CourseDateBlock as DomainCourseDateBlock
1113

1214
data class CourseDates(
13-
@SerializedName("dates_banner_info")
14-
val datesBannerInfo: CourseDatesBannerInfo?,
1515
@SerializedName("course_date_blocks")
1616
val courseDateBlocks: List<CourseDateBlock>,
17-
@SerializedName("missed_deadlines")
18-
val missedDeadlines: Boolean = false,
19-
@SerializedName("missed_gated_content")
20-
val missedGatedContent: Boolean = false,
21-
@SerializedName("learner_is_full_access")
22-
val learnerIsFullAccess: Boolean = false,
23-
@SerializedName("user_timezone")
24-
val userTimezone: String? = "",
25-
@SerializedName("verified_upgrade_link")
26-
val verifiedUpgradeLink: String? = "",
17+
@SerializedName("dates_banner_info")
18+
val datesBannerInfo: DatesBannerInfo?,
19+
@SerializedName("has_ended")
20+
val hasEnded: Boolean,
2721
) {
28-
fun getStructuredCourseDates(): LinkedHashMap<DatesSection, List<DomainCourseDateBlock>> {
22+
fun getCourseDatesResult(): CourseDatesResult {
23+
return CourseDatesResult(
24+
datesSection = getStructuredCourseDates(),
25+
courseBanner = CourseDatesBannerInfo(
26+
missedDeadlines = datesBannerInfo?.missedDeadlines ?: false,
27+
missedGatedContent = datesBannerInfo?.missedGatedContent ?: false,
28+
verifiedUpgradeLink = datesBannerInfo?.verifiedUpgradeLink ?: "",
29+
contentTypeGatingEnabled = datesBannerInfo?.contentTypeGatingEnabled ?: false,
30+
hasEnded = hasEnded,
31+
)
32+
)
33+
}
34+
35+
private fun getStructuredCourseDates(): LinkedHashMap<DatesSection, List<DomainCourseDateBlock>> {
2936
val currentDate = Date()
3037
val courseDatesResponse: LinkedHashMap<DatesSection, List<DomainCourseDateBlock>> =
3138
LinkedHashMap()

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

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.openedx.core.data.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class DatesBannerInfo(
6+
@SerializedName("missed_deadlines")
7+
val missedDeadlines: Boolean = false,
8+
@SerializedName("missed_gated_content")
9+
val missedGatedContent: Boolean = false,
10+
@SerializedName("verified_upgrade_link")
11+
val verifiedUpgradeLink: String? = "",
12+
@SerializedName("content_type_gating_enabled")
13+
val contentTypeGatingEnabled: Boolean = false,
14+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.openedx.core.data.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
import org.openedx.core.domain.model.ResetCourseDates
5+
6+
data class ResetCourseDates(
7+
@SerializedName("message")
8+
val message: String = "",
9+
@SerializedName("body")
10+
val body: String = "",
11+
@SerializedName("header")
12+
val header: String = "",
13+
@SerializedName("link")
14+
val link: String = "",
15+
@SerializedName("link_text")
16+
val linkText: String = "",
17+
) {
18+
fun mapToDomain(): ResetCourseDates {
19+
return ResetCourseDates(
20+
message = message,
21+
body = body,
22+
header = header,
23+
link = link,
24+
linkText = linkText,
25+
)
26+
}
27+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.openedx.core.domain.model
2+
3+
import org.openedx.core.R
4+
import org.openedx.core.domain.model.CourseBannerType.BLANK
5+
import org.openedx.core.domain.model.CourseBannerType.INFO_BANNER
6+
import org.openedx.core.domain.model.CourseBannerType.RESET_DATES
7+
import org.openedx.core.domain.model.CourseBannerType.UPGRADE_TO_GRADED
8+
import org.openedx.core.domain.model.CourseBannerType.UPGRADE_TO_RESET
9+
10+
data class CourseDatesBannerInfo(
11+
private val missedDeadlines: Boolean,
12+
private val missedGatedContent: Boolean,
13+
private val verifiedUpgradeLink: String,
14+
private val contentTypeGatingEnabled: Boolean,
15+
private val hasEnded: Boolean
16+
) {
17+
val bannerType by lazy { getCourseBannerType() }
18+
19+
fun isBannerAvailableForUserType(isSelfPaced: Boolean): Boolean {
20+
if (hasEnded) return false
21+
22+
val selfPacedAvailable = isSelfPaced && bannerType != BLANK
23+
val instructorPacedAvailable = !isSelfPaced && bannerType == UPGRADE_TO_GRADED
24+
25+
return selfPacedAvailable || instructorPacedAvailable
26+
}
27+
28+
private fun getCourseBannerType(): CourseBannerType = when {
29+
canUpgradeToGraded() -> UPGRADE_TO_GRADED
30+
canUpgradeToReset() -> UPGRADE_TO_RESET
31+
canResetDates() -> RESET_DATES
32+
infoBanner() -> INFO_BANNER
33+
else -> BLANK
34+
}
35+
36+
private fun infoBanner(): Boolean = !missedDeadlines
37+
38+
private fun canUpgradeToGraded(): Boolean = contentTypeGatingEnabled && !missedDeadlines
39+
40+
private fun canUpgradeToReset(): Boolean =
41+
!canUpgradeToGraded() && missedDeadlines && missedGatedContent
42+
43+
private fun canResetDates(): Boolean =
44+
!canUpgradeToGraded() && missedDeadlines && !missedGatedContent
45+
}
46+
47+
enum class CourseBannerType(
48+
val headerResId: Int = 0,
49+
val bodyResId: Int = 0,
50+
val buttonResId: Int = 0
51+
) {
52+
BLANK,
53+
INFO_BANNER(bodyResId = R.string.core_dates_info_banner_body),
54+
UPGRADE_TO_GRADED(bodyResId = R.string.core_dates_upgrade_to_graded_banner_body),
55+
UPGRADE_TO_RESET(bodyResId = R.string.core_dates_upgrade_to_reset_banner_body),
56+
RESET_DATES(
57+
headerResId = R.string.core_dates_reset_dates_banner_header,
58+
bodyResId = R.string.core_dates_reset_dates_banner_body,
59+
buttonResId = R.string.core_dates_reset_dates_banner_button
60+
);
61+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.openedx.core.domain.model
2+
3+
data class CourseDatesResult(
4+
val datesSection: LinkedHashMap<DatesSection, List<CourseDateBlock>>,
5+
val courseBanner: CourseDatesBannerInfo,
6+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.openedx.core.domain.model
2+
3+
data class ResetCourseDates(
4+
val message: String,
5+
val body: String,
6+
val header: String,
7+
val link: String,
8+
val linkText: String,
9+
)

0 commit comments

Comments
 (0)