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

Commit

Permalink
Fix when closing a blank tab it destroys playlist url bar button.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Aug 19, 2021
1 parent b512d61 commit fa0b27e
Showing 1 changed file with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@ private let log = Logger.browserLogger
extension BrowserViewController: PlaylistHelperDelegate {

func updatePlaylistURLBar(tab: Tab?, state: PlaylistItemAddedState, item: PlaylistInfo?) {
openInPlayListActivity(info: state == .existingItem ? item : nil)
addToPlayListActivity(info: state == .newItem ? item : nil, itemDetected: state == .newItem)
// `tab` is nil when closed, along with the `.none` state and nil `item`
guard let tab = tab else { return }

switch state {
case .none:
topToolbar.menuButton.removeBadge(.playlist, animated: true)
toolbar?.menuButton.removeBadge(.playlist, animated: true)
case .newItem, .existingItem:
topToolbar.menuButton.addBadge(.playlist, animated: true)
toolbar?.menuButton.addBadge(.playlist, animated: true)
}

if let tab = tab, tab === tabManager.selectedTab {
if tab === tabManager.selectedTab {
openInPlayListActivity(info: state == .existingItem ? item : nil)
addToPlayListActivity(info: state == .newItem ? item : nil, itemDetected: state == .newItem)

tab.playlistItemState = state
tab.playlistItem = item

Expand All @@ -35,15 +29,17 @@ extension BrowserViewController: PlaylistHelperDelegate {
switch state {
case .none:
playlistButton.buttonState = .none
topToolbar.menuButton.removeBadge(.playlist, animated: true)
toolbar?.menuButton.removeBadge(.playlist, animated: true)
case .newItem:
playlistButton.buttonState = shouldShowPlaylistURLBarButton ? .addToPlaylist : .none
topToolbar.menuButton.addBadge(.playlist, animated: true)
toolbar?.menuButton.addBadge(.playlist, animated: true)
case .existingItem:
playlistButton.buttonState = shouldShowPlaylistURLBarButton ? .addedToPlaylist : .none
topToolbar.menuButton.addBadge(.playlist, animated: true)
toolbar?.menuButton.addBadge(.playlist, animated: true)
}
} else {
topToolbar.locationView.playlistButton.buttonState = .none
topToolbar.menuButton.removeBadge(.playlist, animated: true)
toolbar?.menuButton.removeBadge(.playlist, animated: true)
}
}

Expand Down Expand Up @@ -118,11 +114,11 @@ extension BrowserViewController: PlaylistHelperDelegate {
guard let item = selectedTab.playlistItem else { return }
UIImpactFeedbackGenerator(style: .medium).bzzt()

self.dismiss(animated: true) {
DispatchQueue.main.async {
if PlaylistManager.shared.delete(item: item) {
self.updatePlaylistURLBar(tab: tab, state: .newItem, item: item)
}
self.dismiss(animated: true)

DispatchQueue.main.async {
if PlaylistManager.shared.delete(item: item) {
self.updatePlaylistURLBar(tab: tab, state: .newItem, item: item)
}
}
}
Expand Down

0 comments on commit fa0b27e

Please sign in to comment.