Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #3673 - Implements CarPlay + Refactor Playlist #3887

Merged
merged 7 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,12 @@ extension Strings {
bundle: .braveShared,
value: "Remove",
comment: "Button title in the popover when an item is already in your playlist and you tap the 'Add to Playlist' button in the URL bar")

public static let playlistCarplayTitle =
NSLocalizedString("playlist.carplayTitle",
bundle: .braveShared,
value: "Brave Playlist",
comment: "The title of the playlist when in Carplay mode")
}
}

Expand Down
138 changes: 111 additions & 27 deletions Client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Client/Application/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
var window: UIWindow?
var browserViewController: BrowserViewController!
var rootViewController: UIViewController!
var playlistRestorationController: UIViewController? // When Picture-In-Picture is enabled, we need to store a reference to the controller to keep it alive, otherwise if it deallocates, the system automatically kills Picture-In-Picture.
weak var profile: Profile?
var tabManager: TabManager!
var braveCore: BraveCoreMain?
Expand All @@ -51,6 +50,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati

/// Must be added at launch according to Apple's documentation.
let iapObserver = IAPObserver()

/// A car-play manager instance that will handle when car-play status changes
var carPlayManager: PlaylistCarplayManager?

@discardableResult func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Hold references to willFinishLaunching parameters for delayed app launch
Expand Down Expand Up @@ -404,6 +406,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati

AdblockResourceDownloader.shared.startLoading()
PlaylistManager.shared.restoreSession()
carPlayManager = PlaylistCarplayManager.shared.then {
$0.browserController = browserViewController
}

return shouldPerformAdditionalDelegateHandling
}
Expand Down
9 changes: 5 additions & 4 deletions Client/Application/Shortcuts/ActivityShortcutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ class ActivityShortcutManager: NSObject {
bvc.present(container, animated: true)
}
case .openPlayList:
let playlistController = (UIApplication.shared.delegate as? AppDelegate)?.playlistRestorationController ?? PlaylistViewController(initialItem: nil, initialItemPlaybackOffset: 0.0)
playlistController.modalPresentationStyle = .fullScreen

bvc.present(playlistController, animated: true)
let tab = bvc.tabManager.selectedTab
PlaylistCarplayManager.shared.getPlaylistController(tab: tab) { playlistController in
playlistController.modalPresentationStyle = .fullScreen
bvc.present(playlistController, animated: true)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Client/Entitlements/Beta.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
<array>
<string>group.$(MOZ_BUNDLE_ID)</string>
</array>
<key>com.apple.developer.playable-content</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Client/Entitlements/Debug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
<array>
<string>group.$(LOCAL_BUNDLE_ID)</string>
</array>
<key>com.apple.developer.playable-content</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Client/Entitlements/Dev.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
<array>
<string>group.$(MOZ_BUNDLE_ID).unique</string>
</array>
<key>com.apple.developer.playable-content</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Client/Entitlements/Enterprise.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
<array>
<string>group.$(MOZ_BUNDLE_ID)</string>
</array>
<key>com.apple.developer.playable-content</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Client/Entitlements/Release (AppStore).entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
<array>
<string>group.$(MOZ_BUNDLE_ID)</string>
</array>
<key>com.apple.developer.playable-content</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Client/Entitlements/Release.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
<array>
<string>group.$(MOZ_BUNDLE_ID)</string>
</array>
<key>com.apple.developer.playable-content</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,18 @@ extension BrowserViewController {
}
MenuItemButton(icon: #imageLiteral(resourceName: "playlist_menu").template, title: Strings.playlistMenuItem) { [weak self] in
guard let self = self else { return }

let playlistController = (UIApplication.shared.delegate as? AppDelegate)?.playlistRestorationController


// Present existing playlist controller
if let playlistController = playlistController {
if let playlistController = PlaylistCarplayManager.shared.playlistController {
self.dismiss(animated: true) {
self.present(playlistController, animated: true)
}
} else {
// Retrieve the item and offset-time from the current tab's webview.
if let item = self.tabManager.selectedTab?.playlistItem,
let webView = self.tabManager.selectedTab?.webView {
let tab = self.tabManager.selectedTab
PlaylistCarplayManager.shared.getPlaylistController(tab: tab) { [weak self] playlistController in
guard let self = self else { return }

PlaylistHelper.getCurrentTime(webView: webView, nodeTag: item.tagId) { [weak self] currentTime in
guard let self = self else { return }

let playlistController = PlaylistViewController(initialItem: item, initialItemPlaybackOffset: currentTime)
playlistController.modalPresentationStyle = .fullScreen

self.dismiss(animated: true) {
self.present(playlistController, animated: true)
}
}
} else {
// Otherwise no item to play, so just open the playlist controller.
let playlistController = PlaylistViewController(initialItem: nil, initialItemPlaybackOffset: 0.0)
playlistController.modalPresentationStyle = .fullScreen

self.dismiss(animated: true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ extension BrowserViewController: PlaylistHelperDelegate {
}

func openPlaylist(item: PlaylistInfo?, playbackOffset: Double) {
let playlistController = (UIApplication.shared.delegate as? AppDelegate)?.playlistRestorationController as? PlaylistViewController ?? PlaylistViewController(initialItem: item, initialItemPlaybackOffset: playbackOffset)
let playlistController = PlaylistCarplayManager.shared.getPlaylistController(initialItem: item, initialItemPlaybackOffset: playbackOffset)
playlistController.modalPresentationStyle = .fullScreen

/// Donate Open Playlist Activity for suggestions
Expand Down
104 changes: 0 additions & 104 deletions Client/Frontend/Browser/Playlist/Cache/HLSThumbnailGenerator.swift

This file was deleted.

6 changes: 2 additions & 4 deletions Client/Frontend/Browser/Playlist/Cells/PlaylistCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class PlaylistResizingThumbnailView: UIImageView {
}

class PlaylistCell: UITableViewCell {
var thumbnailGenerator: HLSThumbnailGenerator?
var imageAssetGenerator: AVAssetImageGenerator?
let thumbnailGenerator = PlaylistThumbnailRenderer()
var durationFetcher: PlaylistAssetFetcher?

private let thumbnailMaskView = CAShapeLayer().then {
Expand Down Expand Up @@ -97,8 +96,7 @@ class PlaylistCell: UITableViewCell {
}

func prepareForDisplay() {
thumbnailGenerator = nil
imageAssetGenerator = nil
thumbnailGenerator.cancel()
thumbnailView.cancelFaviconLoad()
durationFetcher?.cancelLoading()
durationFetcher = nil
Expand Down
Loading