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

Fixed title changing on section (sequential) screen #136

Merged
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
3 changes: 1 addition & 2 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
fm: FragmentManager,
courseId: String,
blockId: String,
title: String,
mode: CourseViewMode,
) {
replaceFragmentWithBackStack(
fm,
CourseSectionFragment.newInstance(courseId, blockId, title, mode)
CourseSectionFragment.newInstance(courseId, blockId, mode)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface CourseRouter {
fm: FragmentManager,
courseId: String,
blockId: String,
title: String,
mode: CourseViewMode,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class CourseOutlineFragment : Fragment() {
requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
blockId = block.id,
title = block.displayName,
mode = CourseViewMode.FULL
)
},
Expand All @@ -110,7 +109,6 @@ class CourseOutlineFragment : Fragment() {
requireActivity().supportFragmentManager,
viewModel.courseId,
sequential.id,
sequential.displayName,
CourseViewMode.FULL
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,11 @@ class CourseSectionFragment : Fragment() {
}
private val router by inject<CourseRouter>()

private var title = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(viewModel)
val blockId = requireArguments().getString(ARG_BLOCK_ID, "")
viewModel.mode = requireArguments().serializable<CourseViewMode>(ARG_MODE)!!
title = requireArguments().getString(ARG_TITLE, "")
viewModel.mode = requireArguments().serializable(ARG_MODE)!!
viewModel.getBlocks(blockId, viewModel.mode)
}

Expand All @@ -113,7 +110,6 @@ class CourseSectionFragment : Fragment() {
CourseSectionScreen(
windowSize = windowSize,
uiState = uiState,
title = title,
uiMessage = uiMessage,
onBackClick = {
requireActivity().supportFragmentManager.popBackStack()
Expand Down Expand Up @@ -153,19 +149,16 @@ class CourseSectionFragment : Fragment() {
companion object {
private const val ARG_COURSE_ID = "courseId"
private const val ARG_BLOCK_ID = "blockId"
private const val ARG_TITLE = "title"
private const val ARG_MODE = "mode"
fun newInstance(
courseId: String,
blockId: String,
title: String,
mode: CourseViewMode,
): CourseSectionFragment {
val fragment = CourseSectionFragment()
fragment.arguments = bundleOf(
ARG_COURSE_ID to courseId,
ARG_BLOCK_ID to blockId,
ARG_TITLE to title,
ARG_MODE to mode
)
return fragment
Expand All @@ -177,13 +170,17 @@ class CourseSectionFragment : Fragment() {
private fun CourseSectionScreen(
windowSize: WindowSize,
uiState: CourseSectionUIState,
title: String,
uiMessage: UIMessage?,
onBackClick: () -> Unit,
onItemClick: (Block) -> Unit,
onDownloadClick: (Block) -> Unit
) {
val scaffoldState = rememberScaffoldState()
val title = when (uiState) {
is CourseSectionUIState.Blocks -> uiState.sectionName
else -> ""
}

Scaffold(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -399,9 +396,9 @@ private fun CourseSectionScreenPreview() {
mockBlock
),
mapOf(),
""
"",
"Course default"
),
"Course default",
uiMessage = null,
onBackClick = {},
onItemClick = {},
Expand All @@ -425,9 +422,9 @@ private fun CourseSectionScreenTabletPreview() {
mockBlock
),
mapOf(),
""
"",
"Course default",
),
"Course default",
uiMessage = null,
onBackClick = {},
onItemClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sealed class CourseSectionUIState {
data class Blocks(
val blocks: List<Block>,
val downloadedState: Map<String, DownloadedState>,
val sectionName: String,
val courseName: String
) : CourseSectionUIState()
object Loading : CourseSectionUIState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ class CourseSectionViewModel(
super.onCreate(owner)
viewModelScope.launch {
downloadModelsStatusFlow.collect { downloadModels ->
if (uiState.value is CourseSectionUIState.Blocks) {
val list = (uiState.value as CourseSectionUIState.Blocks).blocks
val courseName = (uiState.value as CourseSectionUIState.Blocks).courseName
_uiState.value =
CourseSectionUIState.Blocks(
ArrayList(list),
downloadModels.toMap(),
courseName
)
when (val state = uiState.value) {
is CourseSectionUIState.Blocks -> {
val list = (uiState.value as CourseSectionUIState.Blocks).blocks
_uiState.value = CourseSectionUIState.Blocks(
sectionName = state.sectionName,
courseName = state.courseName,
blocks = ArrayList(list),
downloadedState = downloadModels.toMap())
}
else -> {}
}
}
}
Expand All @@ -82,12 +83,14 @@ class CourseSectionViewModel(
val blocks = courseStructure.blockData
setBlocks(blocks)
val newList = getDescendantBlocks(blocks, blockId)
val sequentialBlock = getSequentialBlock(blocks, blockId)
initDownloadModelsStatus()
_uiState.value =
CourseSectionUIState.Blocks(
ArrayList(newList),
getDownloadModelsStatus(),
courseStructure.name
blocks = ArrayList(newList),
downloadedState = getDownloadModelsStatus(),
courseName = courseStructure.name,
sectionName = sequentialBlock.displayName
)
} catch (e: Exception) {
if (e.isInternetError()) {
Expand Down Expand Up @@ -117,9 +120,7 @@ class CourseSectionViewModel(
private fun getDescendantBlocks(blocks: List<Block>, id: String): List<Block> {
val resultList = mutableListOf<Block>()
if (blocks.isEmpty()) return emptyList()
val selectedBlock = blocks.first {
it.id == id
}
val selectedBlock = getSequentialBlock(blocks, id)
for (descendant in selectedBlock.descendants) {
val blockDescendant = blocks.find {
it.id == descendant
Expand All @@ -134,6 +135,12 @@ class CourseSectionViewModel(
return resultList
}

private fun getSequentialBlock(blocks: List<Block>, id: String): Block {
return blocks.first {
it.id == id
}
}

fun verticalClickedEvent(blockId: String, blockName: String) {
val currentState = uiState.value
if (currentState is CourseSectionUIState.Blocks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class CourseVideosFragment : Fragment() {
requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
blockId = block.id,
title = block.displayName,
mode = CourseViewMode.VIDEOS
)
},
Expand Down