Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move from UIAlertController to UIMenu
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Dec 2, 2023
commit 73c46a77340e12947977da23bd7a6df1d85ffb80
43 changes: 18 additions & 25 deletions NextcloudTalk/RoomSharedItemsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,6 @@ import QuickLook
self.getItemsOverview()
}

func presentItemTypeSelector() {
let itemTypesActionSheet = UIAlertController(title: NSLocalizedString("Shared items", comment: ""), message: nil, preferredStyle: .actionSheet)

for itemType in availableItemTypes() {
let itemTypeName = nameForItemType(itemType: itemType)
let action = UIAlertAction(title: itemTypeName, style: .default) { _ in
self.setupViewForItemType(itemType: itemType)
}

if itemType == currentItemType {
action.setValue(UIImage(named: "checkmark")?.withRenderingMode(_: .alwaysOriginal), forKey: "image")
}
itemTypesActionSheet.addAction(action)
}

itemTypesActionSheet.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil))

// Presentation on iPads
itemTypesActionSheet.popoverPresentationController?.sourceView = self.navigationItem.titleView
itemTypesActionSheet.popoverPresentationController?.sourceRect = self.navigationItem.titleView?.frame ?? CGRect()

self.present(itemTypesActionSheet, animated: true, completion: nil)
}

func availableItemTypes() -> [String] {
var availableItemTypes: [String] = []
for itemType in sharedItemsOverview.keys {
Expand Down Expand Up @@ -183,8 +159,25 @@ import QuickLook
itemTypeSelectorButton.setTitle(buttonTitle, for: .normal)
itemTypeSelectorButton.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .medium)
itemTypeSelectorButton.setTitleColor(NCAppBranding.themeTextColor(), for: .normal)
itemTypeSelectorButton.addTarget(self, action: #selector(presentItemTypeSelector), for: .touchUpInside)
self.navigationItem.titleView = itemTypeSelectorButton

var menuActions: [UIAction] = []

for itemType in availableItemTypes() {
let itemTypeName = nameForItemType(itemType: itemType)
let action = UIAction(title: itemTypeName, image: nil) { [unowned self] _ in
self.setupViewForItemType(itemType: itemType)
}

if itemType == currentItemType {
action.state = .on
}

menuActions.append(action)
}

itemTypeSelectorButton.showsMenuAsPrimaryAction = true
itemTypeSelectorButton.menu = UIMenu(children: menuActions)
}

func showFetchingItemsPlaceholderView() {
Expand Down