diff --git a/Source/VideoBlockViewController.swift b/Source/VideoBlockViewController.swift index 4a3d812eb..d70a4fa78 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 96535f51d..4c7f6ecb9 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)