Переглянути джерело

improved caching image avatar

marinofaggiana 5 роки тому
батько
коміт
0c75329ce0

+ 1 - 1
iOSClient/Activity/NCActivity.swift

@@ -223,7 +223,7 @@ extension NCActivity: UITableViewDataSource {
                     }
                 } else {
                     DispatchQueue.global().async {
-                        let url = self.appDelegate.activeUrl + k_avatar + activity.user + "/128"
+                        let url = self.appDelegate.activeUrl + k_avatar + activity.user + "/" + k_avatar_size
                         let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                         OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
                             if errorCode == 0 && UIImage(data: data!) != nil {

+ 1 - 1
iOSClient/Brand/File_Provider_Extension.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<string>2.24.0</string>
 	<key>CFBundleVersion</key>
-	<string>7</string>
+	<string>8</string>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>

+ 1 - 1
iOSClient/Brand/Share.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<string>2.24.0</string>
 	<key>CFBundleVersion</key>
-	<string>7</string>
+	<string>8</string>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>

+ 1 - 1
iOSClient/Brand/iOSClient.plist

@@ -63,7 +63,7 @@
 		</dict>
 	</array>
 	<key>CFBundleVersion</key>
-	<string>7</string>
+	<string>8</string>
 	<key>FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED</key>
 	<true/>
 	<key>Fabric</key>

+ 1 - 0
iOSClient/CCGlobal.h

@@ -69,6 +69,7 @@
 
 // Avatar
 #define k_avatar                                        @"/index.php/avatar/"
+#define k_avatar_size                                   "128"
 
 // Passphrase test EndToEnd Encryption
 #define k_passphrase_test                               @"more over television factory tendency independence international intellectual impress interest sentence pony"

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.h

@@ -797,7 +797,7 @@ typedef enum {
                                    successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest
                                    failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
-- (NSURLSessionTask *) getRemotePreviewTrashByServer:(NSString*)serverPath ofFileId:(NSString *)fileId onCommunication:(OCCommunication *)sharedOCComunication
+- (NSURLSessionTask *) getRemotePreviewTrashByServer:(NSString*)serverPath ofFileId:(NSString *)fileId size:(NSString *)size onCommunication:(OCCommunication *)sharedOCComunication
                                  successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest
                                  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 

+ 2 - 2
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -1612,14 +1612,14 @@
     return operation;
 }
 
-- (NSURLSessionTask *) getRemotePreviewTrashByServer:(NSString*)serverPath ofFileId:(NSString *)fileId onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+- (NSURLSessionTask *) getRemotePreviewTrashByServer:(NSString*)serverPath ofFileId:(NSString *)fileId size:(NSString *)size onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
     
     serverPath = [serverPath encodeString:NSUTF8StringEncoding];
     
     OCWebDAVClient *request = [OCWebDAVClient new];
     request = [self getRequestWithCredentials:request];
     
-    OCHTTPRequestOperation *operation = [request getRemotePreviewTrashByServer:serverPath ofFileId:fileId onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
+    OCHTTPRequestOperation *operation = [request getRemotePreviewTrashByServer:serverPath ofFileId:fileId size:size onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
         
         NSData *responseData = (NSData*) responseObject;
         

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -513,7 +513,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (OCHTTPRequestOperation *) getRemotePreviewByServer:(NSString * _Nonnull)serverPath ofFilePath:(NSString *_Nonnull)filePath  withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight andA:(NSInteger)a andMode:(NSString * _Nonnull)mode path:(NSString * _Nonnull)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure;
 
-- (OCHTTPRequestOperation *) getRemotePreviewTrashByServer:(NSString * _Nonnull)serverPath ofFileId:(NSString *_Nonnull)fileId onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure;
+- (OCHTTPRequestOperation *) getRemotePreviewTrashByServer:(NSString * _Nonnull)serverPath ofFileId:(NSString *_Nonnull)fileId size:(NSString *)size onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure;
 
 NS_ASSUME_NONNULL_END
 

+ 2 - 2
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -867,11 +867,11 @@ NSString *const NCResource = @"<d:displayname/>"
     return operation;
 }
 
-- (OCHTTPRequestOperation *) getRemotePreviewTrashByServer:(NSString *)serverPath ofFileId:(NSString*)fileId onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure {
+- (OCHTTPRequestOperation *) getRemotePreviewTrashByServer:(NSString *)serverPath ofFileId:(NSString*)fileId size:(NSString *)size onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure {
     
     _requestMethod = @"GET";
     
-    NSString *query = [NSString stringWithFormat:@"/index.php/apps/files_trashbin/preview?fileId=%@&x=128&y=128", fileId];
+    NSString *query = [NSString stringWithFormat:@"/index.php/apps/files_trashbin/preview?fileId=%@&x=%@&y=%@", fileId, size, size];
     serverPath = [serverPath stringByAppendingString:query];
     
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];

+ 9 - 8
iOSClient/Main/CCMain.m

@@ -1985,19 +1985,20 @@
         item.argument = account;
         
         tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
-        NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
         
-        UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
-        if (avatar) {
-            
-            avatar = [[NCUtility sharedInstance] createAvatarWithImage:avatar size:25 alpha:1.0];
-                    
+        NSString *fileNameSource = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
+        NSString *fileNameSourceAvatar = [NSString stringWithFormat:@"%@/%@-a10-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
+        UIImage *avatar;
+        
+        if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameSourceAvatar]) {
+            avatar = [UIImage imageWithContentsOfFile:fileNameSourceAvatar];
+        } else if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameSource]) {
+            avatar = [[NCUtility sharedInstance] createAvatarWithFileNameSource:fileNameSource fileNameSourceAvatar:fileNameSourceAvatar alpha:1.0];
         } else {
-            
             avatar = [UIImage imageNamed:@"menuLogoUser"];
         }
         
-        item.image = avatar;
+        item.image = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:true];
         item.target = self;
         
         if ([account isEqualToString:appDelegate.activeAccount]) {

+ 2 - 0
iOSClient/Main/Cell/CCCellMain.h

@@ -37,6 +37,8 @@
 @property(nonatomic, weak) IBOutlet UILabel *labelTitle;
 @property(nonatomic, weak) IBOutlet UILabel *labelInfoFile;
 
+@property(nonatomic, weak) IBOutlet UIButton *sharedButton;
+
 @property(nonatomic, weak) IBOutlet NSLayoutConstraint *labelTitleTrailingConstraint;
 
 @end

+ 17 - 7
iOSClient/Main/Cell/CCCellMain.xib

@@ -30,6 +30,14 @@
                         <color key="textColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
                         <nil key="highlightedColor"/>
                     </label>
+                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="HRe-1g-6Q1">
+                        <rect key="frame" x="500" y="-0.5" width="50" height="60.5"/>
+                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                        <constraints>
+                            <constraint firstAttribute="height" constant="60" id="0wA-tf-66c"/>
+                            <constraint firstAttribute="width" constant="50" id="qwf-D7-GQV"/>
+                        </constraints>
+                    </view>
                     <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" translatesAutoresizingMaskIntoConstraints="NO" id="5">
                         <rect key="frame" x="15" y="10" width="40" height="40"/>
                         <constraints>
@@ -58,11 +66,11 @@
                             <constraint firstAttribute="height" constant="15" id="Oxa-YI-vu7"/>
                         </constraints>
                     </imageView>
-                    <imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="avatar" translatesAutoresizingMaskIntoConstraints="NO" id="qhJ-el-R92" userLabel="Shared Image View">
-                        <rect key="frame" x="500" y="-0.5" width="50" height="60.5"/>
+                    <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="avatar" translatesAutoresizingMaskIntoConstraints="NO" id="qhJ-el-R92" userLabel="Shared">
+                        <rect key="frame" x="512.5" y="17.5" width="25" height="25"/>
                         <constraints>
-                            <constraint firstAttribute="height" constant="60" id="3Kr-Hv-AdZ"/>
-                            <constraint firstAttribute="width" constant="50" id="Ijp-se-6KO"/>
+                            <constraint firstAttribute="height" constant="25" id="3Kr-Hv-AdZ"/>
+                            <constraint firstAttribute="width" constant="25" id="Ijp-se-6KO"/>
                         </constraints>
                     </imageView>
                     <imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="aRp-Ql-cyA" userLabel="More">
@@ -82,26 +90,28 @@
                 </subviews>
                 <color key="tintColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                 <constraints>
+                    <constraint firstItem="aRp-Ql-cyA" firstAttribute="leading" secondItem="HRe-1g-6Q1" secondAttribute="trailing" id="17F-cr-JRN"/>
                     <constraint firstItem="Gci-mp-QNh" firstAttribute="centerY" secondItem="sQq-jC-UEV" secondAttribute="centerY" id="1DB-lM-7dD"/>
                     <constraint firstAttribute="bottom" secondItem="p7I-KN-FVZ" secondAttribute="bottom" constant="14" id="2Ay-YK-f66"/>
                     <constraint firstItem="5" firstAttribute="leading" secondItem="Fw2-NW-hsK" secondAttribute="trailing" constant="-10" id="32q-iB-1GU"/>
                     <constraint firstItem="DQR-yN-JaH" firstAttribute="top" secondItem="5" secondAttribute="bottom" constant="-9.5" id="3A5-mA-6Hh"/>
                     <constraint firstItem="QNC-8X-DAC" firstAttribute="top" secondItem="sQq-jC-UEV" secondAttribute="top" constant="13" id="4ds-S3-swp"/>
                     <constraint firstItem="5" firstAttribute="leading" secondItem="sQq-jC-UEV" secondAttribute="leading" constant="15" id="5es-ma-EXb"/>
+                    <constraint firstItem="qhJ-el-R92" firstAttribute="centerX" secondItem="HRe-1g-6Q1" secondAttribute="centerX" id="9bQ-Is-znw"/>
                     <constraint firstItem="aRp-Ql-cyA" firstAttribute="centerY" secondItem="sQq-jC-UEV" secondAttribute="centerY" id="DOx-77-6Mg"/>
                     <constraint firstAttribute="trailing" secondItem="p7I-KN-FVZ" secondAttribute="trailing" constant="110" id="JlG-wl-TXg"/>
                     <constraint firstItem="qhJ-el-R92" firstAttribute="centerY" secondItem="sQq-jC-UEV" secondAttribute="centerY" id="Jrh-En-806"/>
                     <constraint firstItem="p7I-KN-FVZ" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="10" id="Rcn-fx-Tz6"/>
-                    <constraint firstItem="aRp-Ql-cyA" firstAttribute="leading" secondItem="qhJ-el-R92" secondAttribute="trailing" id="T0F-Ef-8tH"/>
                     <constraint firstItem="QNC-8X-DAC" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="10" id="TON-2X-Sf9"/>
                     <constraint firstItem="Fw2-NW-hsK" firstAttribute="top" secondItem="5" secondAttribute="bottom" constant="-10" id="WBB-F1-EeD"/>
                     <constraint firstItem="5" firstAttribute="top" secondItem="QQH-5M-Zyv" secondAttribute="bottom" constant="-9" id="bNf-mC-wVr"/>
+                    <constraint firstItem="HRe-1g-6Q1" firstAttribute="centerY" secondItem="sQq-jC-UEV" secondAttribute="centerY" id="dko-At-sWL"/>
+                    <constraint firstItem="HRe-1g-6Q1" firstAttribute="leading" secondItem="Gci-mp-QNh" secondAttribute="trailing" id="h70-Ov-4F7"/>
                     <constraint firstItem="QQH-5M-Zyv" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="-11" id="jUJ-Sc-hQy"/>
                     <constraint firstAttribute="trailing" secondItem="QNC-8X-DAC" secondAttribute="trailing" constant="110" id="ljw-Qp-g60"/>
                     <constraint firstItem="DQR-yN-JaH" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="-11" id="nA1-42-OwZ"/>
                     <constraint firstItem="5" firstAttribute="centerY" secondItem="sQq-jC-UEV" secondAttribute="centerY" id="nyn-bs-x8N"/>
                     <constraint firstAttribute="trailing" secondItem="aRp-Ql-cyA" secondAttribute="trailing" id="o1F-h3-kBd"/>
-                    <constraint firstItem="qhJ-el-R92" firstAttribute="leading" secondItem="Gci-mp-QNh" secondAttribute="trailing" id="t0w-tE-EDc"/>
                 </constraints>
             </tableViewCellContentView>
             <gestureRecognizers/>
@@ -114,7 +124,7 @@
                 <outlet property="labelTitleTrailingConstraint" destination="ljw-Qp-g60" id="Iu0-wc-FFr"/>
                 <outlet property="local" destination="DQR-yN-JaH" id="LBA-Bm-Mz9"/>
                 <outlet property="more" destination="aRp-Ql-cyA" id="vbC-Za-UhD"/>
-                <outlet property="shared" destination="qhJ-el-R92" id="qXO-Vc-N0d"/>
+                <outlet property="shared" destination="qhJ-el-R92" id="P3Z-pt-baO"/>
                 <outlet property="status" destination="Fw2-NW-hsK" id="PjC-tV-ROx"/>
             </connections>
             <point key="canvasLocation" x="664" y="152.02398800599701"/>

+ 18 - 16
iOSClient/Main/NCMainCommon.swift

@@ -336,18 +336,19 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
             }
             if metadata.ownerId != appDelegate.activeUserID {
                 // Load avatar
-                let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
-                if FileManager.default.fileExists(atPath: fileNameLocalPath) {
-                    cell.shared.image = NCUtility.sharedInstance.createAvatar(image: UIImage(contentsOfFile: fileNameLocalPath), size: 30, alpha: 0.75)
+                let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
+                let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-a075-" + metadata.ownerId + ".png"
+                if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
+                    cell.shared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
                 } else {
-                    let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/128"
+                    let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/" + k_avatar_size
                     let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
-                        if errorCode == 0 && UIImage(data: data!) != nil {
+                        if errorCode == 0 {
                             do {
-                                try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
-                                cell.shared.image = NCUtility.sharedInstance.createAvatar(image: UIImage(contentsOfFile: fileNameLocalPath), size: 30, alpha: 0.75)
-                            } catch { return }
+                                try data!.write(to: NSURL(fileURLWithPath: fileNameSource) as URL, options: .atomic)
+                                cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar, alpha: 0.75)
+                            } catch {  }
                         }
                     })
                 }
