Marino Faggiana 8 years ago
parent
commit
31c680e97d

+ 21 - 0
Libraries external/APAvatarImageView/APAvatarImageView.h

@@ -0,0 +1,21 @@
+//
+//  APAvatarImageView.h
+//  Avatar
+//
+//  Created by Ankur Patel on 10/19/13.
+//  Copyright (c) 2013 Patel Labs LLC. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface APAvatarImageView : UIImageView
+
+@property (nonatomic, retain) UIColor *borderColor;
+@property (nonatomic, assign) float borderWidth;
+@property (nonatomic, assign) float cornerRadius;
+
+- (id)initWithFrame:(CGRect)frame borderColor:(UIColor*)borderColor borderWidth:(float)borderWidth;
+- (id)initWithImage:(UIImage *)image borderColor:(UIColor*)borderColor borderWidth:(float)borderWidth;
+- (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage borderColor:(UIColor*)borderColor borderWidth:(float)borderWidth;
+
+@end

+ 115 - 0
Libraries external/APAvatarImageView/APAvatarImageView.m

@@ -0,0 +1,115 @@
+//
+//  APAvatarImageView.m
+//  Avatar
+//
+//  Created by Ankur Patel on 10/19/13.
+//  Copyright (c) 2013 Patel Labs LLC. All rights reserved.
+//
+
+#import "APAvatarImageView.h"
+
+@interface APAvatarImageView ()
+
+- (void)draw;
+
+@end
+
+@implementation APAvatarImageView
+
+- (id)initWithFrame:(CGRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        _cornerRadius = self.frame.size.height/2.0f;
+        [self draw];
+    }
+    return self;
+}
+
+- (id)initWithCoder:(NSCoder *)aDecoder
+{
+    self = [super initWithCoder:aDecoder];
+    if (self) {
+        _borderWidth = -1.0;
+        _cornerRadius = self.frame.size.height/2.0f;
+        [self draw];
+    }
+    return self;
+}
+
+- (id)initWithFrame:(CGRect)frame borderColor:(UIColor*)borderColor borderWidth:(float)borderWidth
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        _borderColor = borderColor;
+        _borderWidth = borderWidth;
+        _cornerRadius = self.frame.size.height/2.0f;
+        [self draw];
+    }
+    return self;
+}
+
+- (id)initWithImage:(UIImage *)image borderColor:(UIColor*)borderColor borderWidth:(float)borderWidth
+{
+    self = [super initWithImage:image];
+    if (self) {
+        _borderColor = borderColor;
+        _borderWidth = borderWidth;
+        _cornerRadius = self.frame.size.height/2.0f;
+        [self draw];
+    }
+    return self;
+}
+
+- (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage borderColor:(UIColor*)borderColor borderWidth:(float)borderWidth
+{
+    self = [super initWithImage:image highlightedImage:highlightedImage];
+    if (self) {
+        _borderColor = borderColor;
+        _borderWidth = borderWidth;
+        _cornerRadius = self.frame.size.height/2.0f;
+        [self draw];
+    }
+    return self;
+}
+
+- (void)setBorderColor:(UIColor *)borderColor
+{
+    _borderColor = borderColor;
+    [self draw];
+}
+
+- (void)setBorderWidth:(float)borderWidth
+{
+    _borderWidth = borderWidth;
+    [self draw];
+}
+
+-(void)setCornerRadius:(float)cornerRadius
+{
+    _cornerRadius = cornerRadius;
+    [self draw];
+}
+
+- (void)draw
+{
+    CGRect frame = self.frame;
+    if (frame.size.width != frame.size.height) {
+        NSLog(@"Warning: Height and Width should be the same for image view");
+    }
+    CALayer *l = [self layer];
+    [l setMasksToBounds:YES];
+    [l setCornerRadius:_cornerRadius];
+    if (_borderWidth < 0) { // Default case
+        [l setBorderWidth:3.0];
+    } else {
+        [l setBorderWidth:_borderWidth];
+    }
+    if (_borderColor == nil) {
+        [l setBorderColor:[[UIColor lightGrayColor] CGColor]];
+    } else {
+        [l setBorderColor:[_borderColor CGColor]];
+    }
+}
+
+@end

+ 18 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -208,6 +208,9 @@
 		F743448C1E128010001CC831 /* CCCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = F7FE125F1BAC03FB0041924B /* CCCrypto.m */; };
 		F74344921E128EB0001CC831 /* Picker.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = F74344901E128E8F001CC831 /* Picker.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
 		F74344931E128EB4001CC831 /* PickerFileProvider.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = F74344911E128E96001CC831 /* PickerFileProvider.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
+		F744FA7E1E57333C00BFAB34 /* APAvatarImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = F744FA7D1E57333C00BFAB34 /* APAvatarImageView.m */; };
+		F744FA7F1E57333C00BFAB34 /* APAvatarImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = F744FA7D1E57333C00BFAB34 /* APAvatarImageView.m */; };
+		F744FA801E57333C00BFAB34 /* APAvatarImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = F744FA7D1E57333C00BFAB34 /* APAvatarImageView.m */; };
 		F749E4E91DC1FB38009BA2FD /* Share Ext Nextcloud.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = F7CE8AFB1DC1F8D8009CAE48 /* Share Ext Nextcloud.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
 		F750374D1DBFA91A008FB480 /* ALView+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F75037441DBFA91A008FB480 /* ALView+PureLayout.m */; };
 		F750374F1DBFA91A008FB480 /* NSArray+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F75037461DBFA91A008FB480 /* NSArray+PureLayout.m */; };
