Skip to content

Commit

Permalink
fix: Address PR comments + missed cases
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Feb 1, 2024
1 parent f9c6a81 commit 3d98024
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 41 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/data/api/CourseApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ interface CourseApi {
suspend fun resetCourseDates(@Body courseBody: Map<String, String>): ResetCourseDates

@GET("/api/course_experience/v1/course_deadlines_info/{course_id}")
suspend fun getDatesBannerInfo(@Path("course_id") courseId: String): CourseDates
suspend fun getDatesBannerInfo(@Path("course_id") courseId: String): CourseDatesBannerInfo

@GET("/api/mobile/v1/course_info/{course_id}/handouts")
suspend fun getHandouts(@Path("course_id") courseId: String): HandoutsModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.openedx.core.data.model

import com.google.gson.annotations.SerializedName
import org.openedx.core.domain.model.CourseDatesBannerInfo

data class CourseDatesBannerInfo(
@SerializedName("dates_banner_info")
val datesBannerInfo: DatesBannerInfo?,
@SerializedName("has_ended")
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,
)
}
}
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,
private val missedGatedContent: Boolean,
private val verifiedUpgradeLink: String,
private val contentTypeGatingEnabled: Boolean,
private val hasEnded: Boolean
private val missedDeadlines: Boolean = false,
private val missedGatedContent: Boolean = false,
private val verifiedUpgradeLink: String = "",
private val contentTypeGatingEnabled: Boolean = false,
private val hasEnded: Boolean = false,
) {
val bannerType by lazy { getCourseBannerType() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CourseRepository(
api.resetCourseDates(mapOf(ApiConstants.COURSE_KEY to courseId)).mapToDomain()

suspend fun getDatesBannerInfo(courseId: String) =
api.getDatesBannerInfo(courseId).getDatesBannerInfo()
api.getDatesBannerInfo(courseId).mapToDomain()

suspend fun getHandouts(courseId: String) = api.getHandouts(courseId).mapToDomain()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CourseContainerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment
}

enum class CourseContainerTab(val itemId: Int, val titleResId: Int) {
OUTLINE(itemId = R.id.outline, titleResId = R.string.course_navigation_course),
COURSE(itemId = R.id.course, titleResId = R.string.course_navigation_course),
VIDEOS(itemId = R.id.videos, titleResId = R.string.course_navigation_video),
DISCUSSION(itemId = R.id.discussions, titleResId = R.string.course_navigation_discussion),
DATES(itemId = R.id.dates, titleResId = R.string.course_navigation_dates),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import org.openedx.core.presentation.global.viewBinding
import org.openedx.course.R
import org.openedx.course.databinding.FragmentCourseContainerBinding
import org.openedx.course.presentation.CourseRouter
import org.openedx.course.presentation.container.CourseContainerTab
import org.openedx.course.presentation.dates.CourseDatesFragment
import org.openedx.course.presentation.handouts.HandoutsFragment
import org.openedx.course.presentation.outline.CourseOutlineFragment
import org.openedx.course.presentation.ui.CourseToolbar
import org.openedx.course.presentation.videos.CourseVideosFragment
import org.openedx.discussion.presentation.topics.DiscussionTopicsFragment
import org.openedx.core.R as coreR
import org.openedx.course.presentation.container.CourseContainerTab as Tabs

class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
Expand Down Expand Up @@ -96,7 +96,7 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
binding.viewPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
adapter = CourseContainerAdapter(this).apply {
addFragment(
Tabs.OUTLINE,
Tabs.COURSE,
CourseOutlineFragment.newInstance(viewModel.courseId, viewModel.courseName)
)
addFragment(
Expand Down Expand Up @@ -132,7 +132,7 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
binding.viewPager.isUserInputEnabled = false
binding.bottomNavView.setOnItemSelectedListener { menuItem ->
Tabs.values().find { menuItem.itemId == it.itemId }?.let { tab ->
viewModel.courseTabClickedEvent(tab)
viewModel.courseContainerTabClickedEvent(tab)
binding.viewPager.setCurrentItem(tab.ordinal, false)
}
true
Expand All @@ -145,30 +145,19 @@ class CourseContainerFragment : Fragment(R.layout.fragment_course_container) {
viewModel.updateData(withSwipeRefresh)
}

fun showDatesUpdateSnackbar(isSuccess: Boolean) {
val message = if (isSuccess) {
getString(coreR.string.core_dates_shift_dates_successfully_msg)
} else {
getString(coreR.string.core_dates_shift_dates_unsuccessful_msg)
}
val duration = if (isSuccess) {
Snackbar.LENGTH_INDEFINITE
} else {
Snackbar.LENGTH_LONG
fun updateCourseDates() {
adapter?.getFragment(Tabs.DATES)?.let {
(it as CourseDatesFragment).updateData()
}
snackBar = Snackbar.make(binding.root, message, duration).also {
if (isSuccess) {
it.setAction(coreR.string.core_dates_view_all_dates) {
adapter?.getFragment(Tabs.DATES)?.let { fragment ->
binding.viewPager.setCurrentItem(Tabs.DATES.ordinal, true)
(fragment as CourseDatesFragment).updateData()
}
}
}
}

fun navigateToTab(tab: CourseContainerTab) {
adapter?.getFragment(tab)?.let {
binding.viewPager.setCurrentItem(tab.ordinal, true)
}
snackBar?.show()
}


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 @@ -109,9 +109,9 @@ class CourseContainerViewModel(
}
}

fun courseTabClickedEvent(tab: CourseContainerTab) {
fun courseContainerTabClickedEvent(tab: CourseContainerTab) {
when (tab) {
CourseContainerTab.OUTLINE -> courseTabClickedEvent()
CourseContainerTab.COURSE -> courseTabClickedEvent()
CourseContainerTab.VIDEOS -> videoTabClickedEvent()
CourseContainerTab.DISCUSSION -> discussionTabClickedEvent()
CourseContainerTab.DATES -> datesTabClickedEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
Expand All @@ -80,6 +81,7 @@ import org.openedx.core.ui.theme.appTypography
import org.openedx.core.ui.windowSizeValue
import org.openedx.course.presentation.CourseRouter
import org.openedx.course.presentation.container.CourseContainerFragment
import org.openedx.course.presentation.container.CourseContainerTab
import org.openedx.course.presentation.outline.CourseOutlineFragment.Companion.getUnitBlockIcon
import org.openedx.course.presentation.ui.CourseDatesBanner
import org.openedx.course.presentation.ui.CourseDatesBannerTablet
Expand All @@ -97,6 +99,8 @@ class CourseOutlineFragment : Fragment() {
}
private val router by inject<CourseRouter>()

private var snackBar: Snackbar? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(viewModel)
Expand Down Expand Up @@ -192,14 +196,38 @@ class CourseOutlineFragment : Fragment() {
},
onResetDatesClick = {
viewModel.resetCourseDatesBanner(onResetDates = {
(parentFragment as CourseContainerFragment).showDatesUpdateSnackbar(it)
(parentFragment as CourseContainerFragment).updateCourseDates()
showDatesUpdateSnackbar(it)
})
}
)
}
}
}

override fun onDestroyView() {
snackBar?.dismiss()
super.onDestroyView()
}

private fun showDatesUpdateSnackbar(isSuccess: Boolean) {
val message = if (isSuccess) {
getString(R.string.core_dates_shift_dates_successfully_msg)
} else {
getString(R.string.core_dates_shift_dates_unsuccessful_msg)
}
snackBar = view?.let {
Snackbar.make(it, message, Snackbar.LENGTH_LONG).apply {
if (isSuccess) {
setAction(R.string.core_dates_view_all_dates) {
(parentFragment as CourseContainerFragment).navigateToTab(CourseContainerTab.DATES)
}
}
}
}
snackBar?.show()
}


companion object {
private const val ARG_COURSE_ID = "courseId"
Expand Down Expand Up @@ -333,8 +361,9 @@ internal fun CourseOutlineScreen(
)
}
}
uiState.datesBannerInfo?.let {
if (it.isBannerAvailableForDashboard()) {
item { Spacer(Modifier.height(28.dp)) }
uiState.datesBannerInfo?.let { banner ->
if (banner.isBannerAvailableForDashboard()) {
item {
Box(
modifier = Modifier
Expand All @@ -343,13 +372,13 @@ internal fun CourseOutlineScreen(
if (windowSize.isTablet) {
CourseDatesBannerTablet(
modifier = Modifier.padding(bottom = 16.dp),
banner = it,
banner = banner,
resetDates = onResetDatesClick,
)
} else {
CourseDatesBanner(
modifier = Modifier.padding(bottom = 16.dp),
banner = it,
banner = banner,
resetDates = onResetDatesClick,
)
}
Expand All @@ -359,7 +388,6 @@ internal fun CourseOutlineScreen(
}
if (uiState.resumeComponent != null) {
item {
Spacer(Modifier.height(28.dp))
Box(listPadding) {
if (windowSize.isTablet) {
ResumeCourseTablet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.openedx.core.config.Config
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.domain.model.Block
import org.openedx.core.domain.model.CourseComponentStatus
import org.openedx.core.domain.model.CourseDatesBannerInfo
import org.openedx.core.extension.getSequentialBlocks
import org.openedx.core.extension.getVerticalBlocks
import org.openedx.core.extension.isInternetError
Expand Down Expand Up @@ -171,7 +172,7 @@ class CourseOutlineViewModel(
val datesBannerInfo = if (networkConnection.isOnline()) {
interactor.getDatesBannerInfo(courseId)
} else {
null
CourseDatesBannerInfo()
}
setBlocks(blocks)
courseSubSections.clear()
Expand Down Expand Up @@ -249,6 +250,7 @@ class CourseOutlineViewModel(
viewModelScope.launch {
try {
interactor.resetCourseDates(courseId = courseId)
updateCourseData(false)
onResetDates(true)
} catch (e: Exception) {
if (e.isInternetError()) {
Expand Down
2 changes: 1 addition & 1 deletion course/src/main/res/menu/bottom_course_container_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/outline"
android:id="@+id/course"
android:title="@string/course_navigation_course"
android:enabled="true"
android:icon="@drawable/ic_course_navigation_outline"/>
Expand Down

0 comments on commit 3d98024

Please sign in to comment.