@@ -636,18 +637,19 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
             }
             if metadata.ownerId != appDelegate.activeUserID {
                 // Load avatar
-                let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
-                if FileManager.default.fileExists(atPath: fileNameLocalPath) {
-                    cell.shared.image = NCUtility.sharedInstance.createAvatar(image: UIImage(contentsOfFile: fileNameLocalPath), size: 30, alpha: 0.75)
+                let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
+                let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-a075-" + metadata.ownerId + ".png"
+                if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
+                    cell.shared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
                 } else {
-                    let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/128"
+                    let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/" + k_avatar_size
                     let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
-                        if errorCode == 0 && UIImage(data: data!) != nil {
+                        if errorCode == 0 {
                             do {
-                                try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
-                                cell.shared.image = NCUtility.sharedInstance.createAvatar(image: UIImage(contentsOfFile: fileNameLocalPath), size: 30, alpha: 0.75)
-                            } catch { return }
+                                try data!.write(to: NSURL(fileURLWithPath: fileNameSource) as URL, options: .atomic)
+                                 cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar, alpha: 0.75)
+                            } catch {  }
                         }
                     })
                 }

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -77,7 +77,7 @@ class NCService: NSObject {
                 
                 DispatchQueue.global().async {
                     
-                    let avatarUrl = "\(self.appDelegate.activeUrl!)/index.php/avatar/\(self.appDelegate.activeUser!)/128".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
+                    let avatarUrl = "\(self.appDelegate.activeUrl!)/index.php/avatar/\(self.appDelegate.activeUser!)/\(k_avatar_size)".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
                     let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(user, activeUrl: url) + "-" + self.appDelegate.activeUser + ".png"
                     
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: avatarUrl, completion: { (data, message, errorCode) in

+ 1 - 1
iOSClient/Networking/OCNetworking.h

@@ -60,7 +60,7 @@
 
 - (void)downloadPreviewWithAccount:(NSString *)account metadata:(tableMetadata*)metadata withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
 - (void)downloadPreviewWithAccount:(NSString *)account serverPath:(NSString *)serverPath fileNamePath:(NSString *)fileNamePath completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
-- (void)downloadPreviewTrashWithAccount:(NSString *)account fileId:(NSString *)fileId fileName:(NSString *)fileName completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
+- (void)downloadPreviewTrashWithAccount:(NSString *)account fileId:(NSString *)fileId size:(NSString *)size fileName:(NSString *)fileName completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
 
 #pragma mark ===== Favorite =====
 

+ 2 - 2
iOSClient/Networking/OCNetworking.m

@@ -1143,7 +1143,7 @@
     }];
 }
 