@@ -1236,6 +1239,8 @@
 		F744BE921BEBB2EE004FFF66 /* CCIntro.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCIntro.h; sourceTree = "<group>"; };
 		F744BE931BEBB2EE004FFF66 /* CCIntro.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCIntro.m; sourceTree = "<group>"; };
 		F744BE961BEBB31E004FFF66 /* ImagesIntro.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = ImagesIntro.xcassets; sourceTree = "<group>"; };
+		F744FA7C1E57333C00BFAB34 /* APAvatarImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APAvatarImageView.h; sourceTree = "<group>"; };
+		F744FA7D1E57333C00BFAB34 /* APAvatarImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAvatarImageView.m; sourceTree = "<group>"; };
 		F74D3DBD1BAC1941000BAE4B /* OCNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCNetworking.h; sourceTree = "<group>"; };
 		F74D3DBE1BAC1941000BAE4B /* OCNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCNetworking.m; sourceTree = "<group>"; };
 		F75037431DBFA91A008FB480 /* ALView+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ALView+PureLayout.h"; sourceTree = "<group>"; };
@@ -1669,6 +1674,7 @@
 			children = (
 				F70F02A91C889183008DAB36 /* AESCrypt-ObjC */,
 				F70F02B21C889183008DAB36 /* AFViewShaker */,
+				F744FA7B1E57333C00BFAB34 /* APAvatarImageView */,
 				F70F0F541C889353008DAB36 /* AHKActionSheet */,
 				F70F02BE1C889183008DAB36 /* BKPasscodeView */,
 				F7F06E291DBFACC600099AE9 /* CTAssetsPickerController */,
@@ -2621,6 +2627,15 @@
 			path = Intro;
 			sourceTree = "<group>";
 		};
