Skip to content

Commit

Permalink
[feature/sharing-user-groups] Implementation of Sharing with Users, G…
Browse files Browse the repository at this point in the history
…roups and Remote Users, Public Links (#358)

* #351 added first draft of Sharing with users, groups, remotes

* - changes for shared with user handling
- new toggle action
- set permissions (unfinished)

* - added icon in file list, if item is shared
- handling shared by me and shared with me in file detail view
- disable permission editing, if user is not the owner
- delete receipient
- added sorting by "shared" in file list

* setting permissions is now working

* using correct sdk commit

* changed query, if item is shared

* - search for recipients
- add recipient to share

* removed deleted SharingSearchResults Controller

* - removed unneeded elements
- fixes for recipients search

* - fixed crash on adding recipient to share
- added header title to search recipients

* - added activity view when searching shares
- refactored code

* fixed Theming for searchBar and selecting rows

* - moved MessageView to own class
- fixed keyboard height constraint in MessageView
- added localization strings
- fixed updating shares handler

* - Add menu: left aligned text, added icons
- More menu: left aligned text, added icons
- fixes for UI glitches in more menu (correct height)
- fixed wrong table header height in MoreStaticTableViewController, for sections without section title
- close more menu before opening sharing overview

* - fixed missing sharing row
- fixed tint color for image

* - changed image alignment
- updated to new sharing SDK (which fixes update notification)

* - fixed wrong usage of Sharing SDK-API
- added delete recipient by swiping in overview

* - fixed delete recipient, only if user has permissions
- new function to detect if user can edit OCShare

* added activity indicator to searchbar

* - implemented public link sharing (WIP)
- updated localization

* - fixed date picker row disable handling
- fixed password row

* - using new SDK with support share.protectedByPassword
- code cleanup

* removed merging with master problems

* - password fixed
- setting permissons
- datepicker: themed, autolayout
- main thread fixes

* - fixed creating public link
- only show "Create Public Link" if item has sharing permission

* added capability support for sharing/public links

* - fixed missing expire date switch
- fixed deleting share receipients

* - fixed wrong sharing logic
- code cleanup

* - fixed keyboard focus for searchbar
- fixed first new public link share was not shown
- added expire date, protected by password in public link details

* - changed sharing icon
- new icon in file list for public links
- no longer use folder sharing icon in file list
- left aligned icons in action menu
- show always icons for sharing/public links in action menu

* code refactoring

* - using new SDK, which fixes URL encoding problems
- multiline for detailtext in table row

* - determine, if an item is shared by user or group
- removed share polling in Action
- stop share polling, if view was dismissed

* - added an action event, when the text field action should be performed
- perform password field action, if editing finished

* added action event for name text field

* - fixed, when showing share rows
- code refactoring

* code refactoring

* - fixed setting share permissions for edit row
- code refactoring

* - changed edit permissions handling (only show change, create, delete if edit is enabled)
- code refactoring
- removed unneeded code

* use correct new created share

* - added item header to sharing overview
- using new SDK with API v2 and additional receipient info

* fixed searchDisplayName

* - use new SDK, which supports pending shares, ...
- implemented pending shares
- new library tab bar item, which holds pending shares and all other shares as file list
- decline a share from sharing view

* set correct table row titles

* - changed Library to Quick Access
- added new Custom Filelist, to show items for custom OCQuery like Recents, Favorites, Images, PDFs, ...
- fixed crash

* - added pending cloud shares
- added search bar to customfilelist controller
- added message view to customfilelist controller
- fixed on main thread crash

* added accepted cloud shares, to "Shared with me"

* - using new SDK with fixed Favorite support
- added setting favorite state in MoreHeader
- added copy private link to public link view
- added refresh interval for OCShareQuery in library view
- code refactoring

* - fixed group sharing
- resolved merge problems
- do not auto add new public link
- removed message view

* fixed main thread crash

* - show shared items only unique, if it was shared to more receipients
- changed favorite button tint color

* code refactoring from code review

* code refactoring for code review

* - added missing localization strings
- removed swift lint warnings

* - subclass for ClientItemCell, which retrieves OCItem by OCShare path and tracks updates for OCItem
- added a represented object to send updated shares to an open SharesFilelistTableViewController

* - using new SDK with refresh for favorites support
- implemented favorites refresh on load and on pull to refresh
- set tint color for sectionIndex

* set default values from OCShare until OCItem is loaded

* - added themable background to custom file list
- removed iPad form sheet presentation style for sharing views
- fixed crash on BreadCrumb selection, if index does not exists

* code review changes

* - added header title to "Copy URL" table view row, to show the link URL (private and public)
- show a "Create Public Link" button row, if no public link exists in overview

* show header label as multiline, because of long urls

* - fixed setting favorite state
- code review changes

* fixed updating preferred content size in cardview for shares

* show image (group, person) for recipient search results

* added missing translation string from clear storage

* mostly retain cycles, fixed cardViewController content size, constraints fixed, clean up duplicated code

* new wording for sharing and some logical changes for sharing UI

* fixed failed merge conflicts

* - creating shares and public links needs confirmation, before creating
- fixed some wording
- fixed missing open-in image

* disable table scrolling for quick access view

* - fixed constraint problems
- auto updating share state in file list
- changed some sharing wording
- show rejected pending shares
- fixed initale share permissions

* If link will be created, share button is not needed

* - fixed wording
- setting default permissions for sharing
- do not show decline action for declined shares

* - Break various retain cycles

* - Add missing constraint to UITableViewController+Extension.swift

* - Refactor item lists to new class tree:
        - FileListTableViewController
                - SharesFilelistTableViewController
        - QueryFileListTableViewController
                - ClientQueryViewController
                - CustomFileListTableViewController
- Restructure source file locations

* - Adding missing copyright notes, minor improvements

* - Continue refactoring of file lists
	- move pull-to-refresh to root level (and add option to disable it)
		- add completion block for custom pull-to-refresh actions
	- move queryProgressSummary to root query level (and add option to disable it)
- Theme fixes

* - Fix accepted cloud shares being dropped if the list of items shared with the user changes
- Renamed updateLibrary() to setupLibrary() to emphasize the method's run-only-once character

* - Fix issues in LibraryTableViewController
	- fixed visibility of sharing section
	- fixed updates to sharing section
	- fixed merge of .sharedWithUser and .acceptedCloudShares queries
- Partial refactor of LibraryTableViewController
- Adding StaticTableViewSection.remove(rowWithIdentifier:)

* - simplify .filter() blocks
- fix refresh bugs in LibraryTableViewController
	- refactor around the concept of "views"
	- add LibraryShareList protocol and LibraryShareView class to LibraryTableViewController and
- LibrarySharesTableViewController
	- update to accept updates and update their content (via LibraryShareList conformance)
- PendingSharesTableViewController
	- update to accept updates and update their content (via LibraryShareList conformance)
	- fix filtering of pending and accepted shares
	- only pop view controller when there are no longer any shares in it (previously popped after every decision)
	- ask to confirm declines in all cases
	- rename declined to rejected shares
- Fix bugs in federated shares support
	- Action.shareRows() now shows "Shared by remote@host" for remote shares
	- OCCore.unifiedShares is now parallelized and also fetches accepted cloud shares
	- GroupSharingTableViewController now shows "Unshare" for remote shares as well
- Add support for unsharing accepted federated shares
- stop queries of SharingTableViewController subclasses on deist
- fix more retain cycles

* - Add "Pending" placeholder for negative item sizes

* - Rename CustomFileListTableViewController to LibraryFilesTableViewController
- Rename GroupSharingEditUserGroupsTableViewController to GroupSharingEditTableViewController
- Editing some OCSharePermissionsMask usages to be more Swifty
- Use instance variables for sections in GroupSharingTableViewController
- Move some additional code from GroupSharingTableViewController and PublicLinkTableViewController to SharingTableViewController
- Fix bug in GroupSharingTableViewController that failed to retrieve the correct share for a row (by using StaticTableViewRow.representedObject)
- Refactored PublicLinkTableViewController to use StaticTableViewRow.representedObject for shares as well
- Turn OCShare.permissionDescription into a property
- Fix a crash bug in StaticTableViewController and increase its swiftiness
- Improved some locales

* - Consolidate NSLayoutConstraint activation in HeaderActionTableViewCell.swift and MessageView.swift

* code review changes
- changed private link section
- public link row changed
- setting default permissions for new shares

* - Update SDK
- Add UIImage padding method to create padded versions of images easily
- Use new padding method to generate equally-width images for the More view

* - Remove non-existant TVG file references

* fixed QA finding (2):
- swipe card to top displaced icon on top and bottom menu item
- changed constraints

* QA finding (2)
- changed sticky table section header to non sticky by changing from plain to grouped table view
- remove footer view in MoreStaticTableViewController to remove gap between sections in grouped style

* QA finding (3) exclude current collaborators from recipient search

* QA finding (7) fixed setting edit permissions and hide/show/selecting the UI

* - Refactor ClientDirectoryPickerViewController to follow best practices and add support for a ClientDirectoryPickerAllowedPathFilter block to control which directories are selectable, and which are not
- Remove code to selectively show actions depending on whether the root directory contains folders

* QA finding (8): remove race condition for permission changes

* - Added ClientDirectoryPickerViewController.navigationPathFilter to allow applying additional constraints on which folders can be navigated to
- Add new convenience initializer to ClientDirectoryPickerViewController to avoid path conflicts - used by Copy and Move action

* QA finding (12) fixed inherit correct resharing permissions
- fixed showing reshares

* QA finding (13) fixed, long filenames and date is now visible

* - added "Invite Collaborator", if item is not shared to overview
- added Owner to share overview
- changed wording
- changed decline handling

* only show decline alert, if share is remote type

* - Fixing ClientRootViewController issues
	- not showing the bookmark editing UI when tapping "Edit" after being informed of authentication not being valid
	- closeClient() calling the completion handler when done, but before the presenting view controller could present the next view controller
- Update ios-sdk to address sharing requests ability to hinder OCCore from shutting down

* - Updated ios-sdk adding recursive deletion of items in the metaData cache

* - added possibility to retrieve more text field delegate actions
- setting default link fixed
- fixed crash on empty link name

* fixed wording

* - setting default expire date
- scroll date picker to visible index path

* changed wording "Save" to "Create"

* fixed removing expiration date

* - fixed counting default link name
- new label for copy links (not finished yet)

* fixed setting expiration date in create mode

* QA finding 25:  if password is required, hide password switch and show secure text field

* QA finding (12) fixed hiding UI elements, if resharing is not allowed
 - fixed pending badge (only count pending items)

* QA finding (15) (16) changed behavior of copy link

* new unshare extension, which is showing in card menu instead of delete menu item, if item is shared to user

* new wording for sharing an item

* fixed text color in search text field

* fixed disable password switch for initial setup, if password is enforced

* fixed enumeration of public link names

* if public link name is empty, use token as name in overview

* hide permission "Share" in description, if resharing capability is not enabled

* new SDK for fixing the default expiration date (was not set before in SDK)

* unshare cloud shares fixed

* update share queries, after accept/decline remote share

* new traitCollection for vertical compact size class, because labels were hidden in landscape view

* - fixed large titles in child view controller
- fixed header view color, when switching to a child view controller

* fixed adding default expiration dates to current date

* - Update ios-sdk to address issue (30) in #358

* - Fix issue (10) in #358 via SDK

* fixed QA finding (32), that only one pending invite was shown, if more exists

* fixed QA finding (27), MessageView has a left and right padding, which showed the content above

* - Correctly handle local user names ending with an "@" (via SDK update)

* - Added OCItem array extension .sharedWithUser
- Fixed retain cycle
- Code cosmetics

* - Added new OCItem.shareRootItem(from: core) and OCItem.isShareRootItem(from: core) methods
- Adapted DeleteAction and UnshareAction so that deletion is available inside shared folders where the owner allowed deletion

* fixed QA finding (35), show options, if not set in default permission list

* - enable "Links" menu item, if public link sharing is disabled
- disable public link section, if not enabled

* - only show link menu item, if bookmark is online
- do not show share menu item, if sharing api is disabled
  • Loading branch information
hosy authored Jun 8, 2019
1 parent f8f6b99 commit 0bd5944
Show file tree
Hide file tree
Showing 91 changed files with 5,518 additions and 812 deletions.
114 changes: 99 additions & 15 deletions ownCloud.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions ownCloud/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
OCExtensionManager.shared.addExtension(CopyAction.actionExtension)
OCExtensionManager.shared.addExtension(UploadFileAction.actionExtension)
OCExtensionManager.shared.addExtension(UploadMediaAction.actionExtension)
OCExtensionManager.shared.addExtension(UnshareAction.actionExtension)

Theme.shared.activeCollection = ThemeCollection(with: ThemeStyle.preferredStyle)

Expand Down
16 changes: 8 additions & 8 deletions ownCloud/Bookmarks/BookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ class BookmarkViewController: StaticTableViewController {
saveBarButtonItem.accessibilityIdentifier = "save-bar-button"

// Name section + row
nameRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender) in
if let textField = sender as? UITextField {
nameRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender, action) in
if let textField = sender as? UITextField, action == .changed {
self?.bookmark?.name = (textField.text?.count == 0) ? nil : textField.text
}
}, placeholder: "Name".localized, identifier: "row-name-name", accessibilityLabel: "Server name".localized)

