Skip to content

Commit

Permalink
fix: Address PR comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Feb 4, 2024
1 parent 3d98024 commit 5942d0d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 41 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/openedx/core/data/model/CourseDates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data class CourseDates(
@SerializedName("dates_banner_info")
val datesBannerInfo: DatesBannerInfo?,
@SerializedName("has_ended")
val hasEnded: Boolean,
val hasEnded: Boolean?,
) {
fun getCourseDatesResult(): CourseDatesResult {
return CourseDatesResult(
Expand All @@ -26,13 +26,13 @@ data class CourseDates(
)
}

fun getDatesBannerInfo(): CourseDatesBannerInfo {
private fun getDatesBannerInfo(): CourseDatesBannerInfo {
return CourseDatesBannerInfo(
missedDeadlines = datesBannerInfo?.missedDeadlines ?: false,
missedGatedContent = datesBannerInfo?.missedGatedContent ?: false,
verifiedUpgradeLink = datesBannerInfo?.verifiedUpgradeLink ?: "",
contentTypeGatingEnabled = datesBannerInfo?.contentTypeGatingEnabled ?: false,
hasEnded = hasEnded,
hasEnded = hasEnded ?: false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ data class CourseDatesBannerInfo(
@SerializedName("dates_banner_info")
val datesBannerInfo: DatesBannerInfo?,
@SerializedName("has_ended")
val hasEnded: Boolean,
val hasEnded: Boolean?,
) {
fun mapToDomain(): CourseDatesBannerInfo {
return CourseDatesBannerInfo(
missedDeadlines = datesBannerInfo?.missedDeadlines ?: false,
missedGatedContent = datesBannerInfo?.missedGatedContent ?: false,
verifiedUpgradeLink = datesBannerInfo?.verifiedUpgradeLink ?: "",
contentTypeGatingEnabled = datesBannerInfo?.contentTypeGatingEnabled ?: false,
hasEnded = hasEnded,
hasEnded = hasEnded ?: false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ 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 = false,
private val missedGatedContent: Boolean = false,
private val verifiedUpgradeLink: String = "",
private val contentTypeGatingEnabled: Boolean = false,
private val hasEnded: Boolean = false,
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() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
}
}


companion object {
private const val ARG_COURSE_ID = "courseId"
private const val ARG_TITLE = "title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import org.openedx.core.utils.clearTime
import org.openedx.course.R
import org.openedx.course.presentation.CourseRouter
import org.openedx.course.presentation.ui.CourseDatesBanner
import org.openedx.course.presentation.ui.CourseDatesBannerTablet
import org.openedx.core.R as coreR

class CourseDatesFragment : Fragment() {
Expand Down Expand Up @@ -271,11 +272,19 @@ internal fun CourseDatesScreen(

if (courseBanner.isBannerAvailableForUserType(isSelfPaced)) {
item {
CourseDatesBanner(
modifier = Modifier.padding(bottom = 16.dp),
banner = courseBanner,
resetDates = onSyncDates
)
if (windowSize.isTablet) {
CourseDatesBannerTablet(
modifier = Modifier.padding(bottom = 16.dp),
banner = courseBanner,
resetDates = onSyncDates,
)
} else {
CourseDatesBanner(
modifier = Modifier.padding(bottom = 16.dp),
banner = courseBanner,
resetDates = onSyncDates
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,26 +362,24 @@ internal fun CourseOutlineScreen(
}
}
item { Spacer(Modifier.height(28.dp)) }
uiState.datesBannerInfo?.let { banner ->
if (banner.isBannerAvailableForDashboard()) {
item {
Box(
modifier = Modifier
.padding(all = 6.dp)
) {
if (windowSize.isTablet) {
CourseDatesBannerTablet(
modifier = Modifier.padding(bottom = 16.dp),
banner = banner,
resetDates = onResetDatesClick,
)
} else {
CourseDatesBanner(
modifier = Modifier.padding(bottom = 16.dp),
banner = banner,
resetDates = onResetDatesClick,
)
}
if (uiState.datesBannerInfo.isBannerAvailableForDashboard()) {
item {
Box(
modifier = Modifier
.padding(all = 8.dp)
) {
if (windowSize.isTablet) {
CourseDatesBannerTablet(
modifier = Modifier.padding(bottom = 16.dp),
banner = uiState.datesBannerInfo,
resetDates = onResetDatesClick,
)
} else {
CourseDatesBanner(
modifier = Modifier.padding(bottom = 16.dp),
banner = uiState.datesBannerInfo,
resetDates = onResetDatesClick,
)
}
}
}
Expand Down Expand Up @@ -628,7 +626,13 @@ private fun CourseOutlineScreenPreview() {
mapOf(),
mapOf(),
mapOf(),
CourseDatesBannerInfo(false, false, "", false, false)
CourseDatesBannerInfo(
missedDeadlines = false,
missedGatedContent = false,
verifiedUpgradeLink = "",
contentTypeGatingEnabled = false,
hasEnded = false
)
),
apiHostUrl = "",
isCourseNestedListEnabled = true,
Expand Down Expand Up @@ -662,7 +666,13 @@ private fun CourseOutlineScreenTabletPreview() {
mapOf(),
mapOf(),
mapOf(),
CourseDatesBannerInfo(false, false, "", false, false)
CourseDatesBannerInfo(
missedDeadlines = false,
missedGatedContent = false,
verifiedUpgradeLink = "",
contentTypeGatingEnabled = false,
hasEnded = false
)
),
apiHostUrl = "",
isCourseNestedListEnabled = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sealed class CourseOutlineUIState {
val courseSubSections: Map<String, List<Block>>,
val courseSectionsState: Map<String, Boolean>,
val subSectionsDownloadsCount: Map<String, Int>,
val datesBannerInfo: CourseDatesBannerInfo?,
val datesBannerInfo: CourseDatesBannerInfo,
) : CourseOutlineUIState()

object Loading : CourseOutlineUIState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class CourseOutlineViewModel(
getCourseDataInternal()
}

fun getCourseData() {
private fun getCourseData() {
_uiState.value = CourseOutlineUIState.Loading
getCourseDataInternal()
}
Expand Down Expand Up @@ -172,7 +172,13 @@ class CourseOutlineViewModel(
val datesBannerInfo = if (networkConnection.isOnline()) {
interactor.getDatesBannerInfo(courseId)
} else {
CourseDatesBannerInfo()
CourseDatesBannerInfo(
missedDeadlines = false,
missedGatedContent = false,
verifiedUpgradeLink = "",
contentTypeGatingEnabled = false,
hasEnded = false
)
}
setBlocks(blocks)
courseSubSections.clear()
Expand Down

0 comments on commit 5942d0d

Please sign in to comment.