Skip to content

Commit 77276c8

Browse files
NMC 1997 - Sharing customisation changes
1 parent 574812f commit 77276c8

10 files changed

Lines changed: 128 additions & 107 deletions

File tree

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
B5E2E6ED2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6EC2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib */; };
111111
B5E2E6EE2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6EB2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift */; };
112112
B5E2E6F02DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6EF2DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift */; };
113+
C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; };
113114
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
114115
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
115116
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
@@ -2135,6 +2136,7 @@
21352136
F34BDB3B2F574A58007A222C /* BidiSafeFilenameTests.swift */,
21362137
AA52EB452D42AC5A0089C348 /* Placeholder.swift */,
21372138
B5E2E6D32DAE52B500AB2EDD /* SharingTest.swift */,
2139+
AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */,
21382140
);
21392141
path = NextcloudUnitTests;
21402142
sourceTree = "<group>";

iOSClient/Activity/NCActivity.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class NCActivity: UIViewController, NCSharePagingContent {
3434
}
3535
}
3636
var dateAutomaticFetch: Date?
37+
private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
3738

3839
@MainActor
3940
var session: NCSession.Session {
@@ -100,6 +101,8 @@ class NCActivity: UIViewController, NCSharePagingContent {
100101
override func viewWillAppear(_ animated: Bool) {
101102
super.viewWillAppear(animated)
102103

104+
appDelegate.activeViewController = self
105+
navigationController?.setNavigationBarAppearance()
103106
fetchAll(isInitial: true)
104107
}
105108

@@ -130,14 +133,10 @@ class NCActivity: UIViewController, NCSharePagingContent {
130133

131134
let label = UILabel()
132135
label.font = UIFont.systemFont(ofSize: 15)
133-
label.textColor = NCBrandColor.shared.textColor2
136+
label.textColor = UIColor.systemGray
134137
label.textAlignment = .center
135138
label.text = NSLocalizedString("_no_activity_footer_", comment: "")
136139
view.addSubview(label)
137-
label.translatesAutoresizingMaskIntoConstraints = false
138-
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
139-
label.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
140-
label.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
141140

142141
return view
143142
}

iOSClient/Share/NCShare+Helper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class NCTableShareOptions: NCTableShareable {
9292
convenience init(sharee: NKSharee, metadata: tableMetadata, password: String?) {
9393
self.init(shareType: sharee.shareType, metadata: metadata, password: password)
9494
self.shareWith = sharee.shareWith
95+
self.shareWithDisplayname = sharee.label
9596
}
9697

9798
static func shareLink(metadata: tableMetadata, password: String?) -> NCTableShareOptions {

iOSClient/Share/NCShare.swift

Lines changed: 73 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -192,43 +192,10 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
192192
@objc func openShareProfile(_ sender: UITapGestureRecognizer) {
193193
self.showProfileMenu(userId: metadata.ownerId, session: session, sender: sender.view)
194194
}
195-
196-
@objc func keyboardWillShow(notification: Notification) {
197-
if UIDevice.current.userInterfaceIdiom == .phone {
198-
if (UIScreen.main.bounds.width < 374 || UIDevice.current.orientation.isLandscape) {
199-
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
200-
if view.frame.origin.y == 0 {
201-
self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
202-
self.view.frame.origin.y -= keyboardSize.height
203-
}
204-
}
205-
} else if UIScreen.main.bounds.height < 850 {
206-
if view.frame.origin.y == 0 {
207-
self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
208-
self.view.frame.origin.y -= 70
209-
}
210-
} else {
211-
if view.frame.origin.y == 0 {
212-
self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
213-
self.view.frame.origin.y -= 40
214-
}
215-
}
216-
}
217-
218-
if UIDevice.current.userInterfaceIdiom == .pad, UIDevice.current.orientation.isLandscape {
219-
if view.frame.origin.y == 0 {
220-
self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
221-
self.view.frame.origin.y -= 230
222-
}
223-
}
224-
textField?.layer.borderColor = NCBrandColor.shared.brand.cgColor
225-
}
226-
227-
@objc func keyboardWillHide(notification: Notification) {
228-
if view.frame.origin.y != 0 {
229-
self.view.frame.origin.y = 0
230-
}
231-
textField?.layer.borderColor = NCBrandColor.shared.label.cgColor
195+
196+
@objc func openShareProfile() {
197+
guard let metadata = metadata else { return }
198+
self.showProfileMenu(userId: metadata.ownerId, session: session)
232199
}
233200

234201
@objc func keyboardWillShow(notification: Notification) {
@@ -278,6 +245,9 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
278245
@objc func reloadData() {
279246
shares = self.database.getTableShares(metadata: metadata)
280247
shareLinksCount = 0
248+
// if let metadata = metadata {
249+
// shares = self.database.getTableShares(metadata: metadata)
250+
// }
281251
tableView.reloadData()
282252
}
283253

@@ -290,14 +260,29 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
290260
}
291261

292262
@IBAction func searchFieldDidChange(textField: UITextField) {
263+
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(searchSharees), object: nil)
293264
guard let searchString = textField.text else {return}
294265
if searchString.count == 0 {
295266
dropDown.hide()
296267
} else {
297-
networking?.getSharees(searchString: searchString)
268+
// networking?.getSharees(searchString: searchString)
269+
perform(#selector(searchSharees), with: nil, afterDelay: 0.5)
298270
}
299271
}
300272

273+
@objc private func searchSharees() {
274+
// https://stackoverflow.com/questions/25471114/how-to-validate-an-e-mail-address-in-swift
275+
func isValidEmail(_ email: String) -> Bool {
276+
277+
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
278+
let emailPred = NSPredicate(format: "SELF MATCHES %@", emailRegEx)
279+
return emailPred.evaluate(with: email)
280+
}
281+
guard let searchString = textField?.text, !searchString.isEmpty else { return }
282+
if searchString.contains("@"), !isValidEmail(searchString) { return }
283+
networking?.getSharees(searchString: searchString)
284+
}
285+
301286
@IBAction func createLinkClicked(_ sender: Any) {
302287
appDelegate?.adjust.trackEvent(TriggerEvent(CreateLink.rawValue))
303288
TealiumHelper.shared.trackEvent(title: "magentacloud-app.sharing.create", data: ["": ""])
@@ -307,7 +292,7 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
307292
@IBAction func touchUpInsideButtonMenu(_ sender: Any) {
308293

309294
guard let metadata = metadata else { return }
310-
let isFilesSharingPublicPasswordEnforced = NCGlobal.shared.capabilityFileSharingPubPasswdEnforced
295+
let isFilesSharingPublicPasswordEnforced = NCCapabilities.Capabilities().capabilityFileSharingPubPasswdEnforced
311296
let shares = NCManageDatabase.shared.getTableShares(metadata: metadata)
312297

313298
if isFilesSharingPublicPasswordEnforced && shares.firstShareLink == nil {
@@ -650,24 +635,43 @@ extension NCShare: UITableViewDataSource {
650635
cell.indexPath = indexPath
651636
cell.tableShare = tableShare
652637
cell.delegate = self
653-
cell.setupCellUI(titleAppendString: String(shareLinksCount))
654-
cell.menuButton.menu = NCContextMenuShare(share: tableShare, isDirectory: metadata.isDirectory, canReshare: canReshare, shareController: self, controller: controller).viewMenu()
655-
cell.menuButton.showsMenuAsPrimaryAction = true
656-
if tableShare.shareType == NKShare.ShareType.publicLink.rawValue { shareLinksCount += 1 }
657-
return cell
658-
}
659-
} else {
660-
// USER / GROUP etc.
661-
if let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell {
662-
cell.index = indexPath
663-
cell.tableShare = tableShare
664-
cell.isDirectory = metadata.directory
665-
cell.delegate = self
666-
cell.setupCellUI(userId: session.userId, session: session, metadata: metadata)
667-
668-
cell.buttonMenu.menu = NCContextMenuShare(share: tableShare, isDirectory: metadata.isDirectory, canReshare: canReshare, shareController: self, controller: controller).viewMenu()
669-
cell.buttonMenu.showsMenuAsPrimaryAction = true
670-
638+
//<<<<<<< HEAD
639+
// cell.setupCellUI(titleAppendString: String(shareLinksCount))
640+
// cell.menuButton.menu = NCContextMenuShare(share: tableShare, isDirectory: metadata.isDirectory, canReshare: canReshare, shareController: self, controller: controller).viewMenu()
641+
// cell.menuButton.showsMenuAsPrimaryAction = true
642+
// if tableShare.shareType == NKShare.ShareType.publicLink.rawValue { shareLinksCount += 1 }
643+
// return cell
644+
// }
645+
// } else {
646+
// // USER / GROUP etc.
647+
// if let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell {
648+
// cell.index = indexPath
649+
// cell.tableShare = tableShare
650+
// cell.isDirectory = metadata.directory
651+
// cell.delegate = self
652+
// cell.setupCellUI(userId: session.userId, session: session, metadata: metadata)
653+
//
654+
// cell.buttonMenu.menu = NCContextMenuShare(share: tableShare, isDirectory: metadata.isDirectory, canReshare: canReshare, shareController: self, controller: controller).viewMenu()
655+
// cell.buttonMenu.showsMenuAsPrimaryAction = true
656+
657+
cell.setupCellUI()
658+
if !tableShare.label.isEmpty {
659+
cell.labelTitle.text = String(format: NSLocalizedString("_share_linklabel_", comment: ""), tableShare.label)
660+
} else {
661+
cell.labelTitle.text = directory ? NSLocalizedString("_share_link_folder_", comment: "") : NSLocalizedString("_share_link_file_", comment: "")
662+
}
663+
// cell.setupCellUI(userId: session.userId)
664+
let isEditingAllowed = shareCommon.isEditingEnabled(isDirectory: directory, fileExtension: metadata?.fileExtension ?? "", shareType: tableShare.shareType)
665+
if isEditingAllowed || directory || checkIsCollaboraFile() {
666+
cell.btnQuickStatus.isEnabled = true
667+
cell.labelQuickStatus.textColor = NCBrandColor.shared.brand
668+
cell.imageDownArrow.image = UIImage(named: "downArrow")?.imageColor(NCBrandColor.shared.brand)
669+
} else {
670+
cell.btnQuickStatus.isEnabled = false
671+
cell.labelQuickStatus.textColor = NCBrandColor.shared.optionItem
672+
cell.imageDownArrow.image = UIImage(named: "downArrow")?.imageColor(NCBrandColor.shared.optionItem)
673+
}
674+
671675
return cell
672676
} else {
673677
// USER / GROUP etc.
@@ -705,18 +709,23 @@ extension NCShare: UITableViewDataSource {
705709
headerView.updateCanReshareUI()
706710

707711

708-
if FileManager.default.fileExists(atPath: utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata?.ocId ?? "", etag: metadata?.etag ?? "")) {
709-
headerView.fullWidthImageView.image = UIImage(contentsOfFile: utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata?.ocId ?? "", etag: metadata?.etag ?? ""))
712+
if let image = NCUtility().getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024) {
713+
headerView.fullWidthImageView.image = image
714+
// headerView.fullWidthImageView.image = UIImage(contentsOfFile: utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata?.ocId ?? "", etag: metadata?.etag ?? ""))
710715
headerView.fullWidthImageView.contentMode = .scaleAspectFill
711716
headerView.imageView.isHidden = true
712717
} else {
713718
if metadata?.directory ?? false {
714-
let image = (metadata?.e2eEncrypted ?? false) ? UIImage(named: "folderEncrypted") : UIImage(named: "folder_nmcloud")
719+
let image = (metadata?.e2eEncrypted ?? false) ? NCImageCache.shared.getFolderEncrypted() : NCImageCache.shared.getFolder()
715720
headerView.imageView.image = image
716721
} else if !(metadata?.iconName.isEmpty ?? false) {
717-
headerView.imageView.image = metadata!.fileExtension == "odg" ? UIImage(named: "file-diagram") : UIImage.init(named: metadata!.iconName)
722+
if let image = UIImage.init(named: metadata!.iconName) {
723+
headerView.imageView.image = metadata!.fileExtension == "odg" ? UIImage(named: "diagram") : image
724+
} else {
725+
headerView.imageView.image = metadata!.fileExtension == "odg" ? UIImage(named: "diagram") : NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account)
726+
}
718727
} else {
719-
headerView.imageView.image = UIImage(named: "file")
728+
headerView.imageView.image = NCImageCache.shared.getImageFile()
720729
}
721730
}
722731

@@ -732,10 +741,10 @@ extension NCShare: UITableViewDataSource {
732741

733742
}
734743
func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
735-
return metadata?.ownerId != appDelegate?.userId ? canReshare ? 400 : 350 : 320
744+
return metadata?.ownerId != session?.userId ? canReshare ? 400 : 350 : 320
736745
}
737746
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
738-
return metadata?.ownerId != appDelegate?.userId ? canReshare ? UITableView.automaticDimension : 350 : 320
747+
return metadata?.ownerId != session?.userId ? canReshare ? UITableView.automaticDimension : 350 : 320
739748
}
740749
}
741750

iOSClient/Share/NCShareCommon.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ enum NCShareCommon {
112112
}
113113

114114
func isCurrentUserIsFileOwner(fileOwnerId: String) -> Bool {
115-
if let currentUser = NCManageDatabase.shared.getActiveAccount(), currentUser.userId == fileOwnerId {
115+
if let currentUser = NCManageDatabase.shared.getActiveTableAccount(), currentUser.userId == fileOwnerId {
116116
return true
117117
}
118118
return false

iOSClient/Share/NCShareHeader.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class NCShareAdvancePermissionHeader: UIView {
5454
imageView.isHidden = true
5555
} else {
5656
if metadata.directory {
57-
imageView.image = UIImage.init(named: "folder")
57+
imageView.image = metadata.e2eEncrypted ? NCImageCache.shared.getFolderEncrypted() : NCImageCache.shared.getFolder()
5858
} else if !metadata.iconName.isEmpty {
59-
imageView.image = UIImage.init(named: metadata.iconName)
59+
imageView.image = NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account)
6060
} else {
61-
imageView.image = UIImage.init(named: "file")
61+
imageView.image = NCImageCache.shared.getImageFile()
6262
}
6363
}
6464

iOSClient/Share/NCShareLinkCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class NCShareLinkCell: UITableViewCell {
134134
buttonMenu.contentMode = .scaleAspectFill
135135
imageItem.image = UIImage(named: "sharebylink")?.image(color: NCBrandColor.shared.label, size: 30)
136136
buttonCopy.setImage(UIImage.init(named: "shareCopy")!.image(color: NCBrandColor.shared.customer, size: 24), for: .normal)
137-
buttonMenu.setImage(NCImageCache.images.buttonMore.image(color: NCBrandColor.shared.customer, size: 24), for: .normal)
137+
buttonMenu.setImage(UIImage.init(named: "shareMenu")!.image(color: NCBrandColor.shared.customer, size: 24), for: .normal)
138138
labelQuickStatus.textColor = NCBrandColor.shared.customer
139139
}
140140

0 commit comments

Comments
 (0)