Skip to content

Commit

Permalink
Add FXIOS-9309 - Download PDF Main Menu (mozilla-mobile#20754)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Dervishi <[email protected]>
  • Loading branch information
DanielDervishi and Daniel Dervishi authored Jun 25, 2024
1 parent 032be95 commit 541c821
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ extension BrowserViewController: TabToolbarDelegate, PhotonActionSheetProtocol {
}

// MARK: - ToolbarActionMenuDelegate
extension BrowserViewController: ToolBarActionMenuDelegate {
extension BrowserViewController: ToolBarActionMenuDelegate, UIDocumentPickerDelegate {
func updateToolbarState() {
updateToolbarStateForTraitCollection(view.traitCollection)
}
Expand Down Expand Up @@ -361,4 +361,17 @@ extension BrowserViewController: ToolBarActionMenuDelegate {
flowType: fxaParameters.flowType,
referringPage: fxaParameters.referringPage)
}

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
if !urls.isEmpty {
showToast(message: .AppMenu.AppMenuDownloadPDFConfirmMessage, toastAction: .downloadPDF)
}
}

func showFilePicker(fileURL: URL) {
let documentPicker = UIDocumentPickerViewController(forExporting: [fileURL], asCopy: true)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
showViewController(viewController: documentPicker)
}
}
22 changes: 22 additions & 0 deletions firefox-ios/Client/Frontend/Browser/MainMenuActionHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protocol ToolBarActionMenuDelegate: AnyObject {
func showZoomPage(tab: Tab)
func showCreditCardSettings()
func showSignInView(fxaParameters: FxASignInViewParameters)
func showFilePicker(fileURL: URL)
}

extension ToolBarActionMenuDelegate {
Expand All @@ -44,6 +45,7 @@ enum MenuButtonToastAction {
case pinPage
case removePinPage
case closeTab
case downloadPDF
}

/// MainMenuActionHelper handles the main menu (hamburger menu) in the toolbar.
Expand Down Expand Up @@ -269,6 +271,13 @@ class MainMenuActionHelper: PhotonActionSheetProtocol,
let sendToDeviceAction = getSendToDevice()
append(to: &section, action: sendToDeviceAction)

if let tab = self.selectedTab,
let url = tab.canonicalURL?.displayURL,
url.lastPathComponent.suffix(4) == ".pdf"{
let downloadPDFAction = getDownloadPDFAction()
append(to: &section, action: downloadPDFAction)
}

let shareAction = getShareAction()
append(to: &section, action: shareAction)
}
Expand Down Expand Up @@ -603,6 +612,19 @@ class MainMenuActionHelper: PhotonActionSheetProtocol,
}.items
}

private func getDownloadPDFAction() -> PhotonRowActions {
return SingleActionViewModel(title: .AppMenu.AppMenuDownloadPDF,
iconString: StandardImageIdentifiers.Large.folder) { _ in
guard let tab = self.selectedTab, let temporaryDocument = tab.temporaryDocument else { return }
temporaryDocument.getURL { fileURL in
DispatchQueue.main.async {
guard let fileURL = fileURL else {return}
self.delegate?.showFilePicker(fileURL: fileURL)
}
}
}.items
}

// Main menu option Share page with when opening a file
private func share(fileURL: URL, buttonView: UIView) {
TelemetryWrapper.recordEvent(category: .action, method: .tap, object: .sharePageWith)
Expand Down
10 changes: 10 additions & 0 deletions firefox-ios/Client/Frontend/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3776,6 +3776,16 @@ extension String {
tableName: nil,
value: "Downloads",
comment: "Label for the button, displayed in the menu, takes you to Downloads screen when pressed.")
public static let AppMenuDownloadPDF = MZLocalizedString(
key: "Menu.DownloadPDF.Label.v129",
tableName: "Menu",
value: "Download PDF",
comment: "Label for the button, displayed in the menu, downloads a pdf when pressed.")
public static let AppMenuDownloadPDFConfirmMessage = MZLocalizedString(
key: "Menu.DownloadPDF.Confirm.v129",
tableName: "Menu",
value: "Successfully Downloaded PDF",
comment: "Toast displayed to user after downlaod pdf was pressed.")
public static let AppMenuPasswords = MZLocalizedString(
key: "Menu.Passwords.Label",
tableName: nil,
Expand Down

0 comments on commit 541c821

Please sign in to comment.