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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate {
Task {
let metadatas = getSelectedMetadatas()
for metadata in metadatas where metadata.lock == isAnyLocked {
self.networking.lockUnlockFile(metadata, shoulLock: !isAnyLocked)
self.networking.lockUnlockFile(metadata, shouldLock: !isAnyLocked)
}
await setEditMode(false)
}
Expand Down
43 changes: 24 additions & 19 deletions iOSClient/Menu/ContextMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,29 @@ enum ContextMenuActions {
}
}

static func lockUnlock(shouldLock: Bool,
metadatas: [tableMetadata],
completion: (() -> Void)? = nil) -> UIAction {
let titleKey: String
if metadatas.count == 1 {
titleKey = shouldLock ? "_lock_file_" : "_unlock_file_"
} else {
titleKey = shouldLock ? "_lock_selected_files_" : "_unlock_selected_files_"
}
static func lockUnlock(isLocked: Bool,
metadata: tableMetadata,
completion: (() -> Void)? = nil) -> UIAction {
let titleKey: String
var subtitleKey: String = ""
let image: UIImage?
if !metadata.canUnlock(as: metadata.userId), isLocked {
titleKey = String(format: NSLocalizedString("_locked_by_", comment: ""), metadata.lockOwnerDisplayName)
image = UIImage(systemName: "lock")
} else {
titleKey = isLocked ? "_unlock_file_" : "_lock_file_"
image = UIImage(systemName: isLocked ? "lock.open" : "lock")
subtitleKey = !metadata.lockOwnerDisplayName.isEmpty ? String(format: NSLocalizedString("_locked_by_", comment: ""), metadata.lockOwnerDisplayName) : ""
}

return UIAction(
title: NSLocalizedString(titleKey, comment: ""),
image: UIImage(systemName: shouldLock ? "lock" : "lock.open")
) { _ in
for metadata in metadatas where metadata.lock != shouldLock {
NCNetworking.shared.lockUnlockFile(metadata, shoulLock: shouldLock)
}
completion?()
}
}
return UIAction(
title: NSLocalizedString(titleKey, comment: ""),
subtitle: subtitleKey,
image: image,
attributes: metadata.canUnlock(as: metadata.userId) ? [] : [.disabled]
) { _ in
NCNetworking.shared.lockUnlockFile(metadata, shouldLock: !isLocked)
completion?()
}
}
}
49 changes: 32 additions & 17 deletions iOSClient/Menu/NCContextMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
return UIMenu()
}

// Build top menu items
let detail = makeDetailAction(metadata: metadata)
let favorite = makeFavoriteAction(metadata: metadata)
let share = makeShareAction()
let topMenuItems = buildTopMenuItems(metadata: metadata)

let mainActionsMenu = buildMainActionsMenu(
metadata: metadata,
Expand All @@ -49,21 +46,39 @@

let deleteMenu = buildDeleteMenu(metadata: metadata)

if !NCNetworking.shared.isOnline {
return UIMenu()
}

// Assemble final menu
if NCNetworking.shared.isOnline {
let baseChildren = [
UIMenu(title: "", options: .displayInline, children: mainActionsMenu),
UIMenu(title: "", options: .displayInline, children: clientIntegrationMenu),
UIMenu(title: "", options: .displayInline, children: deleteMenu)
]
let baseChildren = [
UIMenu(title: "", options: .displayInline, children: mainActionsMenu),
UIMenu(title: "", options: .displayInline, children: clientIntegrationMenu),
UIMenu(title: "", options: .displayInline, children: deleteMenu)
]

let finalMenu = UIMenu(title: "", children: (metadata.lock ? [detail] : [detail, share, favorite]) + baseChildren)
finalMenu.preferredElementSize = .medium
let finalMenu = UIMenu(title: "", children: topMenuItems + baseChildren)
finalMenu.preferredElementSize = .medium // top menu items are shown in a short format style

return finalMenu
} else {
return UIMenu()
return finalMenu
}

// MARK: Top Menu Items

private func buildTopMenuItems(metadata: tableMetadata, appending items: [UIMenuElement] = []) -> [UIMenuElement] {
var topActionsMenu: [UIMenuElement] = []

if metadata.canShare {
topActionsMenu.append(makeShareAction())
}

topActionsMenu.append(makeDetailAction(metadata: metadata))

if !metadata.lock {
topActionsMenu.append(makeFavoriteAction(metadata: metadata))
}

return topActionsMenu
}

// MARK: Basic Actions
Expand Down Expand Up @@ -121,10 +136,9 @@
// Lock/Unlock
if NCNetworking.shared.isOnline,
!metadata.directory,
metadata.canUnlock(as: metadata.userId),
!capabilities.filesLockVersion.isEmpty {
mainActionsMenu.append(
ContextMenuActions.lockUnlock(shouldLock: !metadata.lock, metadatas: [metadata])
ContextMenuActions.lockUnlock(isLocked: metadata.lock, metadata: metadata)
)
}

Expand Down Expand Up @@ -565,3 +579,4 @@
return clientIntegrationMenu
}
}

Check warning on line 582 in iOSClient/Menu/NCContextMenu.swift

View workflow job for this annotation

GitHub Actions / Lint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
2 changes: 1 addition & 1 deletion iOSClient/Menu/NCMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ extension NCMenuAction {
sender: sender,
action: { _ in
for metadata in metadatas where metadata.lock != shouldLock {
NCNetworking.shared.lockUnlockFile(metadata, shoulLock: shouldLock)
NCNetworking.shared.lockUnlockFile(metadata, shouldLock: shouldLock)
}
completion?()
}
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Networking/NCNetworking+WebDAV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ extension NCNetworking {

// MARK: - Lock Files

func lockUnlockFile(_ metadata: tableMetadata, shoulLock: Bool) {
NextcloudKit.shared.lockUnlockFile(serverUrlFileName: metadata.serverUrlFileName, shouldLock: shoulLock, account: metadata.account) { task in
func lockUnlockFile(_ metadata: tableMetadata, shouldLock: Bool) {
NextcloudKit.shared.lockUnlockFile(serverUrlFileName: metadata.serverUrlFileName, shouldLock: shouldLock, account: metadata.account) { task in
Task {
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: metadata.account,
path: metadata.serverUrlFileName,
Expand Down
Loading