Skip to content

Commit

Permalink
coding
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Oct 19, 2023
1 parent 64ab158 commit bfa7bfe
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 131 deletions.
8 changes: 4 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
F70753EB2542A99800972D44 /* NCViewerMediaPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70753EA2542A99800972D44 /* NCViewerMediaPage.swift */; };
F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70753F02542A9A200972D44 /* NCViewerMedia.swift */; };
F70753F72542A9C000972D44 /* NCViewerMediaPage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F70753F62542A9C000972D44 /* NCViewerMediaPage.storyboard */; };
F7075B672AE15F6200512300 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; };
F7075B682AE15F8100512300 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; };
F707C26521A2DC5200F6181E /* NCStoreReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = F707C26421A2DC5200F6181E /* NCStoreReview.swift */; };
F70821D829E59E6D001CA2D7 /* TagListView in Frameworks */ = {isa = PBXBuildFile; productRef = F70821D729E59E6D001CA2D7 /* TagListView */; };
F70968A424212C4E00ED60E5 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; };
Expand Down Expand Up @@ -214,7 +216,6 @@
F72944F52A8424F800246839 /* NCEndToEndMetadataV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72944F42A8424F800246839 /* NCEndToEndMetadataV1.swift */; };
F72944F62A8424F800246839 /* NCEndToEndMetadataV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72944F42A8424F800246839 /* NCEndToEndMetadataV1.swift */; };
F72A17D828B221E300F3F159 /* DashboardWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72A17D728B221E300F3F159 /* DashboardWidgetView.swift */; };
F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */; };
F72AD70D28C24B93006CB92D /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = F72AD70C28C24B93006CB92D /* NextcloudKit */; };
F72AD70F28C24BA1006CB92D /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = F72AD70E28C24BA1006CB92D /* NextcloudKit */; };
F72AD71128C24BBB006CB92D /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = F72AD71028C24BBB006CB92D /* NextcloudKit */; };
Expand Down Expand Up @@ -975,7 +976,6 @@
F72944F12A84246400246839 /* NCEndToEndMetadataV20.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadataV20.swift; sourceTree = "<group>"; };
F72944F42A8424F800246839 /* NCEndToEndMetadataV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadataV1.swift; sourceTree = "<group>"; };
F72A17D728B221E300F3F159 /* DashboardWidgetView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashboardWidgetView.swift; sourceTree = "<group>"; };
F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCOperationQueue.swift; sourceTree = "<group>"; };
F72CD63925C19EBF00F46F9A /* NCAutoUpload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUpload.swift; sourceTree = "<group>"; };
F72D1005210B6882009C96B7 /* NCPushNotificationEncryption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCPushNotificationEncryption.m; sourceTree = "<group>"; };
F72D1006210B6882009C96B7 /* NCPushNotificationEncryption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCPushNotificationEncryption.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1891,7 +1891,6 @@
F75A9EE523796C6F0044CFCE /* NCNetworking.swift */,
F7D96FCB246ED7E100536D73 /* NCNetworkingCheckRemoteUser.swift */,
F70D8D8024A4A9BF000A5756 /* NCNetworkingProcessUpload.swift */,
F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */,
F755BD9A20594AC7008C5FBB /* NCService.swift */,
F77BC3EC293E528A005F2B08 /* NCConfigServer.swift */,
);
Expand Down Expand Up @@ -3549,6 +3548,7 @@
F72EA95A28B7BD0D00C88F0C /* FilesWidgetView.swift in Sources */,
F78302FE28B4C44700B84583 /* NCBrand.swift in Sources */,
F749B64B297B0CBB00087535 /* NCManageDatabase+Share.swift in Sources */,
F7075B682AE15F8100512300 /* NCCellProtocol.swift in Sources */,
F7817CF929801A3500FFBC65 /* Data+Extension.swift in Sources */,
F7864ACD2A78FE73004870E0 /* NCManageDatabase+LocalFile.swift in Sources */,
F343A4B42A1E084100DDA874 /* PHAsset+Extension.swift in Sources */,
Expand Down Expand Up @@ -3631,6 +3631,7 @@
F343A4BF2A1E734600DDA874 /* Optional+Extension.swift in Sources */,
AF4BF62027562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */,
F785EEA62461A4FB00B3F945 /* CCUtility.m in Sources */,
F7075B672AE15F6200512300 /* NCCellProtocol.swift in Sources */,
F73ADD2226554FD10069EA0D /* NCContentPresenter.swift in Sources */,
F72FD3B9297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */,
);
Expand Down Expand Up @@ -3673,7 +3674,6 @@
F79EDAA326B004980007D134 /* NCPlayerToolBar.swift in Sources */,
F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */,
F77BB74A2899857B0090FC19 /* UINavigationController+Extension.swift in Sources */,
F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,
F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */,
F76B649C2ADFFAED00014640 /* NCMediaCache.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Activity/NCActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extension NCActivity: UITableViewDataSource {

// Image
let fileName = appDelegate.userBaseUrl + "-" + comment.actorId + ".png"
NCOperationQueue.shared.downloadAvatar(user: comment.actorId, dispalyName: comment.actorDisplayName, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: comment.actorId, dispalyName: comment.actorDisplayName, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
// Username
cell.labelUser.text = comment.actorDisplayName
cell.labelUser.textColor = .label
Expand Down Expand Up @@ -279,7 +279,7 @@ extension NCActivity: UITableViewDataSource {

let fileName = appDelegate.userBaseUrl + "-" + activity.user + ".png"

NCOperationQueue.shared.downloadAvatar(user: activity.user, dispalyName: nil, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: activity.user, dispalyName: nil, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
}

// subject
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
if !metadata.iconUrl.isEmpty {
if let ownerId = NCUtility.shared.getAvatarFromIconUrl(metadata: metadata), let cell = cell as? NCCellProtocol {
let fileName = metadata.userBaseUrl + "-" + ownerId + ".png"
NCOperationQueue.shared.downloadAvatar(user: ownerId, dispalyName: nil, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.filePreviewImageView)
NCNetworking.shared.downloadAvatar(user: ownerId, dispalyName: nil, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.filePreviewImageView)
}
}
}
Expand All @@ -1250,7 +1250,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
appDelegate.account == metadata.account,
let cell = cell as? NCCellProtocol {
let fileName = metadata.userBaseUrl + "-" + metadata.ownerId + ".png"
NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.fileAvatarImageView)
}
}

Expand Down
76 changes: 76 additions & 0 deletions iOSClient/Networking/NCNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,26 @@ class NCNetworking: NSObject, NKCommonDelegate {
}
}

#if !EXTENSION
func downloadAvatar(user: String, dispalyName: String?, fileName: String, cell: NCCellProtocol, view: UIView?, cellImageView: UIImageView?) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName

if let image = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
cellImageView?.image = image
cell.fileAvatarImageView?.image = image
return
}

if let account = NCManageDatabase.shared.getActiveAccount() {
cellImageView?.image = NCUtility.shared.loadUserImage(for: user, displayName: dispalyName, userBaseUrl: account)
}

for case let operation as NCOperationDownloadAvatar in appDelegate.downloadAvatarQueue.operations where operation.fileName == fileName { return }
appDelegate.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: user, fileName: fileName, fileNameLocalPath: fileNameLocalPath, cell: cell, view: view, cellImageView: cellImageView))
}
#endif

// MARK: - Upload

func upload(metadata: tableMetadata,
Expand Down Expand Up @@ -1672,3 +1692,59 @@ class NCOperationDownload: ConcurrentOperation {
}
}
}

class NCOperationDownloadAvatar: ConcurrentOperation {

var user: String
var fileName: String
var etag: String?
var fileNameLocalPath: String
var cell: NCCellProtocol!
var view: UIView?
var cellImageView: UIImageView?

init(user: String, fileName: String, fileNameLocalPath: String, cell: NCCellProtocol, view: UIView?, cellImageView: UIImageView?) {
self.user = user
self.fileName = fileName
self.fileNameLocalPath = fileNameLocalPath
self.cell = cell
self.view = view
self.etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
self.cellImageView = cellImageView
}

override func start() {

guard !isCancelled else { return self.finish() }

NextcloudKit.shared.downloadAvatar(user: user,
fileNameLocalPath: fileNameLocalPath,
sizeImage: NCGlobal.shared.avatarSize,
avatarSizeRounded: NCGlobal.shared.avatarSizeRounded,
etag: self.etag,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imageAvatar, _, etag, error in

if error == .success, let imageAvatar = imageAvatar, let etag = etag {
NCManageDatabase.shared.addAvatar(fileName: self.fileName, etag: etag)
DispatchQueue.main.async {
if self.user == self.cell.fileUser, let avatarImageView = self.cellImageView {
UIView.transition(with: avatarImageView,
duration: 0.75,
options: .transitionCrossDissolve,
animations: { avatarImageView.image = imageAvatar },
completion: nil)
} else {
if self.view is UICollectionView {
(self.view as? UICollectionView)?.reloadData()
} else if self.view is UITableView {
(self.view as? UITableView)?.reloadData()
}
}
}
} else if error.errorCode == NCGlobal.shared.errorNotModified {
NCManageDatabase.shared.setAvatarLoaded(fileName: self.fileName)
}
self.finish()
}
}
}
120 changes: 0 additions & 120 deletions iOSClient/Networking/NCOperationQueue.swift

This file was deleted.

2 changes: 1 addition & 1 deletion iOSClient/Notification/NCNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
cell.avatar.image = image
} else if !FileManager.default.fileExists(atPath: fileNameLocalPath) {
cell.fileUser = user
NCOperationQueue.shared.downloadAvatar(user: user, dispalyName: json["user"]?["name"].string, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: user, dispalyName: json["user"]?["name"].string, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
}
}

Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Select/NCSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ extension NCSelect: UICollectionViewDataSource {
activeAccount.account == metadata.account,
let cell = cell as? NCCellProtocol {
let fileName = metadata.userBaseUrl + "-" + metadata.ownerId + ".png"
NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView, cellImageView: cell.fileAvatarImageView)
}
}

Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Share/NCShare.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ extension NCShare: UITableViewDataSource {
cell.delegate = self
cell.setupCellUI(userId: appDelegate.userId)
let fileName = appDelegate.userBaseUrl + "-" + tableShare.shareWith + ".png"
NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, dispalyName: tableShare.shareWithDisplayname, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: tableShare.shareWith, dispalyName: tableShare.shareWithDisplayname, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
return cell
}
}
Expand Down

0 comments on commit bfa7bfe

Please sign in to comment.