marinofaggiana 4 years ago
parent
commit
a1d6542b07

+ 0 - 10
Nextcloud.xcodeproj/project.pbxproj

@@ -259,10 +259,6 @@
 		F7A0D1362591FBC5008F8A13 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
 		F7A0D1372591FBC5008F8A13 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
 		F7A0D1382591FBC5008F8A13 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
-		F7A0D1462592256F008F8A13 /* UIImageView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1452592256F008F8A13 /* UIImageView+Extensions.swift */; };
-		F7A0D1472592256F008F8A13 /* UIImageView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1452592256F008F8A13 /* UIImageView+Extensions.swift */; };
-		F7A0D1482592256F008F8A13 /* UIImageView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1452592256F008F8A13 /* UIImageView+Extensions.swift */; };
-		F7A0D1492592256F008F8A13 /* UIImageView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1452592256F008F8A13 /* UIImageView+Extensions.swift */; };
 		F7A321AD1E9E6AD50069AD1B /* CCAdvanced.m in Sources */ = {isa = PBXBuildFile; fileRef = F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */; };
 		F7A76DC8256A71CD00119AB3 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B7504A2397D38E004E13EC /* UIImage+Extensions.swift */; };
 		F7A76DCD256A71CE00119AB3 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B7504A2397D38E004E13EC /* UIImage+Extensions.swift */; };
@@ -620,7 +616,6 @@
 		F79A65C22191D90F00FF6DCC /* NCSelect.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCSelect.storyboard; sourceTree = "<group>"; };
 		F79A65C52191D95E00FF6DCC /* NCSelect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCSelect.swift; sourceTree = "<group>"; };
 		F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
-		F7A0D1452592256F008F8A13 /* UIImageView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Extensions.swift"; sourceTree = "<group>"; };
 		F7A321AB1E9E6AD50069AD1B /* CCAdvanced.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAdvanced.h; sourceTree = "<group>"; };
 		F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAdvanced.m; sourceTree = "<group>"; };
 		F7A80BC8252624C100C7CD01 /* NCFileViewInFolder.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCFileViewInFolder.storyboard; sourceTree = "<group>"; };
@@ -1167,7 +1162,6 @@
 				F713FEFE2472764000214AF6 /* UIImage+animatedGIF.h */,
 				F713FEFF2472764100214AF6 /* UIImage+animatedGIF.m */,
 				F7B7504A2397D38E004E13EC /* UIImage+Extensions.swift */,
-				F7A0D1452592256F008F8A13 /* UIImageView+Extensions.swift */,
 			);
 			path = Extensions;
 			sourceTree = "<group>";
@@ -1940,7 +1934,6 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				F7A0D1492592256F008F8A13 /* UIImageView+Extensions.swift in Sources */,
 				F785EEA52461A4CF00B3F945 /* CCUtility.m in Sources */,
 				2C1D5D7923E2DE9100334ABB /* NCBrand.swift in Sources */,
 				F702F2D225EE5B5C008F8E80 /* NCGlobal.swift in Sources */,
