From 2c13e773dc43a79651770ab42c46ff39f76658a5 Mon Sep 17 00:00:00 2001 From: Muhammad Umer Date: Tue, 1 Aug 2023 11:33:14 +0100 Subject: [PATCH] chore: expand next section after a section is marked as completed (#1782) --- Source/CourseOutlineTableSource.swift | 31 ++++++++++++++++++------ Source/CourseOutlineViewController.swift | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Source/CourseOutlineTableSource.swift b/Source/CourseOutlineTableSource.swift index 256f12f27..c960264e8 100644 --- a/Source/CourseOutlineTableSource.swift +++ b/Source/CourseOutlineTableSource.swift @@ -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 @@ -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) } } } diff --git a/Source/CourseOutlineViewController.swift b/Source/CourseOutlineViewController.swift index cc1e5e5ef..74ab3e419 100644 --- a/Source/CourseOutlineViewController.swift +++ b/Source/CourseOutlineViewController.swift @@ -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.