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

Prev

clear playlistItems when navigating on YT

  • Loading branch information
jamesmudgett committed May 7, 2020
commit f44ec9b9cda389c33f6c8b87c0002cb9b84ae100
@@ -6,10 +6,12 @@
"scale" : "1x"
},
{
"filename" : "check-o@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "check-o@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Binary file not shown.
Binary file not shown.
@@ -6,10 +6,12 @@
"scale" : "1x"
},
{
"filename" : "close-o@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "close-o@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Binary file not shown.
Binary file not shown.
@@ -6,10 +6,12 @@
"scale" : "1x"
},
{
"filename" : "maximize-o@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "maximize-o@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Binary file not shown.
Binary file not shown.
@@ -6,12 +6,12 @@
"scale" : "1x"
},
{
"filename" : "Layer 1@2x.png",
"filename" : "plus-circle-o@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Layer 1@3x.png",
"filename" : "plus-circle-o@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -573,6 +573,7 @@ class BrowserViewController: UIViewController {
scrollController.tabsBar = tabsBar
scrollController.footer = footer
scrollController.snackBars = alertStackView
scrollController.nowPlayingBar = nowPlayingBar

self.updateToolbarStateForTraitCollection(self.traitCollection)

@@ -666,10 +667,6 @@ 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)
@@ -977,6 +974,12 @@ class BrowserViewController: UIViewController {
}
}

nowPlayingBar.snp.remakeConstraints { make in
make.left.right.equalTo(webViewContainer).inset(8)
make.height.equalTo(50)
scrollController.nowPlayingBottomConstraint = make.bottom.equalTo(webViewContainer).inset(8).constraint
}

// Setup the bottom toolbar
toolbar?.snp.remakeConstraints { make in
make.edges.equalTo(self.footer)
@@ -3530,10 +3533,15 @@ extension BrowserViewController: NowPlayingBarDelegate {
let items = tab.playlistItems.value
if items.count > 1 {
let controller = PlaylistMultipleSelectionController(tabManager: self.tabManager)
self.present(controller, animated: true, completion: nil)
} else {
let controller = UINavigationController(rootViewController: PlaylistViewController(tabManager: self.tabManager))
self.present(controller, animated: true, completion: nil)
self.present(controller, animated: false, completion: nil)
} else if let item = items.first {
Playlist.shared.addItem(item: item, cachedData: nil) { [weak self] in
DispatchQueue.main.async {
guard let self = self else { return }
CarplayMediaManager.shared.updateItems()
self.tabManager.allTabs.forEach({ $0.playlistItems.refresh() })
}
}
}
}
}
@@ -56,7 +56,7 @@ class PlaylistMultipleSelectionController: UIViewController {

@objc
private func onExit(_ button: UIButton) {
self.dismiss(animated: true, completion: nil)
self.dismiss(animated: false, completion: nil)
}

@objc
@@ -29,6 +29,8 @@ class NowPlayingBar: UIView {
}
}

private let backgroundBlurView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))

