marinofaggiana 4 years ago
parent
commit
119c8f6510

+ 2 - 7
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -238,13 +238,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     image = userImage
                 }
                 
-                let rect = CGRect(x: 0, y: 0, width: 30, height: 30)
-                UIGraphicsBeginImageContextWithOptions(rect.size, false, 3.0)
-                UIBezierPath.init(roundedRect: rect, cornerRadius: rect.size.height).addClip()
-                image.draw(in: rect)
-                image = UIGraphicsGetImageFromCurrentImageContext() ?? NCUtility.shared.loadImage(named: "person.crop.circle")
-                UIGraphicsEndImageContext()
-
+                image = NCUtility.shared.createAvatar(image: image, size: 30)
+                
                 let button = UIButton(type: .custom)
                 button.setImage(image, for: .normal)
                 

+ 3 - 14
iOSClient/Settings/CCManageAccount.m

@@ -54,25 +54,14 @@
         
         NSString *title = [NSString stringWithFormat:@"%@ %@", account.user, [NSURL URLWithString:account.urlBase].host];
         row = [XLFormRowDescriptor formRowDescriptorWithTag:account.account rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
+        
         // Avatar
         NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:account.user urlBase:account.urlBase], account.user];
         UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
         if (avatar) {
-            
-            avatar = [avatar resizeImageWithSize:CGSizeMake(35, 35) isAspectRation:false];
-            UIImageView *avatarImageView = [[UIImageView alloc] initWithImage:avatar];
-            [avatarImageView avatarWithRoundness:2 borderWidth:1 borderColor:NCBrandColor.shared.avatarBorder backgroundColor:[UIColor clearColor]];
-            
-            CGSize imageSize = avatarImageView.bounds.size;
-            UIGraphicsBeginImageContextWithOptions(imageSize, NO, UIScreen.mainScreen.scale);
-            CGContextRef context = UIGraphicsGetCurrentContext();
-            [avatarImageView.layer renderInContext:context];
-            avatar = UIGraphicsGetImageFromCurrentImageContext();
-            UIGraphicsEndImageContext();
-            
+            avatar = [[NCUtility shared] createAvatarWithImage:avatar size:30];
         } else {
-            
-            avatar = [[UIImage imageNamed:@"avatar"] imageWithColor:NCBrandColor.shared.icon size:35];
+            avatar = [[UIImage imageNamed:@"avatar"] imageWithColor:NCBrandColor.shared.icon size:30];
         }
         
         row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundView;

+ 14 - 0
iOSClient/Utility/NCUtility.swift

@@ -454,6 +454,20 @@ class NCUtility: NSObject {
         return  UIImage(named: "file")!.image(color: color, size: size)
     }
     
+    @objc func createAvatar(image: UIImage, size: CGFloat) -> UIImage {
+        
+        var avatarImage = image
+        let rect = CGRect(x: 0, y: 0, width: size, height: size)
+        
+        UIGraphicsBeginImageContextWithOptions(rect.size, false, 3.0)
+        UIBezierPath.init(roundedRect: rect, cornerRadius: rect.size.height).addClip()
+        avatarImage.draw(in: rect)
+        avatarImage = UIGraphicsGetImageFromCurrentImageContext() ?? image
+        UIGraphicsEndImageContext()
+        
+        return avatarImage
+    }
+    
     // MARK: -
 
     @objc func startActivityIndicator(backgroundView: UIView?, blurEffect: Bool, bottom: CGFloat = 0) {