Skip to content

Commit

Permalink
use modern UIMenu group's QR code viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jan 24, 2025
1 parent 51d1ba2 commit 08a59db
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions deltachat-ios/Controller/QrViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class QrViewController: UIViewController {
private let contentScrollView: UIScrollView
private let qrContentView: UIImageView
private let shareLinkButton: UIButton
private let moreButton: UIBarButtonItem

private lazy var moreButton: UIBarButtonItem = {
let moreButtonImage = UIImage(systemName: "ellipsis.circle")
return UIBarButtonItem(image: moreButtonImage, menu: showMoreOptions())
}()

var verticalCenterConstraint: NSLayoutConstraint?
var contentTopAnchor: NSLayoutConstraint?
Expand Down Expand Up @@ -49,17 +53,12 @@ class QrViewController: UIViewController {
contentScrollView.translatesAutoresizingMaskIntoConstraints = false
contentScrollView.addSubview(contentStackView)

let moreButtonImage = UIImage(systemName: "ellipsis.circle")
moreButton = UIBarButtonItem(image: moreButtonImage, style: .plain, target: nil, action: nil)

super.init(nibName: nil, bundle: nil)

view.backgroundColor = DcColors.defaultBackgroundColor

title = String.localized("qrshow_title")
navigationItem.rightBarButtonItem = moreButton
moreButton.action = #selector(QrViewController.showMoreOptions(_:))
moreButton.target = self
shareLinkButton.addTarget(self, action: #selector(QrViewController.shareInviteLink(_:)), for: .touchUpInside)
shareLinkButton.setTitleColor(DcColors.primary, for: .normal)

Expand Down Expand Up @@ -143,26 +142,32 @@ class QrViewController: UIViewController {
}

// Only relevant for GroupChatDetails, for QR-Code-Tab, this gets handled by QrPageController
@objc private func showMoreOptions(_ sender: Any) {
let alert = UIAlertController(title: String.localized("qrshow_title"), message: nil, preferredStyle: .safeActionSheet)
alert.addAction(UIAlertAction(title: String.localized("menu_share"), style: .default, handler: share(_:)))
alert.addAction(UIAlertAction(title: String.localized("menu_copy_to_clipboard"), style: .default, handler: copyToClipboard(_:)))
alert.addAction(UIAlertAction(title: String.localized("withdraw_qr_code"), style: .default, handler: withdrawQrCode(_:)))
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
private func showMoreOptions() -> UIMenu {
let actions = [
UIAction(title: String.localized("menu_share")) { [weak self] _ in
self?.share()
},
UIAction(title: String.localized("menu_copy_to_clipboard")) { [weak self] _ in
self?.copyToClipboard()
},
UIAction(title: String.localized("withdraw_qr_code")) { [weak self] _ in
self?.withdrawQrCode()
},
]
return UIMenu(children: actions)
}

@objc func share(_ action: UIAlertAction) {
func share() {
if let inviteLink = Utils.getInviteLink(context: dcContext, chatId: chatId) {
Utils.share(url: inviteLink, parentViewController: self, sourceItem: moreButton)
}
}

@objc func copyToClipboard(_ action: UIAlertAction) {
func copyToClipboard() {
UIPasteboard.general.string = Utils.getInviteLink(context: dcContext, chatId: chatId)
}

@objc func withdrawQrCode(_ action: UIAlertAction) {
func withdrawQrCode() {
let groupName = dcContext.getChat(chatId: chatId).name
let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("withdraw_verifygroup_explain"), groupName),
message: nil, preferredStyle: .alert)
Expand Down

0 comments on commit 08a59db

Please sign in to comment.