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

Commit

Permalink
Extracting Navigation functions to BVController
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Jul 6, 2021
1 parent cfea616 commit ae762a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
24 changes: 5 additions & 19 deletions Client/Application/Shortcuts/ActivityShortcutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum ActivityType: String {
case openPlayList = "OpenPlayList"

var identifier: String {
return " \(Bundle.main.bundleIdentifier ?? "") + .\(self.rawValue)"
return "\(Bundle.main.bundleIdentifier ?? "").\(self.rawValue)"
}

/// The activity title for designated type
Expand Down Expand Up @@ -120,29 +120,15 @@ class ActivityShortcutManager: NSObject {
case .newPrivateTab:
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: true)
case .clearBrowsingHistory:
History.deleteAll {
bvc.tabManager.clearTabHistory() {
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: false)
}
}
bvc.clearHistoryAndOpenNewTab()
case .enableBraveVPN:
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: false)

switch BraveVPN.vpnState {
case .notPurchased, .purchased, .expired:
guard let vc = BraveVPN.vpnState.enableVPNDestinationVC else { return }
guard let enableVPNController = BraveVPN.vpnState.enableVPNDestinationVC else { return }

let settingsNavigationController = SettingsNavigationController(rootViewController: vc)
settingsNavigationController.isModalInPresentation = false
settingsNavigationController.modalPresentationStyle =
UIDevice.current.userInterfaceIdiom == .phone ? .pageSheet : .formSheet
settingsNavigationController.navigationBar.topItem?.leftBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .done, target: settingsNavigationController, action: #selector(settingsNavigationController.done))

// All menu views should be opened in portrait on iPhones.
UIDevice.current.forcePortraitIfIphone(for: UIApplication.shared)

bvc.present(settingsNavigationController, animated: true)
bvc.openInsideSettingsNavigation(with: enableVPNController)
case .installed(let connected):
if !connected {
BraveVPN.reconnect()
Expand Down Expand Up @@ -192,7 +178,7 @@ class ActivityShortcutManager: NSObject {
let intent = createCustomIntent(for: type, with: urlString)

let interaction = INInteraction(intent: intent, response: nil)
interaction.donate { (error) in
interaction.donate { error in
guard let error = error else {
return
}
Expand Down
24 changes: 24 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,30 @@ class BrowserViewController: UIViewController {
}
}
}

func clearHistoryAndOpenNewTab() {
History.deleteAll { [weak self] in
guard let self = self else { return }

self.tabManager.clearTabHistory() {
self.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: false)
}
}
}

func openInsideSettingsNavigation(with viewController: UIViewController) {
let settingsNavigationController = SettingsNavigationController(rootViewController: viewController)
settingsNavigationController.isModalInPresentation = false
settingsNavigationController.modalPresentationStyle =
UIDevice.current.userInterfaceIdiom == .phone ? .pageSheet : .formSheet
settingsNavigationController.navigationBar.topItem?.leftBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .done, target: settingsNavigationController, action: #selector(settingsNavigationController.done))

// All menu views should be opened in portrait on iPhones.
UIDevice.current.forcePortraitIfIphone(for: UIApplication.shared)

present(settingsNavigationController, animated: true)
}

func popToBVC() {
guard let currentViewController = navigationController?.topViewController else {
Expand Down

0 comments on commit ae762a9

Please sign in to comment.