-- (void)downloadPreviewTrashWithAccount:(NSString *)account fileId:(NSString *)fileId fileName:(NSString *)fileName completion:(void (^)(NSString *account,  UIImage *image, NSString *message, NSInteger errorCode))completion
+- (void)downloadPreviewTrashWithAccount:(NSString *)account fileId:(NSString *)fileId size:(NSString *)size fileName:(NSString *)fileName completion:(void (^)(NSString *account,  UIImage *image, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -1166,7 +1166,7 @@
         
         [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
         [communication setUserAgent:[CCUtility getUserAgent]];
-        [communication getRemotePreviewTrashByServer:tableAccount.url ofFileId:fileId onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer) {
+        [communication getRemotePreviewTrashByServer:tableAccount.url ofFileId:fileId size:size onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer) {
             
             [preview writeToFile:file atomically:YES];
             

+ 1 - 1
iOSClient/Notification/CCNotification.swift

@@ -111,7 +111,7 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
                         }
                     } else {
                         DispatchQueue.global().async {
-                            let url = self.appDelegate.activeUrl + k_avatar + name + "/128"
+                            let url = self.appDelegate.activeUrl + k_avatar + name + "/" + k_avatar_size
                             let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                             OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
                                 if errorCode == 0 && UIImage(data: data!) != nil  {

+ 3 - 3
iOSClient/Share/NCShare.swift

@@ -81,7 +81,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
             if FileManager.default.fileExists(atPath: fileNameLocalPath) {
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) { sharedWithYouByImage.image = image }
             } else {
-                let url = appDelegate.activeUrl + k_avatar + metadata!.ownerId + "/128"
+                let url = appDelegate.activeUrl + k_avatar + metadata!.ownerId + "/" + k_avatar_size
                 let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                 OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
                     if errorCode == 0 && UIImage(data: data!) != nil {
@@ -255,7 +255,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
             } else {
                 DispatchQueue.global().async {
-                    let url = self.appDelegate.activeUrl + k_avatar + item.name + "/128"
+                    let url = self.appDelegate.activeUrl + k_avatar + item.name + "/" + k_avatar_size
                     let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
                         if errorCode == 0 && UIImage(data: data!) != nil {
@@ -345,7 +345,7 @@ extension NCShare: UITableViewDataSource {
                     if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
                 } else {
                     DispatchQueue.global().async {
-                        let url = self.appDelegate.activeUrl + k_avatar + tableShare.shareWith + "/128"
+                        let url = self.appDelegate.activeUrl + k_avatar + tableShare.shareWith + "/" + k_avatar_size
                         let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                         OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
                             if errorCode == 0 && UIImage(data: data!) != nil {

+ 1 - 1
iOSClient/Share/NCShareComments.swift

@@ -228,7 +228,7 @@ extension NCShareComments: UITableViewDataSource {
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
             } else {
                 DispatchQueue.global().async {
-                    let url = self.appDelegate.activeUrl + k_avatar + tableComments.actorId + "/128"
+                    let url = self.appDelegate.activeUrl + k_avatar + tableComments.actorId + "/" + k_avatar_size
                     let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
                         if errorCode == 0 && UIImage(data: data!) != nil {

+ 1 - 1
iOSClient/Trash/NCTrash.swift

@@ -747,7 +747,7 @@ extension NCTrash {
     
     func downloadThumbnail(with tableTrash: tableTrash, indexPath: IndexPath) {
         
-        OCNetworking.sharedManager().downloadPreviewTrash(withAccount: appDelegate.activeAccount, fileId: tableTrash.fileId, fileName: tableTrash.fileName, completion: { (account, image, message, errorCode) in
+        OCNetworking.sharedManager().downloadPreviewTrash(withAccount: appDelegate.activeAccount, fileId: tableTrash.fileId, size: "128", fileName: tableTrash.fileName, completion: { (account, image, message, errorCode) in
             
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 if let cell = self.collectionView.cellForItem(at: indexPath) {

+ 14 - 6
iOSClient/Utility/NCUtility.swift

@@ -384,13 +384,14 @@ class NCUtility: NSObject {
         CCUtility.deleteAllChainStore()
     }
     
-    @objc func createAvatar(image: UIImage?, size: Int, alpha: CGFloat) -> UIImage? {
+    @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String, alpha: CGFloat) -> UIImage? {
         
-        if image == nil { return image }
+        guard let imageSource = UIImage(contentsOfFile: fileNameSource) else { return nil }
+        let size = Int(k_avatar_size) ?? 128
         
         UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, 0)
-        image?.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
-        var image = UIGraphicsGetImageFromCurrentImageContext()
+        imageSource.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
+        let image = UIGraphicsGetImageFromCurrentImageContext()
         UIGraphicsEndImageContext()
 
         UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, 0)
@@ -398,10 +399,17 @@ class NCUtility: NSObject {
         avatarImageView?.alpha = alpha
         guard let context = UIGraphicsGetCurrentContext() else { return nil }
         avatarImageView?.layer.render(in: context)
-        image = UIGraphicsGetImageFromCurrentImageContext()
+        guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
         UIGraphicsEndImageContext()
         
-        return image
+        guard let data = imageAvatar.pngData() else {
+            return nil
+        }
+        do {
+            try data.write(to: NSURL(fileURLWithPath: fileNameSourceAvatar) as URL, options: .atomic)
+        } catch { }
+        
+        return imageAvatar
     }
 }