-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Course dates support. - Add test cases for Course dates ViewModel. Not included in this PR: - Calendar integration - PLS (shift due dates) banner - Linking of items on the dates page to specific assessments within the app. fixes: LEARNER-9664
- Loading branch information
1 parent
a6fd21c
commit 5e6666f
Showing
28 changed files
with
1,409 additions
and
42 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
28 changes: 28 additions & 0 deletions
28
core/src/main/java/org/openedx/core/data/model/CourseDateBlock.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,28 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.util.* | ||
|
||
data class CourseDateBlock( | ||
@SerializedName("complete") | ||
val complete: Boolean = false, | ||
@SerializedName("date") | ||
val date: String = "", // ISO 8601 compliant format | ||
@SerializedName("assignment_type") | ||
val assignmentType: String? = "", | ||
@SerializedName("date_type") | ||
val dateType: DateType = DateType.NONE, | ||
@SerializedName("description") | ||
val description: String = "", | ||
@SerializedName("learner_has_access") | ||
val learnerHasAccess: Boolean = false, | ||
@SerializedName("link") | ||
val link: String = "", | ||
@SerializedName("link_text") | ||
val linkText: String = "", | ||
@SerializedName("title") | ||
val title: String = "", | ||
// component blockId in-case of navigating inside the app for component available in mobile | ||
@SerializedName("first_component_block_id") | ||
val blockId: String = "", | ||
) |
163 changes: 163 additions & 0 deletions
163
core/src/main/java/org/openedx/core/data/model/CourseDates.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,163 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.presentation.course.CourseDatesBadge | ||
import org.openedx.core.utils.TimeUtils | ||
import java.util.Date | ||
import org.openedx.core.domain.model.CourseDateBlock as DomainCourseDateBlock | ||
|
||
data class CourseDates( | ||
@SerializedName("dates_banner_info") | ||
val datesBannerInfo: CourseDatesBannerInfo?, | ||
@SerializedName("course_date_blocks") | ||
val courseDateBlocks: List<CourseDateBlock>, | ||
@SerializedName("missed_deadlines") | ||
val missedDeadlines: Boolean = false, | ||
@SerializedName("missed_gated_content") | ||
val missedGatedContent: Boolean = false, | ||
@SerializedName("learner_is_full_access") | ||
val learnerIsFullAccess: Boolean = false, | ||
@SerializedName("user_timezone") | ||
val userTimezone: String? = "", | ||
@SerializedName("verified_upgrade_link") | ||
val verifiedUpgradeLink: String? = "", | ||
) { | ||
fun mapToDomain(): LinkedHashMap<String, ArrayList<DomainCourseDateBlock>> { | ||
var courseDatesDomain = organiseCourseDatesInBlock() | ||
if (isContainToday().not()) { | ||
// Adding today's date block manually if not present in the date | ||
val todayBlock = DomainCourseDateBlock.getTodayDateBlock() | ||
courseDatesDomain[TimeUtils.formatDate(TimeUtils.FORMAT_DATE, todayBlock.date)] = | ||
arrayListOf(todayBlock) | ||
} | ||
// Sort the map entries date keys wise | ||
courseDatesDomain = LinkedHashMap(courseDatesDomain.toSortedMap(compareBy { | ||
TimeUtils.stringToDate(TimeUtils.FORMAT_DATE, it) | ||
})) | ||
reviseDateBlockBadge(courseDatesDomain) | ||
return courseDatesDomain | ||
} | ||
|
||
/** | ||
* Map the date blocks according to dates and stack all the blocks of same date against one key | ||
*/ | ||
private fun organiseCourseDatesInBlock(): LinkedHashMap<String, ArrayList<DomainCourseDateBlock>> { | ||
val courseDates = | ||
LinkedHashMap<String, ArrayList<DomainCourseDateBlock>>() | ||
courseDateBlocks.forEach { item -> | ||
val key = | ||
TimeUtils.formatDate(TimeUtils.FORMAT_DATE, TimeUtils.iso8601ToDate(item.date)) | ||
val dateBlock = DomainCourseDateBlock( | ||
title = item.title, | ||
description = item.description, | ||
link = item.link, | ||
blockId = item.blockId, | ||
date = TimeUtils.iso8601ToDate(item.date), | ||
complete = item.complete, | ||
learnerHasAccess = item.learnerHasAccess, | ||
dateType = item.dateType, | ||
dateBlockBadge = CourseDatesBadge.BLANK | ||
) | ||
if (courseDates.containsKey(key)) { | ||
(courseDates[key] as ArrayList).add(dateBlock) | ||
} else { | ||
courseDates[key] = arrayListOf(dateBlock) | ||
} | ||
} | ||
return courseDates | ||
} | ||
|
||
/** | ||
* Utility method to check that list contains today's date block or not. | ||
*/ | ||
private fun isContainToday(): Boolean { | ||
val today = Date() | ||
return courseDateBlocks.any { blockDate -> | ||
TimeUtils.iso8601ToDate(blockDate.date) == today | ||
} | ||
} | ||
|
||
/** | ||
* Set the Date Block Badge based on the date block data | ||
*/ | ||
private fun reviseDateBlockBadge(courseDatesDomain: LinkedHashMap<String, ArrayList<DomainCourseDateBlock>>) { | ||
var dueNextCount = 0 | ||
courseDatesDomain.keys.forEach { key -> | ||
courseDatesDomain[key]?.forEach { item -> | ||
var dateBlockTag: CourseDatesBadge = getDateTypeBadge(item) | ||
//Setting Due Next only for first occurrence | ||
if (dateBlockTag == CourseDatesBadge.DUE_NEXT) { | ||
if (dueNextCount == 0) | ||
dueNextCount += 1 | ||
else | ||
dateBlockTag = CourseDatesBadge.BLANK | ||
} | ||
item.dateBlockBadge = dateBlockTag | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Return Pill/Badge type of date block based on data | ||
*/ | ||
private fun getDateTypeBadge(item: DomainCourseDateBlock): CourseDatesBadge { | ||
val dateBlockTag: CourseDatesBadge | ||
val currentDate = Date() | ||
val componentDate: Date = item.date ?: return CourseDatesBadge.BLANK | ||
when (item.dateType) { | ||
DateType.TODAY_DATE -> { | ||
dateBlockTag = CourseDatesBadge.TODAY | ||
} | ||
|
||
DateType.COURSE_START_DATE, | ||
DateType.COURSE_END_DATE -> { | ||
dateBlockTag = CourseDatesBadge.BLANK | ||
} | ||
|
||
DateType.ASSIGNMENT_DUE_DATE -> { | ||
when { | ||
item.complete -> { | ||
dateBlockTag = CourseDatesBadge.COMPLETED | ||
} | ||
|
||
item.learnerHasAccess -> { | ||
dateBlockTag = when { | ||
item.link.isEmpty() -> { | ||
CourseDatesBadge.NOT_YET_RELEASED | ||
} | ||
|
||
TimeUtils.isDueDate(currentDate, componentDate) -> { | ||
CourseDatesBadge.DUE_NEXT | ||
} | ||
|
||
TimeUtils.isDatePassed(currentDate, componentDate) -> { | ||
CourseDatesBadge.PAST_DUE | ||
} | ||
|
||
else -> { | ||
CourseDatesBadge.BLANK | ||
} | ||
} | ||
} | ||
|
||
else -> { | ||
dateBlockTag = CourseDatesBadge.VERIFIED_ONLY | ||
} | ||
} | ||
} | ||
|
||
DateType.COURSE_EXPIRED_DATE -> { | ||
dateBlockTag = CourseDatesBadge.COURSE_EXPIRED_DATE | ||
} | ||
|
||
else -> { | ||
// dateBlockTag is BLANK for all other cases | ||
// DateTypes.CERTIFICATE_AVAILABLE_DATE, | ||
// DateTypes.VERIFIED_UPGRADE_DEADLINE, | ||
// DateTypes.VERIFICATION_DEADLINE_DATE | ||
dateBlockTag = CourseDatesBadge.BLANK | ||
} | ||
} | ||
return dateBlockTag | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/openedx/core/data/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,36 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CourseDatesBannerInfo( | ||
@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, | ||
) { | ||
fun getCourseBannerType(): CourseBannerType = when { | ||
upgradeToGraded() -> CourseBannerType.UPGRADE_TO_GRADED | ||
upgradeToReset() -> CourseBannerType.UPGRADE_TO_RESET | ||
resetDates() -> CourseBannerType.RESET_DATES | ||
showBannerInfo() -> CourseBannerType.INFO_BANNER | ||
else -> CourseBannerType.BLANK | ||
} | ||
|
||
private fun showBannerInfo(): Boolean = missedDeadlines.not() | ||
|
||
private fun upgradeToGraded(): Boolean = contentTypeGatingEnabled && missedDeadlines.not() | ||
|
||
private fun upgradeToReset(): Boolean = | ||
upgradeToGraded().not() && missedDeadlines && missedGatedContent | ||
|
||
private fun resetDates(): Boolean = | ||
upgradeToGraded().not() && missedDeadlines && missedGatedContent.not() | ||
} | ||
|
||
enum class CourseBannerType { | ||
BLANK, INFO_BANNER, UPGRADE_TO_GRADED, UPGRADE_TO_RESET, RESET_DATES; | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/org/openedx/core/data/model/DateType.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,31 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
enum class DateType { | ||
@SerializedName("todays-date") | ||
TODAY_DATE, | ||
|
||
@SerializedName("course-start-date") | ||
COURSE_START_DATE, | ||
|
||
@SerializedName("course-end-date") | ||
COURSE_END_DATE, | ||
|
||
@SerializedName("course-expired-date") | ||
COURSE_EXPIRED_DATE, | ||
|
||
@SerializedName("assignment-due-date") | ||
ASSIGNMENT_DUE_DATE, | ||
|
||
@SerializedName("certificate-available-date") | ||
CERTIFICATE_AVAILABLE_DATE, | ||
|
||
@SerializedName("verified-upgrade-deadline") | ||
VERIFIED_UPGRADE_DEADLINE, | ||
|
||
@SerializedName("verification-deadline-date") | ||
VERIFICATION_DEADLINE_DATE, | ||
|
||
NONE, | ||
} |
26 changes: 26 additions & 0 deletions
26
core/src/main/java/org/openedx/core/domain/model/CourseDateBlock.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,26 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import org.openedx.core.data.model.DateType | ||
import org.openedx.core.presentation.course.CourseDatesBadge | ||
import java.util.Date | ||
|
||
data class CourseDateBlock( | ||
val title: String = "", | ||
val description: String = "", | ||
val link: String = "", | ||
val blockId: String = "", | ||
val learnerHasAccess: Boolean = false, | ||
val complete: Boolean = false, | ||
val date: Date?, | ||
val dateType: DateType = DateType.NONE, | ||
var dateBlockBadge: CourseDatesBadge = CourseDatesBadge.BLANK, | ||
) { | ||
companion object { | ||
fun getTodayDateBlock() = | ||
CourseDateBlock( | ||
date = Date(), | ||
dateType = DateType.TODAY_DATE, | ||
dateBlockBadge = CourseDatesBadge.TODAY | ||
) | ||
} | ||
} |
Oops, something went wrong.