Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

chore: expand next section after a section is marked as completed #1782

Merged
merged 3 commits into from
Aug 1, 2023
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
31 changes: 23 additions & 8 deletions Source/CourseOutlineTableSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ extension CourseOutlineTableController {
for (index, group) in groups.enumerated() {
let observer = BlockCompletionObserver(controller: self, blockID: group.block.blockID, mode: courseOutlineMode, delegate: self)
courseQuerier.add(observer: observer)
if let blocks = courseQuerier.childrenOfBlockWithID(blockID: group.block.blockID, forMode: .full).value {
blocks.children.forEach { block in
let observer = BlockCompletionObserver(controller: self, blockID: block.blockID, mode: courseOutlineMode, delegate: self)
courseQuerier.add(observer: observer)
}
}

if firstIncompleteSection == nil && !allBlocksCompleted(for: group) && !hasAddedToCollapsedSections {
firstIncompleteSection = index
Expand Down Expand Up @@ -759,16 +765,25 @@ extension CourseOutlineTableController: VideoDownloadQualityDelegate {

extension CourseOutlineTableController: BlockCompletionDelegate {
func didCompletionChanged(in blockGroup: CourseOutlineQuerier.BlockGroup, mode: CourseOutlineMode) {
guard mode == courseOutlineMode, mode == .full else { return }

if mode != courseOutlineMode { return }

guard let index = groups.firstIndex(where: { return $0.block.blockID == blockGroup.block.blockID }) else { return }

if tableView.isValidSection(with: index) {
if mode == .full {
groups[index] = blockGroup
if let index = groups.firstIndex(where: { $0.block.blockID == blockGroup.block.blockID }) {
groups[index] = blockGroup
collapsedSections.removeAll()
hasAddedToCollapsedSections = false
setGroups(groups)
} else {
for (index, group) in groups.enumerated() {
guard var child = courseQuerier.childrenOfBlockWithID(blockID: group.block.blockID, forMode: .full).value else { continue }
if let indexOfBlock = child.children.firstIndex(where: { $0.blockID == blockGroup.block.blockID }) {
child.children[indexOfBlock] = blockGroup.block
groups[index] = child
collapsedSections.removeAll()
hasAddedToCollapsedSections = false
setGroups(groups)
break
}
}
tableView.reloadSections([index], with: .none)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/CourseOutlineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ public class CourseOutlineViewController :
view.setNeedsUpdateConstraints()
addListeners()
setAccessibilityIdentifiers()
loadCourseStream()
}

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
resumeCourseController.loadResumeCourse(forMode: courseOutlineMode)
loadCourseStream()

if courseOutlineMode == .video {
// We are doing calculations to show downloading progress on video tab, For this purpose we are observing notifications.
Expand Down