@@ -1963,7 +1956,6 @@
 			files = (
 				F73D5E48246DE09200DF6467 /* NCElementsJSON.swift in Sources */,
 				F7A0D1362591FBC5008F8A13 /* String+Extensions.swift in Sources */,
-				F7A0D1472592256F008F8A13 /* UIImageView+Extensions.swift in Sources */,
 				F70460532499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
 				F71459C21D12E3B700CAFEEC /* ShareViewController.m in Sources */,
 				F70BFC7520E0FA7D00C67599 /* NCUtility.swift in Sources */,
@@ -2001,7 +1993,6 @@
 				F771E3D520E2392D00AFB62D /* FileProviderItem.swift in Sources */,
 				F7434B3620E23FE000417916 /* NCManageDatabase.swift in Sources */,
 				F798F0E725880609000DAFFD /* UIColor+Extensions.swift in Sources */,
-				F7A0D1482592256F008F8A13 /* UIImageView+Extensions.swift in Sources */,
 				F70460542499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
 				F785EEA42461A4A600B3F945 /* NCUtility.swift in Sources */,
 				F771E3F320E239A600AFB62D /* FileProviderData.swift in Sources */,
@@ -2090,7 +2081,6 @@
 				F70BFC7420E0FA7D00C67599 /* NCUtility.swift in Sources */,
 				F7C1EEA525053A9C00866ACC /* NCDataSource.swift in Sources */,
 				F713FF002472764100214AF6 /* UIImage+animatedGIF.m in Sources */,
-				F7A0D1462592256F008F8A13 /* UIImageView+Extensions.swift in Sources */,
 				F749C10B23C4A5340027D966 /* NCIntroCollectionViewCell.swift in Sources */,
 				F718C24E254D507B00C5C256 /* NCViewerImageDetailView.swift in Sources */,
 				F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */,

+ 0 - 57
iOSClient/Extensions/UIImageView+Extensions.swift

@@ -1,57 +0,0 @@
-//
-//  UIImageView+Extensions.swift
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 22/12/20.
-//  Copyright © 2020 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-
-import Foundation
-
-extension UIImageView {
-    
-    @objc func avatar(roundness: CGFloat = 2, borderWidth: CGFloat = 1, borderColor: UIColor = NCBrandColor.shared.avatarBorder, backgroundColor: UIColor = .clear) {
-        
-        layer.cornerRadius = bounds.width / roundness
-        layer.borderWidth = borderWidth
-        layer.borderColor = borderColor.cgColor
-        layer.backgroundColor = backgroundColor.cgColor
-
-        clipsToBounds = true
-        
-        let path = UIBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), cornerRadius: bounds.width / roundness)
-        let mask = CAShapeLayer()
-        
-        mask.path = path.cgPath
-        layer.mask = mask
-    }
-    
-    func clearLayerMask() {
-        
-        layer.cornerRadius = 0
-        layer.borderWidth = 0
-        layer.borderColor = nil
-        layer.backgroundColor = nil
-        
-        clipsToBounds = false
-        
-        mask = nil
-        layer.mask = nil
-    }
-}

+ 6 - 5
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1258,7 +1258,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             cell.imageLocal.image = nil
             cell.imageFavorite.image = nil
             cell.imageShared.image = nil
-            cell.imageShared.clearLayerMask()
             cell.imageMore.image = nil
             
             cell.imageItem.image = nil
@@ -1341,13 +1340,15 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 var fileNameUser = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId
                 fileNameUser = fileNameUser + ".png"
                 if FileManager.default.fileExists(atPath: fileNameUser) {
-                    cell.imageShared.avatar()
-                    cell.imageShared.image = UIImage(contentsOfFile: fileNameUser)
+                    if let image = UIImage(contentsOfFile: fileNameUser) {
+                        cell.imageShared.image = NCUtility.shared.createAvatar(image: image, size: 30)
+                    }
                 } else {
                     NCCommunication.shared.downloadAvatar(userId: metadata.ownerId, fileNameLocalPath: fileNameUser, size: NCGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
                         if errorCode == 0 && account == self.appDelegate.account {
-                            cell.imageShared.avatar()
-                            cell.imageShared.image = UIImage(contentsOfFile: fileNameUser)
+                            if let image = UIImage(contentsOfFile: fileNameUser) {
+                                cell.imageShared.image = NCUtility.shared.createAvatar(image: image, size: 30)
+                            }
                         }
                     }
                 }

+ 2 - 10
iOSClient/Menu/NCLoginWeb+Menu.swift

@@ -38,16 +38,8 @@ extension NCLoginWeb {
             let title = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
             let fileNamePath = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(account.user, urlBase: account.urlBase)) + "-" + account.user + ".png"
 
