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

Commit

Permalink
Fixing Merge conflicts and adjustment menu options action using new m…
Browse files Browse the repository at this point in the history
…enu UI
  • Loading branch information
soner-yuksel committed May 26, 2021
1 parent cccf424 commit bf06fd4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ import Shared
extension BrowserViewController {
func featuresMenuSection(_ menuController: MenuViewController) -> some View {
VStack(spacing: 0) {
VPNMenuButton(vpnProductInfo: self.vpnProductInfo) { vc in
(self.presentedViewController as? MenuViewController)?
.pushViewController(vc, animated: true)
}
VPNMenuButton(vpnProductInfo: self.vpnProductInfo,
displayVPNDestination: { vc in
(self.presentedViewController as? MenuViewController)?
.pushViewController(vc, animated: true)
},
enableInstalledVPN: { [unowned menuController] in
/// Donate Enable VPN Activity for suggestions
let enableVPNActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .enableBraveVPN)
menuController.userActivity = enableVPNActivity
enableVPNActivity.becomeCurrent()
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ extension BrowserViewController: PlaylistHelperDelegate {
private func openPlaylist() {
let playlistController = (UIApplication.shared.delegate as? AppDelegate)?.playlistRestorationController ?? PlaylistViewController()
playlistController.modalPresentationStyle = .fullScreen

/// Donate Open Playlist Activity for suggestions
let openPlaylist = ActivityShortcutManager.shared.createShortcutActivity(type: .openPlayList)
self.userActivity = openPlaylist
openPlaylist.becomeCurrent()

present(playlistController, animated: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco
if !self.isPrivateBrowsing {
ActivityShortcutManager.shared.donateCustomIntent(for: .openBookmarks, with: url.absoluteString)
}
self.toolbarUrlActionsDelegate?.select(url: url, visitType: .bookmark)
self.toolbarUrlActionsDelegate?.select(url: url, isBookmark: true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol

if let u = site?.url, let url = URL(string: u) {
dismiss(animated: true) {
/// Donate Custom Intent Open History
// Donate Custom Intent Open History
if !self.isPrivateBrowsing {
ActivityShortcutManager.shared.donateCustomIntent(for: .openHistory, with: url.absoluteString)
}

self.toolbarUrlActionsDelegate?.select(url: url, visitType: .typed)
self.toolbarUrlActionsDelegate?.select(url: url, isBookmark: false)
}
}
tableView.deselectRow(at: indexPath, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,52 +204,9 @@ extension MenuViewController: PanModalPresentable {
var allowsExtendedPanScrolling: Bool {
true
}

var cornerRadius: CGFloat {
10.0
}

private func openVPNAction(menuCell: MenuCell) {
let enabled = !menuCell.toggleButton.isOn
let vpnState = BraveVPN.vpnState

/// Connecting to the vpn takes a while, that's why we have to show a spinner until it finishes.
if enabled {
menuCell.isLoading = true
}

if !VPNProductInfo.isComplete {
let alert =
UIAlertController(title: Strings.VPN.errorCantGetPricesTitle,
message: Strings.VPN.errorCantGetPricesBody,
preferredStyle: .alert)
alert.addAction(.init(title: Strings.OKString, style: .default))
dismissView()
bvc.present(alert, animated: true)
// Reattempt to connect to the App Store to get VPN prices.
bvc.vpnProductInfo.load()
return
}

switch BraveVPN.vpnState {
case .notPurchased, .purchased, .expired:
guard let vc = vpnState.enableVPNDestinationVC else { return }
open(vc, doneButton: DoneButton(style: .cancel, position: .left), allowSwipeToDismiss: true)
case .installed:
// Do not modify UISwitch state here, update it based on vpn status observer.
if enabled {
BraveVPN.reconnect()

/// Donate Enable VPN Activity for suggestions
let enableVPNActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .enableBraveVPN)
self.userActivity = enableVPNActivity
enableVPNActivity.becomeCurrent()
} else {
BraveVPN.disconnect()
}
}
}

var anchorModalToLongForm: Bool {
isPresentingInnerMenu
}
Expand All @@ -260,20 +217,6 @@ extension MenuViewController: PanModalPresentable {
var dragIndicatorBackgroundColor: UIColor {
UIColor(white: 0.95, alpha: 1.0)
}

private func openPlaylist() {
let playlistController = (UIApplication.shared.delegate as? AppDelegate)?.playlistRestorationController ?? PlaylistViewController()
playlistController.modalPresentationStyle = .fullScreen

/// Donate Open Playlist Activity for suggestions
let openPlaylist = ActivityShortcutManager.shared.createShortcutActivity(type: .openPlayList)
self.userActivity = openPlaylist
openPlaylist.becomeCurrent()

dismissView()
bvc.present(playlistController, animated: true)
}

var transitionDuration: Double {
0.35
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ struct VPNMenuButton: View {
/// A closure executed when the parent must display a VPN-specific view controller due to some
/// user action
var displayVPNDestination: (UIViewController) -> Void
/// A closure executed when VPN is toggled and status is installed. This will be used to set
/// current activity for user
var enableInstalledVPN: () -> Void

@State private var isVPNStatusChanging: Bool = BraveVPN.reconnectPending
@State private var isVPNEnabled = BraveVPN.isConnected
Expand Down Expand Up @@ -43,7 +46,12 @@ struct VPNMenuButton: View {
case .installed:
isVPNStatusChanging = true
// Do not modify UISwitch state here, update it based on vpn status observer.
enabled ? BraveVPN.reconnect() : BraveVPN.disconnect()
if enabled {
BraveVPN.reconnect()
enableInstalledVPN()
} else {
BraveVPN.disconnect()
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ class SettingsViewController: TableViewController {
cellClass: MultilineValue1Cell.self),
.boolRow(title: Strings.bookmarksLastVisitedFolderTitle, option: Preferences.General.showLastVisitedBookmarksFolder, image: #imageLiteral(resourceName: "menu_folder_open").template),
Row(text: Strings.Shortcuts.shortcutSettingsTitle, selection: { [unowned self] in
let viewController = ShortcutSettingsViewController(self.theme)
self.navigationController?.pushViewController(viewController, animated: true)
self.navigationController?.pushViewController(ShortcutSettingsViewController(), animated: true)
}, image: #imageLiteral(resourceName: "settings-siri-shortcuts").template, accessory: .disclosureIndicator, cellClass: MultilineValue1Cell.self)
]
)
Expand Down
8 changes: 2 additions & 6 deletions Client/Frontend/Settings/ShortcutSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ import IntentsUI
// MARK: - ShortcutSettingsViewController

class ShortcutSettingsViewController: TableViewController {

let theme: Theme


// MARK: Lifecycle

init(_ theme: Theme) {
self.theme = theme

init() {
super.init(style: .insetGrouped)
}

Expand Down

0 comments on commit bf06fd4

Please sign in to comment.