Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 4 additions & 9 deletions iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NCFiles: NCCollectionViewCommon {
let account = userInfo["account"] as? String,
self.controller?.account == account {
// re-tint the + button
self.mainNavigationController?.menuPlusButton.setPlusButtonColor(NCBrandColor.shared.getElement(account: account))
self.mainNavigationController?.menuPlus?.updatePlusButtonEnabled(session: NCSession.shared.getSession(account: account))
}
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ class NCFiles: NCCollectionViewCommon {
if let userInfo = notification.userInfo,
let account = userInfo["account"] as? String {
// re-tint the + button for the new account
self.mainNavigationController?.menuPlusButton.setPlusButtonColor(NCBrandColor.shared.getElement(account: account))
self.mainNavigationController?.menuPlus?.updatePlusButtonEnabled(session: NCSession.shared.getSession(account: account))
}

self.navigationController?.popToRootViewController(animated: false)
Expand Down Expand Up @@ -139,13 +139,8 @@ class NCFiles: NCCollectionViewCommon {
if let metadataFolder {
nkLog(info: "Inside metadata folder \(metadataFolder.fileName) with permissions: \(metadataFolder.permissions)")

// disable + button if no create permission
let color = NCBrandColor.shared.getElement(account: self.session.account)

if let menuPlusButton = self.mainNavigationController?.menuPlusButton {
menuPlusButton.isEnabled = metadataFolder.isCreatable
menuPlusButton.setPlusButtonColor(metadataFolder.isCreatable ? color : .lightGray)
}
// disable + button if no create permission or E2EE offline
self.mainNavigationController?.menuPlus?.updatePlusButtonEnabled(session: self.session)
}

let metadatas = await self.database.getMetadatasAsyncDataSource(withServerUrl: self.serverUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
self.layoutForView = self.database.getLayoutForView(account: session.account, key: layoutKey, serverUrl: serverUrl)
// is a Directory E2EE
if isSearchingMode {
self.isDirectoryE2EE = false
self.isCurrentDirectoryE2EE = false
} else {
self.isDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(serverUrl: serverUrl, urlBase: session.urlBase, userId: session.userId, account: session.account)
self.isCurrentDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(serverUrl: serverUrl, urlBase: session.urlBase, userId: session.userId, account: session.account)
}
return self.dataSource.numberOfItemsInSection(section)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
let metadata = self.dataSource.getMetadata(indexPath: indexPath) ?? tableMetadata()

// E2EE create preview
if self.isDirectoryE2EE,
if self.isCurrentDirectoryE2EE,
metadata.isImageOrVideo,
!utilityFileSystem.fileProviderStorageImageExists(metadata.ocId, etag: metadata.etag, userId: metadata.userId, urlBase: metadata.urlBase) {
utility.createImageFileFrom(metadata: metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
internal var backgroundImageView = UIImageView()
internal var serverUrl: String = ""
internal var isEditMode = false
internal var isDirectoryE2EE = false
// whether the displayed folder is E2EE; refreshed on each collection view data-source pass
internal var isCurrentDirectoryE2EE = false
internal var fileSelect: [String] = []
internal var metadataFolder: tableMetadata?
internal var richWorkspaceText: String?
Expand Down
23 changes: 22 additions & 1 deletion iOSClient/Main/NCMainNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NCMainNavigationController: UINavigationController, UINavigationController
let utility = NCUtility()
let utilityFileSystem = NCUtilityFileSystem()
let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
let menuPlusButton = UIButton(type: .system)
let menuPlusButton: UIButton = NCMenuPlusButton(type: .system)

var controller: NCMainTabBarController? {
self.tabBarController as? NCMainTabBarController
Expand Down Expand Up @@ -451,6 +451,27 @@ class NCMainNavigationController: UINavigationController, UINavigationController
}
}

private final class NCMenuPlusButton: UIButton {
// Keep hit testing so taps don't fall through if the button is disabled, hidden or low alpha.
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if let view = super.hitTest(point, with: event) {
return view
}

guard !isEnabled, !isHidden, alpha >= 0.01, bounds.contains(point) else {
return nil
}
Comment thread
mpivchev marked this conversation as resolved.

return self
}

override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
guard isEnabled else { return nil }

return super.contextMenuInteraction(interaction, configurationForMenuAtLocation: location)
}
}

extension UIButton {
func setPlusButtonColor(_ color: UIColor) {
if #available(iOS 26.0, *) {
Expand Down
31 changes: 28 additions & 3 deletions iOSClient/Menu/NCContextMenuPlus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,43 @@ class NCContextMenuPlus: NSObject {
let plusMenu = UIMenu(children: plusMenuElements)

// PLUS BUTTON
updatePlusButtonEnabled(session: session)

if menuPlusButton.menu != nil,
!capabilitiesChanged {
return
}

menuPlusButton.menu = plusMenu
menuPlusButton.showsMenuAsPrimaryAction = true
menuPlusButton.setPlusButtonColor(NCBrandColor.shared.getElement(account: session.account))
menuPlusButton.alpha = 1
}

func updatePlusButtonEnabled(session: NCSession.Session) {
guard let controller, let menuPlusButton else {
return
}

let isEnabled = isPlusButtonEnabled(for: controller)

menuPlusButton.isEnabled = isEnabled
menuPlusButton.setPlusButtonColor(isEnabled ? NCBrandColor.shared.getElement(account: session.account) : .lightGray)
}

private func isPlusButtonEnabled(for controller: NCMainTabBarController) -> Bool {
guard let metadataFolder = (controller.currentViewController() as? NCCollectionViewCommon)?.metadataFolder else {
return true
}

guard metadataFolder.isCreatable else {
return false
}

guard metadataFolder.e2eEncrypted else {
return true
}

// E2EE Offline disable
menuPlusButton.isEnabled = isNetworkReachable || !isDirectoryE2EE
return NextcloudKit.shared.isNetworkReachable()
}

@MainActor
Expand Down
Loading