Skip to content

Commit

Permalink
share webxdc's (#2015)
Browse files Browse the repository at this point in the history
* add 'Share' button to webxdc more-menu

* make share() in FilesViewController reusable, call share() from WebxdcViewController
  • Loading branch information
r10s authored Dec 11, 2023
1 parent a41923b commit 6ecc434
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions deltachat-ios/Controller/FilesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ extension FilesViewController {

func shareAttachment(of indexPath: IndexPath) {
let msgId = fileMessageIds[indexPath.row]
let message = dcContext.getMessage(id: msgId)
FilesViewController.share(message: dcContext.getMessage(id: msgId), parentViewController: self, sourceView: self.view)
}

public static func share(message: DcMsg, parentViewController: UIViewController, sourceView: UIView) {
let activityVC: UIActivityViewController
guard let fileURL = message.fileURL else { return }
let objectsToShare: [Any]
Expand All @@ -301,8 +304,8 @@ extension FilesViewController {

activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [.copyToPasteboard]
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completion: nil)
activityVC.popoverPresentationController?.sourceView = sourceView
parentViewController.present(activityVC, animated: true, completion: nil)
}
}

Expand Down
8 changes: 8 additions & 0 deletions deltachat-ios/Controller/WebxdcViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ class WebxdcViewController: WebViewViewController {
let sourceCodeAction = UIAlertAction(title: String.localized("source_code"), style: .default, handler: openUrl(_:))
alert.addAction(sourceCodeAction)
}

let shareAction = UIAlertAction(title: String.localized("menu_share"), style: .default, handler: shareWebxdc(_:))
alert.addAction(shareAction)

let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: nil)
Expand All @@ -418,6 +422,10 @@ class WebxdcViewController: WebViewViewController {
UIApplication.shared.open(url)
}
}

private func shareWebxdc(_ action: UIAlertAction) {
FilesViewController.share(message: dcContext.getMessage(id: messageId), parentViewController: self, sourceView: self.view)
}
}

extension WebxdcViewController: WKScriptMessageHandler {
Expand Down

0 comments on commit 6ecc434

Please sign in to comment.