nameSection = StaticTableViewSection(headerTitle: "Name".localized, footerTitle: nil, identifier: "section-name", rows: [ nameRow! ])

// URL section + row
urlRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender) in
if let textField = sender as? UITextField {
urlRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender, action) in
if let textField = sender as? UITextField, action == .changed {
var placeholderString = "Name".localized
var changedBookmark = false

Expand Down Expand Up @@ -161,15 +161,15 @@ class BookmarkViewController: StaticTableViewController {
urlSection = StaticTableViewSection(headerTitle: "Server URL".localized, footerTitle: nil, identifier: "section-url", rows: [ urlRow! ])

// Credentials section + rows
usernameRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender) in
if (sender as? UITextField) != nil, self?.bookmark?.authenticationData != nil {
usernameRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender, action) in
if (sender as? UITextField) != nil, self?.bookmark?.authenticationData != nil, action == .changed {
self?.bookmark?.authenticationData = nil
self?.composeSectionsAndRows(animated: true)
}
}, placeholder: "Username".localized, autocorrectionType: .no, identifier: "row-credentials-username", accessibilityLabel: "Server Username".localized)

passwordRow = StaticTableViewRow(secureTextFieldWithAction: { [weak self] (_, sender) in
if (sender as? UITextField) != nil, self?.bookmark?.authenticationData != nil {
passwordRow = StaticTableViewRow(secureTextFieldWithAction: { [weak self] (_, sender, action) in
if (sender as? UITextField) != nil, self?.bookmark?.authenticationData != nil, action == .changed {
self?.bookmark?.authenticationData = nil
self?.composeSectionsAndRows(animated: true)
}
Expand Down
187 changes: 179 additions & 8 deletions ownCloud/Client/Actions/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,47 @@ class Action : NSObject {
}

// MARK: - Provide Card view controller
class func cardViewController(for item: OCItem, with context: ActionContext, progressHandler: ActionProgressHandler? = nil, completionHandler: ((Action, Error?) -> Void)? = nil) -> UIViewController {

class func cardViewController(for item: OCItem, with context: ActionContext, progressHandler: ActionProgressHandler? = nil, completionHandler: ((Action, Error?) -> Void)? = nil) -> UIViewController? {
guard let core = context.core else { return nil }

let tableViewController = MoreStaticTableViewController(style: .grouped)
let header = MoreViewHeader(for: item, with: context.core!)
let moreViewController = MoreViewController(item: item, core: context.core!, header: header, viewController: tableViewController)
let header = MoreViewHeader(for: item, with: core)
let moreViewController = MoreViewController(item: item, core: core, header: header, viewController: tableViewController)

if core.connectionStatus == .online {
if core.connection.capabilities?.sharingAPIEnabled == 1 {
OnMainThread {
if item.isSharedWithUser || item.isShared {
let progressView = UIActivityIndicatorView(style: Theme.shared.activeCollection.activityIndicatorViewStyle)
progressView.startAnimating()

let row = StaticTableViewRow(rowWithAction: nil, title: "Searching Shares…".localized, alignment: .left, accessoryView: progressView, identifier: "share-searching")
let placeholderRow = StaticTableViewRow(rowWithAction: nil, title: "", alignment: .left, identifier: "share-empty-searching")
self.updateSharingSection(sectionIdentifier: "share-section", rows: [placeholderRow, row], tableViewController: tableViewController, contentViewController: moreViewController)

core.unifiedShares(for: item, completionHandler: { (shares) in
OnMainThread {
let shareRows = self.shareRows(shares: shares, item: item, presentingController: moreViewController, context: context)
self.updateSharingSection(sectionIdentifier: "share-section", rows: shareRows, tableViewController: tableViewController, contentViewController: moreViewController)
}
})
}
}
} else {
if let publicLinkRow = self.shareAsPublicLinkRow(item: item, presentingController: moreViewController, context: context) {
tableViewController.insertSection(StaticTableViewSection(headerTitle: nil, footerTitle: nil, identifier: "share-section", rows: [publicLinkRow]), at: 0, animated: false)
}
}
}

let title = NSAttributedString(string: "Actions".localized, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20, weight: .heavy)])

let actions = Action.sortedApplicableActions(for: context)

actions.forEach({
$0.actionWillRunHandler = {
moreViewController.dismiss(animated: true)
$0.actionWillRunHandler = { [weak moreViewController] in
moreViewController?.dismiss(animated: true)
}

$0.progressHandler = progressHandler
Expand Down Expand Up @@ -243,11 +271,13 @@ class Action : NSObject {
}

// MARK: - Action UI elements
private static let staticRowImageWidth : CGFloat = 32

func provideStaticRow() -> StaticTableViewRow? {
return StaticTableViewRow(buttonWithAction: { (_ row, _ sender) in
self.willRun()
self.run()
}, title: actionExtension.name, style: actionExtension.category == .destructive ? .destructive : .plain, identifier: actionExtension.identifier.rawValue)
}, title: actionExtension.name, style: actionExtension.category == .destructive ? .destructive : .plain, image: self.icon, imageWidth: Action.staticRowImageWidth, alignment: .left, identifier: actionExtension.identifier.rawValue)
}

func provideContextualAction() -> UIContextualAction? {
Expand All @@ -259,10 +289,20 @@ class Action : NSObject {
}

func provideAlertAction() -> UIAlertAction? {
return UIAlertAction(title: self.actionExtension.name, style: actionExtension.category == .destructive ? .destructive : .default, handler: { (_ alertAction) in
let alertAction = UIAlertAction(title: self.actionExtension.name, style: actionExtension.category == .destructive ? .destructive : .default, handler: { (_ alertAction) in
self.willRun()
self.run()
})

let image = self.icon
if alertAction.responds(to: NSSelectorFromString("setImage:")) {
alertAction.setValue(image, forKey: "image")
}
if alertAction.responds(to: NSSelectorFromString("_setTitleTextAlignment:")) {
alertAction.setValue(CATextLayerAlignmentMode.left, forKey: "titleTextAlignment")
}

return alertAction
}

// MARK: - Action metadata
Expand All @@ -272,7 +312,7 @@ class Action : NSObject {

var icon : UIImage? {
if let locationIdentifier = context.location?.identifier {
return Action.iconForLocation(locationIdentifier)
return type(of: self).iconForLocation(locationIdentifier)
}

return nil
Expand All @@ -281,4 +321,135 @@ class Action : NSObject {
var position : ActionPosition {
return type(of: self).applicablePosition(forContext: context)
}

}

// MARK: - Sharing

private extension Action {

class func shareRows(shares: [OCShare], item: OCItem, presentingController: UIViewController, context: ActionContext) -> [StaticTableViewRow] {
var shareRows: [StaticTableViewRow] = []

var userTitle = ""
var linkTitle = ""
var hasUserGroupSharing = false
var hasLinkSharing = false

if item.isSharedWithUser {
// find shares by others
if let itemOwner = item.owner, itemOwner.isRemote, let ownerName = itemOwner.displayName ?? itemOwner.userName {
// - remote shares
userTitle = String(format: "Shared by %@".localized, ownerName)
hasUserGroupSharing = true
} else {
// - local shares
for share in shares {
if let ownerName = share.itemOwner?.displayName {
userTitle = String(format: "Shared by %@".localized, ownerName)
hasUserGroupSharing = true
break
}
}
}
} else {
// find Shares by me
let privateShares = shares.filter { (share) -> Bool in
return share.type != .link
}

if privateShares.count > 0 {
let title = ((privateShares.count > 1) ? "Recipients" : "Recipient").localized

userTitle = "\(privateShares.count) \(title)"
hasUserGroupSharing = true
}
}

// find Public link shares
let linkShares = shares.filter { (share) -> Bool in
return share.type == .link
}
if linkShares.count > 0 {
let title = ((linkShares.count > 1) ? "Links" : "Link").localized

linkTitle.append("\(linkShares.count) \(title)")
hasLinkSharing = true
}

if hasUserGroupSharing {
let addGroupRow = StaticTableViewRow(rowWithAction: { [weak presentingController, weak context] (_, _) in
if let context = context, let presentingController = presentingController, let core = context.core {
let sharingViewController = GroupSharingTableViewController(core: core, item: item)
sharingViewController.shares = shares

self.dismiss(presentingController: presentingController, andPresent: sharingViewController, on: context.viewController)
}
}, title: userTitle, subtitle: nil, image: UIImage(named: "group"), imageWidth: Action.staticRowImageWidth, alignment: .left, accessoryType: .disclosureIndicator)
shareRows.append(addGroupRow)
} else if item.isShareable {
shareRows.append(self.shareAsGroupRow(item: item, presentingController: presentingController, context: context))
}

if hasLinkSharing, let core = context.core, core.connection.capabilities?.publicSharingEnabled == true {
let addGroupRow = StaticTableViewRow(rowWithAction: { [weak presentingController, weak context] (_, _) in
if let context = context, let presentingController = presentingController {
let sharingViewController = PublicLinkTableViewController(core: core, item: item)
sharingViewController.shares = shares

self.dismiss(presentingController: presentingController, andPresent: sharingViewController, on: context.viewController)
}
}, title: linkTitle, subtitle: nil, image: UIImage(named: "link"), imageWidth: Action.staticRowImageWidth, alignment: .left, accessoryType: .disclosureIndicator)
shareRows.append(addGroupRow)
} else if let publicLinkRow = self.shareAsPublicLinkRow(item: item, presentingController: presentingController, context: context) {
shareRows.append(publicLinkRow)
}

return shareRows
}

private class func updateSharingSection(sectionIdentifier: String, rows: [StaticTableViewRow], tableViewController: MoreStaticTableViewController, contentViewController: MoreViewController) {
if let section = tableViewController.sectionForIdentifier(sectionIdentifier) {
tableViewController.removeSection(section)
}
if rows.count > 0 {
tableViewController.insertSection(MoreStaticTableViewSection(identifier: "share-section", rows: rows), at: 0, animated: false)
}
}

private class func shareAsGroupRow(item : OCItem, presentingController: UIViewController, context: ActionContext) -> StaticTableViewRow {
let title = ((item.type == .collection) ? "Share this folder" : "Share this file").localized

let addGroupRow = StaticTableViewRow(buttonWithAction: { [weak presentingController, weak context] (_, _) in
if let context = context, let presentingController = presentingController, let core = context.core {
self.dismiss(presentingController: presentingController,
andPresent: GroupSharingTableViewController(core: core, item: item),
on: context.viewController)
}
}, title: title, style: .plain, image: UIImage(named: "group"), imageWidth: Action.staticRowImageWidth, alignment: .left, identifier: "share-add-group")

return addGroupRow
}

private class func shareAsPublicLinkRow(item : OCItem, presentingController: UIViewController, context: ActionContext) -> StaticTableViewRow? {
let addGroupRow = StaticTableViewRow(buttonWithAction: { [weak presentingController, weak context] (_, _) in
if let context = context, let presentingController = presentingController, let core = context.core {
self.dismiss(presentingController: presentingController,
andPresent: PublicLinkTableViewController(core: core, item: item),
on: context.viewController)
}
}, title: "Links".localized, style: .plain, image: UIImage(named: "link"), imageWidth: Action.staticRowImageWidth, alignment: .left, identifier: "share-add-group")

return addGroupRow
}

private class func dismiss(presentingController: UIViewController, andPresent viewController: UIViewController, on hostViewController: UIViewController?) {
presentingController.dismiss(animated: true)

guard let hostViewController = hostViewController else { return }

let navigationController = ThemeNavigationController(rootViewController: viewController)

hostViewController.present(navigationController, animated: true, completion: nil)
}
}
22 changes: 9 additions & 13 deletions ownCloud/Client/Actions/Actions+Extensions/CopyAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ class CopyAction : Action {
override class var name : String? { return "Copy".localized }
override class var locations : [OCExtensionLocationIdentifier]? { return [.moreItem, .moreFolder, .toolbar] }

// MARK: - Extension matching
override class func applicablePosition(forContext: ActionContext) -> ActionPosition {
if forContext.items.contains(where: {$0.type == .file}),
let path = forContext.query?.queryPath, path.isRootPath,
let containsFolder = forContext.preferences?["containsFolders"] as? Bool, !containsFolder {
return .none
}
// Examine items in context
return .middle
}

// MARK: - Action implementation
override func run() {
guard context.items.count > 0, let viewController = context.viewController, let core = self.core else {
Expand All @@ -45,8 +34,7 @@ class CopyAction : Action {

let items = context.items

let directoryPickerViewController = ClientDirectoryPickerViewController(core: core, path: "/", selectButtonTitle: "Copy here", completion: { (selectedDirectory) in

let directoryPickerViewController = ClientDirectoryPickerViewController(core: core, path: "/", selectButtonTitle: "Copy here".localized, avoidConflictsWith: items, choiceHandler: { (selectedDirectory) in
if let targetDirectory = selectedDirectory {
items.forEach({ (item) in

Expand All @@ -68,4 +56,12 @@ class CopyAction : Action {
let pickerNavigationController = ThemeNavigationController(rootViewController: directoryPickerViewController)
viewController.present(pickerNavigationController, animated: true)
}

override class func iconForLocation(_ location: OCExtensionLocationIdentifier) -> UIImage? {
if location == .moreItem {
return UIImage(named: "copy-file")
}

return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CreateFolderAction : Action {
}

override class func iconForLocation(_ location: OCExtensionLocationIdentifier) -> UIImage? {
if location == .toolbar {
if location == .toolbar || location == .plusButton {
return Theme.shared.image(for: "folder-create", size: CGSize(width: 30.0, height: 30.0))!.withRenderingMode(.alwaysTemplate)
}

Expand Down
19 changes: 18 additions & 1 deletion ownCloud/Client/Actions/Actions+Extensions/DeleteAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ class DeleteAction : Action {

// MARK: - Extension matching
override class func applicablePosition(forContext: ActionContext) -> ActionPosition {
// Examine items in context
let sharedWithUser = forContext.items.sharedWithUser

if let core = forContext.core {
for sharedItem in sharedWithUser {
if sharedItem.isShareRootItem(from: core) {
return .none
}
}
}

return .last
}

Expand Down Expand Up @@ -84,4 +93,12 @@ class DeleteAction : Action {
viewController.present(alertController, animated: true)

}

override class func iconForLocation(_ location: OCExtensionLocationIdentifier) -> UIImage? {
if location == .moreItem {
return UIImage(named: "trash")
}

return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class DuplicateAction : Action {
override class var category : ActionCategory? { return .normal }
override class var name : String? { return "Duplicate".localized }
override class var locations : [OCExtensionLocationIdentifier]? { return [.moreItem, .moreFolder, .toolbar] }
var remainingItems : [OCItem] = []

// MARK: - Extension matching
override class func applicablePosition(forContext: ActionContext) -> ActionPosition {
Expand Down Expand Up @@ -106,4 +105,12 @@ class DuplicateAction : Action {

self.completed()
}

override class func iconForLocation(_ location: OCExtensionLocationIdentifier) -> UIImage? {
if location == .moreItem {
return UIImage(named: "duplicate-file")
}

return nil
}
}
Loading

0 comments on commit 0bd5944

Please sign in to comment.