-            if var userImage = UIImage(contentsOfFile: fileNamePath) {
-                userImage = userImage.resizeImage(size: CGSize(width: 50, height: 50), isAspectRation: true)!
-                let userImageView = UIImageView(image: userImage)
-                userImageView.avatar(roundness: 2, borderWidth: 1, borderColor: NCBrandColor.shared.avatarBorder, backgroundColor: .clear)
-                UIGraphicsBeginImageContext(userImageView.bounds.size)
-                userImageView.layer.render(in: UIGraphicsGetCurrentContext()!)
-                if let newAvatar = UIGraphicsGetImageFromCurrentImageContext() {
-                    avatar = newAvatar
-                }
-                UIGraphicsEndImageContext()
+            if let image = UIImage(contentsOfFile: fileNamePath) {
+                avatar = NCUtility.shared.createAvatar(image: image, size: 50)
             }
             
             actions.append(

+ 4 - 9
iOSClient/Share/NCShare.swift

@@ -302,7 +302,6 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
         dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
             guard let cell = cell as? NCShareUserDropDownCell else { return }
             let sharee = sharees[index]
-            cell.imageItem.clearLayerMask()
             cell.imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
             let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
             cell.imageStatus.image = status.onlineStatus
@@ -317,8 +316,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
             fileNameLocalPath = fileNameLocalPath + ".png"
             if FileManager.default.fileExists(atPath: fileNameLocalPath) {
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) {
-                    cell.imageItem.image = image
-                    cell.imageItem.avatar()
+                    cell.imageItem.image = NCUtility.shared.createAvatar(image: image, size: 30)
                 }
             } else {
                 DispatchQueue.global().async {
@@ -326,8 +324,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
                         if errorCode == 0 && account == self.appDelegate.account && UIImage(data: data!) != nil {
                             if let image = UIImage(contentsOfFile: fileNameLocalPath) {
                                 DispatchQueue.main.async {
-                                    cell.imageItem.image = image
-                                    cell.imageItem.avatar()
+                                    cell.imageItem.image = NCUtility.shared.createAvatar(image: image, size: 30)
                                 }
                             }
                         } 
@@ -414,16 +411,14 @@ extension NCShare: UITableViewDataSource {
                 fileNameLocalPath = fileNameLocalPath + ".png"
                 if FileManager.default.fileExists(atPath: fileNameLocalPath) {
                     if let image = UIImage(contentsOfFile: fileNameLocalPath) {
-                        cell.imageItem.avatar()
-                        cell.imageItem.image = image
+                        cell.imageItem.image = NCUtility.shared.createAvatar(image: image, size: 40)
                     }
                 } else {
                     DispatchQueue.global().async {
                         NCCommunication.shared.downloadAvatar(userId: tableShare.shareWith, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
                             if errorCode == 0 && account == self.appDelegate.account && UIImage(data: data!) != nil {
                                 if let image = UIImage(contentsOfFile: fileNameLocalPath) {
-                                    cell.imageItem.avatar()
-                                    cell.imageItem.image = image
+                                    cell.imageItem.image = NCUtility.shared.createAvatar(image: image, size: 40)
                                 }
                             }
                         }

+ 10 - 3
iOSClient/Share/NCShareComments.swift

@@ -67,11 +67,12 @@ class NCShareComments: UIViewController, NCShareCommentsCellDelegate {
             labelUser.text = tabAccount.displayName
         }
         
+        imageItem.image = UIImage(named: "avatar")
         var fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + appDelegate.user
         fileNameLocalPath = fileNameLocalPath + ".png"
         if FileManager.default.fileExists(atPath: fileNameLocalPath) {
             if let image = UIImage(contentsOfFile: fileNameLocalPath) {
-                imageItem.image = image
+                imageItem.image = NCUtility.shared.createAvatar(image: image, size: 40)
             }
         }
         
@@ -179,15 +180,21 @@ extension NCShareComments: UITableViewDataSource {
             cell.sizeToFit()
             
             // Image
+            cell.imageItem.image = UIImage(named: "avatar")
+
             var fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + tableComments.actorId
             fileNameLocalPath = fileNameLocalPath + ".png"
             if FileManager.default.fileExists(atPath: fileNameLocalPath) {
-                if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
+                if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                    cell.imageItem.image = NCUtility.shared.createAvatar(image: image, size: 40)
+                }
             } else {
                 DispatchQueue.global().async {
                     NCCommunication.shared.downloadAvatar(userId: tableComments.actorId, fileNameLocalPath: fileNameLocalPath, size: 128) { (account, data, errorCode, errorMessage) in
                         if errorCode == 0 && UIImage(data: data!) != nil {
-                            cell.imageItem.image = UIImage(named: "avatar")
+                            if let image = UIImage(data: data!) {
+                                cell.imageItem.image = NCUtility.shared.createAvatar(image: image, size: 40)
+                            }
                         }
                     }
                     /*

+ 1 - 1
iOSClient/Share/NCShareCommentsCell.xib

@@ -16,7 +16,7 @@
                 <rect key="frame" x="0.0" y="0.0" width="600" height="122"/>
                 <autoresizingMask key="autoresizingMask"/>
                 <subviews>
-                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" translatesAutoresizingMaskIntoConstraints="NO" id="qDs-UG-Mn7" userLabel="ImageItem" customClass="NCAvatar" customModule="Nextcloud" customModuleProvider="target">
+                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" translatesAutoresizingMaskIntoConstraints="NO" id="qDs-UG-Mn7" userLabel="ImageItem">
                         <rect key="frame" x="5" y="15" width="40" height="40"/>
                         <constraints>
                             <constraint firstAttribute="height" constant="40" id="8et-YH-T1D"/>