-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
452 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
core/src/main/java/org/openedx/core/data/model/CourseDatesBannerInfo.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
core/src/main/java/org/openedx/core/data/model/DatesBannerInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class DatesBannerInfo( | ||
@SerializedName("missed_deadlines") | ||
val missedDeadlines: Boolean = false, | ||
@SerializedName("missed_gated_content") | ||
val missedGatedContent: Boolean = false, | ||
@SerializedName("verified_upgrade_link") | ||
val verifiedUpgradeLink: String? = "", | ||
@SerializedName("content_type_gating_enabled") | ||
val contentTypeGatingEnabled: Boolean = false, | ||
) |
27 changes: 27 additions & 0 deletions
27
core/src/main/java/org/openedx/core/data/model/ResetCourseDates.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.ResetCourseDates | ||
|
||
data class ResetCourseDates( | ||
@SerializedName("message") | ||
val message: String = "", | ||
@SerializedName("body") | ||
val body: String = "", | ||
@SerializedName("header") | ||
val header: String = "", | ||
@SerializedName("link") | ||
val link: String = "", | ||
@SerializedName("link_text") | ||
val linkText: String = "", | ||
) { | ||
fun mapToDomain(): ResetCourseDates { | ||
return ResetCourseDates( | ||
message = message, | ||
body = body, | ||
header = header, | ||
link = link, | ||
linkText = linkText, | ||
) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
core/src/main/java/org/openedx/core/domain/model/CourseDatesBannerInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import org.openedx.core.R | ||
import org.openedx.core.domain.model.CourseBannerType.BLANK | ||
import org.openedx.core.domain.model.CourseBannerType.INFO_BANNER | ||
import org.openedx.core.domain.model.CourseBannerType.RESET_DATES | ||
import org.openedx.core.domain.model.CourseBannerType.UPGRADE_TO_GRADED | ||
import org.openedx.core.domain.model.CourseBannerType.UPGRADE_TO_RESET | ||
|
||
data class CourseDatesBannerInfo( | ||
private val missedDeadlines: Boolean, | ||
private val missedGatedContent: Boolean, | ||
private val verifiedUpgradeLink: String, | ||
private val contentTypeGatingEnabled: Boolean, | ||
private val hasEnded: Boolean | ||
) { | ||
val bannerType by lazy { getCourseBannerType() } | ||
|
||
fun isBannerAvailableForUserType(isSelfPaced: Boolean): Boolean { | ||
if (hasEnded) return false | ||
|
||
val selfPacedAvailable = isSelfPaced && bannerType != BLANK | ||
val instructorPacedAvailable = !isSelfPaced && bannerType == UPGRADE_TO_GRADED | ||
|
||
return selfPacedAvailable || instructorPacedAvailable | ||
} | ||
|
||
private fun getCourseBannerType(): CourseBannerType = when { | ||
canUpgradeToGraded() -> UPGRADE_TO_GRADED | ||
canUpgradeToReset() -> UPGRADE_TO_RESET | ||
canResetDates() -> RESET_DATES | ||
infoBanner() -> INFO_BANNER | ||
else -> BLANK | ||
} | ||
|
||
private fun infoBanner(): Boolean = !missedDeadlines | ||
|
||
private fun canUpgradeToGraded(): Boolean = contentTypeGatingEnabled && !missedDeadlines | ||
|
||
private fun canUpgradeToReset(): Boolean = | ||
!canUpgradeToGraded() && missedDeadlines && missedGatedContent | ||
|
||
private fun canResetDates(): Boolean = | ||
!canUpgradeToGraded() && missedDeadlines && !missedGatedContent | ||
} | ||
|
||
enum class CourseBannerType( | ||
val headerResId: Int = 0, | ||
val bodyResId: Int = 0, | ||
val buttonResId: Int = 0 | ||
) { | ||
BLANK, | ||
INFO_BANNER(bodyResId = R.string.core_dates_info_banner_body), | ||
UPGRADE_TO_GRADED(bodyResId = R.string.core_dates_upgrade_to_graded_banner_body), | ||
UPGRADE_TO_RESET(bodyResId = R.string.core_dates_upgrade_to_reset_banner_body), | ||
RESET_DATES( | ||
headerResId = R.string.core_dates_reset_dates_banner_header, | ||
bodyResId = R.string.core_dates_reset_dates_banner_body, | ||
buttonResId = R.string.core_dates_reset_dates_banner_button | ||
); | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/org/openedx/core/domain/model/CourseDatesResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.openedx.core.domain.model | ||
|
||
data class CourseDatesResult( | ||
val datesSection: LinkedHashMap<DatesSection, List<CourseDateBlock>>, | ||
val courseBanner: CourseDatesBannerInfo, | ||
) |
9 changes: 9 additions & 0 deletions
9
core/src/main/java/org/openedx/core/domain/model/ResetCourseDates.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.openedx.core.domain.model | ||
|
||
data class ResetCourseDates( | ||
val message: String, | ||
val body: String, | ||
val header: String, | ||
val link: String, | ||
val linkText: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.openedx.core.extension | ||
|
||
fun Int.nonZero(): Int? { | ||
return if (this != 0) this else null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.