Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug when sequence units level appear after tapping back #260

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ val screenModule = module {
get(),
get(),
get(),
get(),
)
}
viewModel { (courseId: String, handoutsType: String) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,26 @@ class CourseDatesFragment : Fragment() {
onItemClick = { blockId ->
if (blockId.isNotEmpty()) {
viewModel.getVerticalBlock(blockId)?.let { verticalBlock ->
viewModel.getSequentialBlock(verticalBlock.id)
?.let { sequentialBlock ->
router.navigateToCourseSubsections(
fm = requireActivity().supportFragmentManager,
subSectionId = sequentialBlock.id,
courseId = viewModel.courseId,
unitId = verticalBlock.id,
mode = CourseViewMode.FULL
)
}
if (viewModel.isCourseExpandableSectionsEnabled) {
router.navigateToCourseContainer(
fm = requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
unitId = verticalBlock.id,
componentId = "",
mode = CourseViewMode.FULL
)
} else {
viewModel.getSequentialBlock(verticalBlock.id)
?.let { sequentialBlock ->
router.navigateToCourseSubsections(
fm = requireActivity().supportFragmentManager,
subSectionId = sequentialBlock.id,
courseId = viewModel.courseId,
unitId = verticalBlock.id,
mode = CourseViewMode.FULL
)
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.launch
import org.openedx.core.BaseViewModel
import org.openedx.core.SingleEventLiveData
import org.openedx.core.UIMessage
import org.openedx.core.config.Config
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.domain.model.Block
import org.openedx.core.extension.getSequentialBlocks
Expand All @@ -37,6 +38,7 @@ class CourseDatesViewModel(
private val networkConnection: NetworkConnection,
private val resourceManager: ResourceManager,
private val corePreferences: CorePreferences,
private val config: Config,
) : BaseViewModel() {

private val _uiState = MutableLiveData<DatesUIState>(DatesUIState.Loading)
Expand Down Expand Up @@ -64,6 +66,8 @@ class CourseDatesViewModel(
val hasInternetConnection: Boolean
get() = networkConnection.isOnline()

val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled()

init {
getCourseDates()
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,24 @@ class CourseOutlineFragment : Fragment() {
viewModel.resumeSectionBlock?.let { subSection ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also move this and the other block (in DatesFragment) to their respective ViewModel, but that's up to you now. 😄

viewModel.resumeCourseTappedEvent(subSection.id)
viewModel.resumeVerticalBlock?.let { unit ->
router.navigateToCourseSubsections(
requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
subSectionId = subSection.id,
mode = CourseViewMode.FULL,
unitId = unit.id,
componentId = componentId
)
if (viewModel.isCourseExpandableSectionsEnabled) {
router.navigateToCourseContainer(
fm = requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
unitId = unit.id,
componentId = componentId,
mode = CourseViewMode.FULL
)
} else {
router.navigateToCourseSubsections(
requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
subSectionId = subSection.id,
mode = CourseViewMode.FULL,
unitId = unit.id,
componentId = componentId
)
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class CourseOutlineViewModel(
val hasInternetConnection: Boolean
get() = networkConnection.isOnline()

val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled()

private val courseSubSections = mutableMapOf<String, MutableList<Block>>()
private val subSectionsDownloadsCount = mutableMapOf<String, Int>()
val courseSubSectionUnit = mutableMapOf<String, Block?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.openedx.core.R
import org.openedx.core.UIMessage
import org.openedx.core.config.Config
import org.openedx.core.data.model.DateType
import org.openedx.core.data.model.User
import org.openedx.core.data.storage.CorePreferences
Expand Down Expand Up @@ -54,6 +55,7 @@ class CourseDatesViewModelTest {
private val calendarManager = mockk<CalendarManager>()
private val networkConnection = mockk<NetworkConnection>()
private val corePreferences = mockk<CorePreferences>()
private val config = mockk<Config>()

private val openEdx = "OpenEdx"
private val calendarTitle = "OpenEdx - Abc"
Expand Down Expand Up @@ -159,7 +161,8 @@ class CourseDatesViewModelTest {
calendarManager,
networkConnection,
resourceManager,
corePreferences
corePreferences,
config
)
every { networkConnection.isOnline() } returns true
coEvery { interactor.getCourseDates(any()) } throws UnknownHostException()
Expand All @@ -185,7 +188,8 @@ class CourseDatesViewModelTest {
calendarManager,
networkConnection,
resourceManager,
corePreferences
corePreferences,
config
)
every { networkConnection.isOnline() } returns true
coEvery { interactor.getCourseDates(any()) } throws Exception()
Expand All @@ -211,7 +215,8 @@ class CourseDatesViewModelTest {
calendarManager,
networkConnection,
resourceManager,
corePreferences
corePreferences,
config
)
every { networkConnection.isOnline() } returns true
coEvery { interactor.getCourseDates(any()) } returns mockedCourseDatesResult
Expand All @@ -236,7 +241,8 @@ class CourseDatesViewModelTest {
calendarManager,
networkConnection,
resourceManager,
corePreferences
corePreferences,
config
)
every { networkConnection.isOnline() } returns true
coEvery { interactor.getCourseDates(any()) } returns CourseDatesResult(
Expand Down
Loading