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

clear playlistItems when navigating on YT #2587

Open
wants to merge 14 commits into
base: feature/Playlists
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Added playlist multiple item selection and now playing bar proto-type.

  • Loading branch information
Brandon-T committed Apr 2, 2020
commit 08773b180c4d0a37c626ea9589326ef5e8f29319
@@ -702,6 +702,9 @@
5E612A8F234B7FCA007D12B5 /* OnboardingRewardsAgreementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E1D8C6A232BF95200BDE662 /* OnboardingRewardsAgreementViewController.swift */; };
5E612A90234B7FCD007D12B5 /* OnboardingRewardsAgreementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E1D8C6C232BF9C200BDE662 /* OnboardingRewardsAgreementView.swift */; };
5E6683A923D61CF7005B3A6C /* NTPDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E6683A823D61CF7005B3A6C /* NTPDownloader.swift */; };
5E66CCB82432588B0076BA78 /* VideoPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E66CCB72432588B0076BA78 /* VideoPlayer.swift */; };
5E66CCBB243259390076BA78 /* PlaylistNowPlayingBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E66CCBA243259390076BA78 /* PlaylistNowPlayingBar.swift */; };
5E66CCBD24336D2D0076BA78 /* PlaylistMultipleSelectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E66CCBC24336D2D0076BA78 /* PlaylistMultipleSelectionController.swift */; };
5E6B9A3D239573D100E6720C /* Playlist.js in Resources */ = {isa = PBXBuildFile; fileRef = 5E6B9A3C239573D100E6720C /* Playlist.js */; };
5E6B9A4223957DB800E6720C /* PlaylistViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E6B9A4123957DB800E6720C /* PlaylistViewController.swift */; };
5E77F9A8236B362800E1649C /* DeviceCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E856FE7235E083B0094E113 /* DeviceCheck.swift */; };
@@ -2208,6 +2211,9 @@
5E4845BF22DE381200372022 /* WindowRenderHelper.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = WindowRenderHelper.js; sourceTree = "<group>"; };
5E4845C122DE3DF800372022 /* WindowRenderHelperScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowRenderHelperScript.swift; sourceTree = "<group>"; };
5E6683A823D61CF7005B3A6C /* NTPDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NTPDownloader.swift; sourceTree = "<group>"; };
5E66CCB72432588B0076BA78 /* VideoPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayer.swift; sourceTree = "<group>"; };
5E66CCBA243259390076BA78 /* PlaylistNowPlayingBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistNowPlayingBar.swift; sourceTree = "<group>"; };
5E66CCBC24336D2D0076BA78 /* PlaylistMultipleSelectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistMultipleSelectionController.swift; sourceTree = "<group>"; };
5E6B9A3C239573D100E6720C /* Playlist.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Playlist.js; sourceTree = "<group>"; };
5E6B9A4123957DB800E6720C /* PlaylistViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistViewController.swift; sourceTree = "<group>"; };
5E77F9DC236BB68700E1649C /* AttestationDebugger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttestationDebugger.swift; sourceTree = "<group>"; };
@@ -4280,6 +4286,9 @@
5ED3F38E239AD9A30048CE56 /* PlaylistItem+CoreDataProperties.swift */,
5E2DF91C24194779000A8943 /* PlaylistCacheLoader.swift */,
5ED3F38A239AD89D0048CE56 /* Playlist.xcdatamodeld */,
5E66CCB72432588B0076BA78 /* VideoPlayer.swift */,
5E66CCBA243259390076BA78 /* PlaylistNowPlayingBar.swift */,
5E66CCBC24336D2D0076BA78 /* PlaylistMultipleSelectionController.swift */,
);
path = Playlists;
sourceTree = "<group>";
0BF0DB941A8545800039F300 /* TopToolbarView.swift in Sources */,
4422D4C321BFFB7600BF1855 /* coding.cc in Sources */,
595E0EE121CAEF5B00813D49 /* FileManagerExtension.swift in Sources */,
5E66CCBB243259390076BA78 /* PlaylistNowPlayingBar.swift in Sources */,
C615FAD9212A1E2600A8168C /* WebImageCache.swift in Sources */,
C615FAED212ACAD200A8168C /* BraveWebView.swift in Sources */,
C817B34D1FC609500086018E /* UIScrollViewSwizzled.swift in Sources */,
D83822001FC7961D00303C12 /* DispatchQueueExtensions.swift in Sources */,
D03F8EB22004014E003C2224 /* FaviconHandler.swift in Sources */,
78A9D0962407B4A90077576C /* BraveGetUA.swift in Sources */,
5E6B9A402395752300E6720C /* PlaylistManager.swift in Sources */,
0AB2442C22AA789B00B4D9DD /* ReaderModeButton.swift in Sources */,
4422D55E21BFFB7F00BF1855 /* mimics_pcre.cc in Sources */,
5E2DF91D24194779000A8943 /* PlaylistCacheLoader.swift in Sources */,
44331DBB22521013007E3E93 /* MenuViewController.swift in Sources */,
4422D4BC21BFFB7600BF1855 /* testharness.cc in Sources */,
3BE7275D1CCFE8B60099189F /* CustomSearchHandler.swift in Sources */,
5E66CCBD24336D2D0076BA78 /* PlaylistMultipleSelectionController.swift in Sources */,
F930CDD72270F14300A23FE1 /* WebAuthnUtils.swift in Sources */,
5E66CCB82432588B0076BA78 /* VideoPlayer.swift in Sources */,
A1FEEE2020BF28D900298DA2 /* Then.swift in Sources */,
0A1E84442190A57F0042F782 /* SyncCameraView.swift in Sources */,
A1CA29C420E1746A00CB9126 /* OptionSelectionViewController.swift in Sources */,
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Layer 1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Layer 1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Layer 1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Layer 1-1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Layer 1@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Layer 1@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Layer 1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
@@ -5,8 +5,8 @@
"scale" : "1x"
},
{
"filename" : "pause-1.png",
"idiom" : "universal",
"filename" : "VideoPause.png",
"scale" : "2x"
},
{
@@ -15,7 +15,7 @@
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Binary file not shown.
Binary file not shown.
@@ -5,8 +5,8 @@
"scale" : "1x"
},
{
"filename" : "skip.png",
"idiom" : "universal",
"filename" : "VideoSkipBack.png",
"scale" : "2x"
},
{
@@ -15,7 +15,7 @@
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Binary file not shown.
Binary file not shown.
@@ -5,8 +5,8 @@
"scale" : "1x"
},
{
"filename" : "skipRIGHT.png",
"idiom" : "universal",
"filename" : "VideoSkipForward.png",
"scale" : "2x"
},
{
@@ -15,7 +15,7 @@
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Binary file not shown.
Binary file not shown.
@@ -50,6 +50,8 @@ class BrowserViewController: UIViewController {
var readerModeBar: ReaderModeBarView?
var readerModeCache: ReaderModeCache
var statusBarOverlay: UIView!
var nowPlayingBar: NowPlayingBar!
private var nowPlayingItem: PlaylistInfo?
fileprivate(set) var toolbar: BottomToolbarView?
var searchController: SearchViewController?
fileprivate var screenshotHelper: ScreenshotHelper!
@@ -486,6 +488,11 @@ class BrowserViewController: UIViewController {

webViewContainer = UIView()
view.addSubview(webViewContainer)

nowPlayingBar = NowPlayingBar()
nowPlayingBar.delegate = self
nowPlayingBar.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(nowPlayingBar)

// Temporary work around for covering the non-clipped web view content
statusBarOverlay = UIView()
@@ -649,11 +656,14 @@ class BrowserViewController: UIViewController {
make.edges.equalTo(webViewContainer)
}

nowPlayingBar.snp.makeConstraints { make in
make.left.right.bottom.equalTo(webViewContainer)
}

topTouchArea.snp.makeConstraints { make in
make.top.left.right.equalTo(self.view)
make.height.equalTo(BrowserViewControllerUX.showHeaderTapAreaHeight)
}

}

override func viewDidLayoutSubviews() {
@@ -2124,6 +2134,11 @@ extension BrowserViewController: TabDelegate {
#if !NO_SKUS
tab.addContentScript(PaymentRequestExtension(rewards: rewards, tab: tab, paymentRequested: self.paymentRequested), name: PaymentRequestExtension.name())
#endif

tab.playlistItems.observe { [weak self] _, _ in
guard let self = self else { return }
self.onUpdateNowPlaying(tab: tab)
}.bind(to: tab)
}

func tab(_ tab: Tab, willDeleteWebView webView: WKWebView) {
@@ -3498,3 +3513,38 @@ extension BrowserViewController: OnboardingControllerDelegate {
// 60 days until the next time the user sees the onboarding..
static let onboardingDaysInterval = TimeInterval(60.days)
}

extension BrowserViewController: NowPlayingBarDelegate {
func onAddToPlaylist() {
let controller = PlaylistMultipleSelectionController(tabManager: self.tabManager)
self.present(controller, animated: true, completion: nil)
}

func onExpand() {

}

func onExit() {
self.presentedViewController?.dismiss(animated: true, completion: nil)
}

func onUpdateNowPlaying(tab: Tab) {
let items = tab.playlistItems.value
if items.isEmpty {
if Playlist.shared.currentlyPlayingInfo != nil {
nowPlayingBar.state = .nowPlaying
nowPlayingBar.isHidden = false
} else {
nowPlayingBar.isHidden = true
}
} else {
nowPlayingBar.isHidden = false

if Playlist.shared.currentlyPlayingInfo != nil {
nowPlayingBar.state = .addNowPlaying
} else {
nowPlayingBar.state = .add
}
}
}
}
@@ -224,7 +224,7 @@ extension AddToPlaylistViewController: UITableViewDelegate {
}
}

private class PlaylistSelectionCell: UITableViewCell {
public class PlaylistSelectionCell: UITableViewCell {

public let thumbnailView = UIImageView().then {
$0.contentMode = .scaleAspectFit
@@ -314,7 +314,7 @@ private class PlaylistSelectionCell: UITableViewCell {
fatalError("init(coder:) has not been implemented")
}

override public var layoutMargins: UIEdgeInsets {
public override var layoutMargins: UIEdgeInsets {
get {
return .zero
}
@@ -324,7 +324,7 @@ private class PlaylistSelectionCell: UITableViewCell {
}
}

override var separatorInset: UIEdgeInsets {
public override var separatorInset: UIEdgeInsets {
get {
return UIEdgeInsets(top: 0, left: self.titleLabel.frame.origin.x, bottom: 0, right: 0)
}
@@ -13,6 +13,8 @@ class Playlist {
static let shared = Playlist()
private let dbLock = NSRecursiveLock()

public var currentlyPlayingInfo: PlaylistInfo?

func addItem(item: PlaylistInfo, completion: @escaping () -> Void) {
if !self.itemExists(item: item) {
self.backgroundContext.perform { [weak self] in
@@ -113,6 +113,7 @@ class PlaylistWebLoader: UIView, WKScriptMessageHandler, WKNavigationDelegate {
}

webView.navigationDelegate = self
webView.configuration.mediaTypesRequiringUserActionForPlayback = []
webView.configuration.userContentController.add(self, name: "playlistManager")
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.