From 9e32e7459b71a58e24a1a47b68cef24f62f6d8c1 Mon Sep 17 00:00:00 2001 From: saeedbashir Date: Tue, 19 Sep 2023 11:36:58 +0500 Subject: [PATCH] chore: handle header view in video block --- Source/VideoBlockViewController.swift | 8 +++++++- Source/VideoTranscript.swift | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Source/VideoBlockViewController.swift b/Source/VideoBlockViewController.swift index 4a3d812eb2..d70a4fa78a 100644 --- a/Source/VideoBlockViewController.swift +++ b/Source/VideoBlockViewController.swift @@ -10,7 +10,7 @@ import Foundation import MediaPlayer import UIKit -class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewController, StatusBarOverriding, InterfaceOrientationOverriding, VideoTranscriptDelegate, RatingViewControllerDelegate, VideoPlayerDelegate { +class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewController, StatusBarOverriding, InterfaceOrientationOverriding, VideoTranscriptDelegate, RatingViewControllerDelegate, VideoPlayerDelegate, ScrollableDelegateProvider { typealias Environment = DataManagerProvider & OEXInterfaceProvider & ReachabilityProvider & OEXConfigProvider & OEXRouterProvider & OEXAnalyticsProvider & OEXStylesProvider & OEXSessionProvider & NetworkManagerProvider @@ -32,6 +32,12 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo private var overlayLabel: UILabel? var shouldCelebrationAppear: Bool + weak var scrollableDelegate: ScrollableDelegate? { + didSet { + videoTranscriptView?.scrollableDelegate = scrollableDelegate + } + } + init(environment : Environment, blockID : CourseBlockID?, courseID: String, shouldCelebrationAppear: Bool = false) { self.blockID = blockID self.environment = environment diff --git a/Source/VideoTranscript.swift b/Source/VideoTranscript.swift index 96535f51d4..4c7f6ecb99 100644 --- a/Source/VideoTranscript.swift +++ b/Source/VideoTranscript.swift @@ -12,10 +12,13 @@ protocol VideoTranscriptDelegate: AnyObject { func didSelectSubtitleAtInterval(time: TimeInterval) } -class VideoTranscript: NSObject, UITableViewDelegate, UITableViewDataSource{ +class VideoTranscript: NSObject, UITableViewDelegate, UITableViewDataSource, ScrollableDelegateProvider { typealias Environment = DataManagerProvider & OEXInterfaceProvider & ReachabilityProvider + weak var scrollableDelegate: ScrollableDelegate? + private var scrollByDragging = false + let transcriptTableView = UITableView(frame: CGRect.zero, style: .plain) var transcripts = [TranscriptObject]() @@ -68,7 +71,18 @@ class VideoTranscript: NSObject, UITableViewDelegate, UITableViewDataSource{ delegate?.didSelectSubtitleAtInterval(time: transcripts[indexPath.row].start) } + func scrollViewDidScroll(_ scrollView: UIScrollView) { + if scrollByDragging { + scrollableDelegate?.scrollViewDidScroll(scrollView: scrollView) + } + } + + func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { + scrollByDragging = false + } + func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { + scrollByDragging = true isTableDragged = true draggingTimer.invalidate() draggingTimer = Timer.scheduledTimer(timeInterval: dragDelay, target: self, selector: #selector(invalidateDragging), userInfo: nil, repeats: false)