private let infoStackView = UIStackView().then {
$0.axis = .horizontal
$0.spacing = 15.0
@@ -57,11 +59,13 @@ class NowPlayingBar: UIView {
$0.contentMode = .scaleAspectFit
$0.layer.masksToBounds = true
$0.layer.cornerRadius = 5.0
$0.tintColor = .white
}

private let soundBarButton = UIButton().then {
$0.setImage(#imageLiteral(resourceName: "videoPlayingIndicator"), for: .normal)
$0.setImage(#imageLiteral(resourceName: "videoPlayingIndicator").withRenderingMode(.alwaysTemplate), for: .normal)
$0.imageView?.contentMode = .scaleAspectFit
$0.tintColor = .white
}

private let titleLabel = UILabel().then {
@@ -84,19 +88,23 @@ class NowPlayingBar: UIView {
}

private let expandButton = UIButton().then {
$0.setImage(#imageLiteral(resourceName: "nowPlayingExpand"), for: .normal)
$0.setImage(#imageLiteral(resourceName: "nowPlayingExpand").withRenderingMode(.alwaysTemplate), for: .normal)
$0.imageView?.contentMode = .scaleAspectFit
$0.tintColor = UIColor.white
}

private let closeButton = UIButton().then {
$0.setImage(#imageLiteral(resourceName: "nowPlayingExit"), for: .normal)
$0.setImage(#imageLiteral(resourceName: "nowPlayingExit").withRenderingMode(.alwaysTemplate), for: .normal)
$0.imageView?.contentMode = .scaleAspectFit
$0.tintColor = .white
}

override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = #colorLiteral(red: 0.4352941176, green: 0.4352941176, blue: 0.4352941176, alpha: 1)
backgroundBlurView.contentView.backgroundColor = UIColor(white: 1.0, alpha: 0.4)

addSubview(backgroundBlurView)

infoStackView.addArrangedSubview(iconView)
infoStackView.addArrangedSubview(titleLabel)
@@ -108,6 +116,10 @@ class NowPlayingBar: UIView {
addSubview(infoStackView)
addSubview(buttonStackView)

backgroundBlurView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

infoStackView.snp.makeConstraints {
$0.left.top.bottom.equalToSuperview()
}
@@ -146,6 +158,13 @@ class NowPlayingBar: UIView {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
let roundPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8, height: 8))
let maskLayer = CAShapeLayer()
maskLayer.path = roundPath.cgPath
layer.mask = maskLayer
}

private func createSeparator() -> UIView {
return UIView().then {
$0.backgroundColor = #colorLiteral(red: 0.537254902, green: 0.5411764706, blue: 0.537254902, alpha: 1)
@@ -163,7 +182,8 @@ class NowPlayingBar: UIView {

switch state {
case .add:
iconView.image = #imageLiteral(resourceName: "playlistsAdd")
iconView.image = #imageLiteral(resourceName: "playlistsAdd").withRenderingMode(.alwaysTemplate)
iconView.tintColor = .white
titleLabel.text = "Add to playlist"
titleLabel.isHidden = false
mediaInfoStackView.isHidden = true
@@ -175,7 +195,8 @@ class NowPlayingBar: UIView {
mediaInfoStackView.isHidden = true

case .addNowPlaying:
iconView.image = #imageLiteral(resourceName: "playlistsAdd")
iconView.image = #imageLiteral(resourceName: "playlistsAdd").withRenderingMode(.alwaysTemplate)
iconView.tintColor = .white
titleLabel.isHidden = true
mediaInfoStackView.isHidden = false

@@ -219,17 +240,15 @@ class NowPlayingBar: UIView {
infoStackView.addArrangedSubview(mediaInfoStackView)
}

buttonStackView.addArrangedSubview(createSeparator())
buttonStackView.addArrangedSubview(expandButton)
buttonStackView.addArrangedSubview(createSeparator())
buttonStackView.addArrangedSubview(closeButton)
}

// MARK: - Delegates
@objc
private func onAddToPlaylist(_ gestureRecognizer: UIGestureRecognizer) {
if state == .add || state == .addNowPlaying {
if state == .add {
delegate?.onAddToPlaylist()
} else {
delegate?.onExpand()
@@ -265,6 +265,7 @@ extension PlaylistViewController: UITableViewDelegate {

self.currentItem = -1
Playlist.shared.currentlyPlayingInfo.value = nil

//currentItem.mimeType = response?.mimeType
Playlist.shared.updateCache(item: currentItem, cachedData: data ?? Data())
completionHandler(true)
@@ -512,6 +512,10 @@ class Tab: NSObject {
return
}

if playlistItems.value.count > 0 {
playlistItems.value = []
}

self.urlDidChangeDelegate?.tab(self, urlDidChangeTo: url)
}

@@ -985,17 +985,18 @@ class TabManagerNavDelegate: NSObject, WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let authenticatingDelegates = delegates.filter { wv in
return wv.responds(to: #selector(webView(_:didReceive:completionHandler:)))
}

let authenticatingDelegates = delegates.filter { wv in
return wv.responds(to: #selector(webView(_:didReceive:completionHandler:)))
}

guard let firstAuthenticatingDelegate = authenticatingDelegates.first else {
return completionHandler(.performDefaultHandling, nil)
}
guard let firstAuthenticatingDelegate = authenticatingDelegates.first else {
return completionHandler(.performDefaultHandling, nil)
}

firstAuthenticatingDelegate.webView?(webView, didReceive: challenge) { (disposition, credential) in
completionHandler(disposition, credential)
}
firstAuthenticatingDelegate.webView?(webView, didReceive: challenge) { (disposition, credential) in
completionHandler(disposition, credential)
}
}

func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
@@ -40,9 +40,11 @@ class TabScrollingController: NSObject {
weak var footer: UIView?
weak var topToolbar: TopToolbarView?
weak var tabsBar: TabsBarViewController?
weak var nowPlayingBar: NowPlayingBar?
weak var snackBars: UIView?

var footerBottomConstraint: Constraint?
var nowPlayingBottomConstraint: Constraint?
var headerTopConstraint: Constraint?
var toolbarsShowing: Bool { return headerTopOffset == 0 }

@@ -66,6 +68,7 @@ class TabScrollingController: NSObject {
fileprivate var footerBottomOffset: CGFloat = 0 {
didSet {
footerBottomConstraint?.update(offset: footerBottomOffset)
nowPlayingBottomConstraint?.update(offset: footerBottomOffset - 8)
footer?.superview?.setNeedsLayout()
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.