瀏覽代碼

improvements

marinofaggiana 4 年之前
父節點
當前提交
e4dd1d78e1

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -2807,8 +2807,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
-				kind = exactVersion;
-				version = 0.87.0;
+				kind = revision;
+				revision = 628f524daac4a98f1cdb2da5adccd1f70cc18c07;
 			};
 		};
 		F7C4D88B2534887E00C142DA /* XCRemoteSwiftPackageReference "Parchment" */ = {

+ 2 - 2
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -15,8 +15,8 @@
         "repositoryURL": "https://github.com/nextcloud/ios-communication-library/",
         "state": {
           "branch": null,
-          "revision": "1d0230e399808e9064acbd65137b3801b56018fc",
-          "version": "0.87.0"
+          "revision": "628f524daac4a98f1cdb2da5adccd1f70cc18c07",
+          "version": null
         }
       },
       {

+ 1 - 1
iOSClient/Brand/NCBrand.swift

@@ -244,7 +244,7 @@ class NCBrandColor: NSObject {
     @objc let introSignup: Int                      = 1
     
     // Avatar & Preview
-    let avatarSize: Int                             = 512
+    let avatarSize: CGFloat                         = 512
     @objc let sizePreview: CGFloat                  = 1024
     @objc let sizeIcon: CGFloat                     = 512
     

+ 2 - 2
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -1421,11 +1421,11 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
                     cell.imageShared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
                 } else if FileManager.default.fileExists(atPath: fileNameSource) {
-                    cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
+                    cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar, borderColor: .white, borderWidth: 1)
                 } else {
                     NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: NCBrandGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
                         if errorCode == 0 && account == self.appDelegate.account {
-                            cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
+                            cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar, borderColor: .white, borderWidth: 1)
                         }
                     }
                 }

+ 2 - 2
iOSClient/Select/NCSelect.swift

@@ -572,11 +572,11 @@ extension NCSelect: UICollectionViewDataSource {
                 if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
                     cell.imageShared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
                 } else if FileManager.default.fileExists(atPath: fileNameSource) {
-                    cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
+                    cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar, borderColor: .white, borderWidth: 1)
                 } else {
                     NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: NCBrandGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
                         if errorCode == 0 && account == self.appDelegate.account {
-                            cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
+                            cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar, borderColor: .white, borderWidth: 1)
                         }
                     }
                 }

+ 29 - 2
iOSClient/Utility/NCUtility.swift

@@ -407,8 +407,34 @@ class NCUtility: NSObject {
     }
     
     #if !EXTENSION
-    @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String) -> UIImage? {
+    @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String, borderColor: UIColor, borderWidth: CGFloat) -> UIImage? {
         
+        guard let imageFile = UIImage(contentsOfFile: fileNameSource) else { return nil }
+        let size = NCBrandGlobal.shared.avatarSize
+        guard let imageSource = imageFile.resizeImage(size: CGSize(width: size, height: size), isAspectRation: true) else { return nil }
+        
+        UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
+        imageSource.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
+        let image = UIGraphicsGetImageFromCurrentImageContext()
+        UIGraphicsEndImageContext()
+
+        UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
+        let avatarImageView = NCAvatar.init(image: image, borderColor: borderColor, borderWidth: borderWidth)
+        guard let context = UIGraphicsGetCurrentContext() else { return nil }
+        avatarImageView.layer.render(in: context)
+        guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
+        UIGraphicsEndImageContext()
+        
+        guard let data = imageAvatar.pngData() else {
+            return nil
+        }
+        do {
+            try data.write(to: NSURL(fileURLWithPath: fileNameSourceAvatar) as URL, options: .atomic)
+        } catch { }
+        
+        return imageAvatar
+        
+        /*
         guard let imageSource = UIImage(contentsOfFile: fileNameSource) else { return nil }
         let size = NCBrandGlobal.shared.avatarSize
         
@@ -418,7 +444,7 @@ class NCUtility: NSObject {
         UIGraphicsEndImageContext()
 
         UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
-        let avatarImageView = NCAvatar.init(image: image, borderColor: .lightGray, borderWidth: 1)
+        let avatarImageView = NCAvatar.init(image: image, borderColor: borderColor, borderWidth: borderWidth)
         guard let context = UIGraphicsGetCurrentContext() else { return nil }
         avatarImageView.layer.render(in: context)
         guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
@@ -432,6 +458,7 @@ class NCUtility: NSObject {
         } catch { }
         
         return imageAvatar
+        */
     }
     #endif