+		F744FA7B1E57333C00BFAB34 /* APAvatarImageView */ = {
+			isa = PBXGroup;
+			children = (
+				F744FA7C1E57333C00BFAB34 /* APAvatarImageView.h */,
+				F744FA7D1E57333C00BFAB34 /* APAvatarImageView.m */,
+			);
+			path = APAvatarImageView;
+			sourceTree = "<group>";
+		};
 		F74D3DB81BAC1941000BAE4B /* Networking */ = {
 			isa = PBXGroup;
 			children = (
@@ -3757,6 +3772,7 @@
 				F71459D21D12E3B700CAFEEC /* CCUtility.m in Sources */,
 				F71459D31D12E3B700CAFEEC /* CCBKPasscode.m in Sources */,
 				F71459D51D12E3B700CAFEEC /* MBProgressHUD.m in Sources */,
+				F744FA7F1E57333C00BFAB34 /* APAvatarImageView.m in Sources */,
 				F71459D71D12E3B700CAFEEC /* BKPasscodeDummyViewController.m in Sources */,
 				F708CF801E56E8CC00271D8B /* TableDirectory+CoreDataClass.m in Sources */,
 				F71459D91D12E3B700CAFEEC /* CCCrypto.m in Sources */,
@@ -3851,6 +3867,7 @@
 				F708CF991E56E8CC00271D8B /* TableAccount+CoreDataClass.m in Sources */,
 				F743445C1E127D3D001CC831 /* BKPasscodeField.m in Sources */,
 				F7FC88FA1E140558006D0506 /* cryptocloud.xcdatamodeld in Sources */,
+				F744FA801E57333C00BFAB34 /* APAvatarImageView.m in Sources */,
 				F708CF721E56E8CC00271D8B /* TableMetadata+CoreDataProperties.m in Sources */,
 				F743445E1E127D44001CC831 /* BKPasscodeLockScreenManager.m in Sources */,
 				F74344631E127D79001CC831 /* CCBKPasscode.m in Sources */,
@@ -4134,6 +4151,7 @@
 				F77B0EC31D118A16002130FE /* UIImage+Enhancing.m in Sources */,
 				F77B0EC61D118A16002130FE /* CCCellMain.m in Sources */,
 				F77B0EC71D118A16002130FE /* AESCrypt.m in Sources */,
+				F744FA7E1E57333C00BFAB34 /* APAvatarImageView.m in Sources */,
 				F73CCE091DC13776007E38D8 /* NSObject+XLFormAdditions.m in Sources */,
 				F708CF971E56E8CC00271D8B /* TableAccount+CoreDataClass.m in Sources */,
 				F708CF8E1E56E8CC00271D8B /* TableCertificates+CoreDataProperties.m in Sources */,

+ 6 - 1
iOSClient/Main/CCMain.m

@@ -1118,7 +1118,12 @@
 - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
 {
     [CCCoreData setUserProfileActiveAccount:metadataNet.account userProfile:userProfile];
-}
+
+    NSString *address = [NSString stringWithFormat:@"%@/index.php/avatar/%@/64", app.activeUrl, app.activeUser];
+    UIImage *avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
+    if (avatar)
+        [UIImagePNGRepresentation(avatar) writeToFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] atomically:YES];
+    }
 
 - (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
 {

+ 1 - 0
iOSClient/Settings/CCSettings.h

@@ -28,6 +28,7 @@
 #import "BKPasscodeViewController.h"
 #import "CCUtility.h"
 #import "CCHud.h"
+#import "APAvatarImageView.h"
 
 @interface CCSettings : XLFormViewController <BKPasscodeViewControllerDelegate, MFMailComposeViewControllerDelegate>
 

+ 30 - 0
iOSClient/Settings/CCSettings.m

@@ -332,6 +332,8 @@
     XLFormRowDescriptor *rowUserEmail = [self.form formRowWithTag:@"useremail"];
     XLFormRowDescriptor *rowQuota = [self.form formRowWithTag:@"quota"];
     
+    XLFormRowDescriptor *rowChangeCredentials = [self.form formRowWithTag:@"changecredentials"];
+
     // ------------------------------------------------------------------
     
     if ([[CCUtility getBlockCode] length]) {
@@ -345,6 +347,20 @@
     if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
     if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
     
+    // Avatar
+    UIImage *avatar = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser]];
+    if (avatar) {
+        
+        APAvatarImageView *avatarImageView = [[APAvatarImageView alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
+        
+        CGSize imageSize = avatarImageView.bounds.size;
+        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
+        CGContextRef context = UIGraphicsGetCurrentContext();
+        [avatarImageView.layer renderInContext:context];
+        avatar = UIGraphicsGetImageFromCurrentImageContext();
+        UIGraphicsEndImageContext();
+    }
+    
     TableAccount *tableAccount = [CCCoreData getActiveAccount];
     
     rowVersionServer.value =  [CCNetworking sharedNetworking].sharedOCCommunication.getCurrentServerVersion;
@@ -355,6 +371,8 @@
         
         rowUserInformation.title = [NSString stringWithFormat:@"%@ %@ %@", tableAccount.displayName, tableAccount.address, tableAccount.phone];
         rowUserInformation.disabled = @YES;
+        [rowUserInformation.cellConfig setObject:avatar forKey:@"imageView.image"];
+        rowUserInformation.height = 100;
         
     } else {
         
@@ -368,7 +386,19 @@
     NSString *quotaAvailable = [CCUtility transformedSize:[tableAccount.quotaFree doubleValue]];
     
     rowQuota.value = [NSString stringWithFormat:@"%@ / %@ %@", quota, quotaAvailable, NSLocalizedString(@"_available_", nil)];
+    
+    /*
+        [rowChangeCredentials.cellConfig setObject:avatarViewImage forKey:@"imageView.image"];
+        rowChangeCredentials.height = 50;
         
+    } else {
+        
+        [rowChangeCredentials.cellConfig setObject:[UIImage imageNamed:image_settingsCredentials] forKey:@"imageView.image"];
+    }
+    */
+    
+    
+    
     // -----------------------------------------------------------------
     
     [self.tableView reloadData];