marinofaggiana преди 5 години
родител
ревизия
2a5e298bec
променени са 5 файла, в които са добавени 68 реда и са изтрити 56 реда
  1. 5 14
      iOSClient/Favorites/CCFavorites.m
  2. 7 25
      iOSClient/Main/CCMain.m
  3. 8 5
      iOSClient/Main/Cell/CCCellMain.xib
  4. 29 12
      iOSClient/Main/NCMainCommon.swift
  5. 19 0
      iOSClient/Utility/NCUtility.swift

+ 5 - 14
iOSClient/Favorites/CCFavorites.m

@@ -576,9 +576,7 @@
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     tableShare *shareCell;
-    BOOL isShare = false;
-    BOOL isMounted = false;
-    
+   
     tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
     if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
         return [CCCellMain new];
@@ -605,17 +603,10 @@
     if ([cell isKindOfClass:[CCCellMain class]]) {
         
         // Share add Tap
-        if (metadataFolder) {
-            isShare = [metadata.permissions containsString:k_permission_shared] && ![metadataFolder.permissions containsString:k_permission_shared];
-            isMounted = [metadata.permissions containsString:k_permission_mounted] && ![metadataFolder.permissions containsString:k_permission_mounted];
-        }
-        if (isShare || isMounted || shareCell) {
-            
-            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
-            [tap setNumberOfTapsRequired:1];
-            ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
-            [((CCCellMain *)cell).shared addGestureRecognizer:tap];
-        }
+        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
+        [tap setNumberOfTapsRequired:1];
+        ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
+        [((CCCellMain *)cell).shared addGestureRecognizer:tap];
         
         // More
         if ([self canOpenMenuAction:metadata]) {

+ 7 - 25
iOSClient/Main/CCMain.m

@@ -1981,17 +1981,8 @@
         UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
         if (avatar) {
             
-            avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
-            
-            CCAvatar *avatarImageView = [[CCAvatar 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();
-            
+            avatar = [[NCUtility sharedInstance] createAvatarWithImage:avatar size:25];
+                    
         } else {
             
             avatar = [UIImage imageNamed:@"menuLogoUser"];
@@ -3708,9 +3699,7 @@
 {
     tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
     tableShare *shareCell;
-    BOOL isShare = false;
-    BOOL isMounted = false;
-    
+   
     if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || (_metadataFolder != nil && [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])) {
         return [CCCellMain new];
     }
@@ -3729,17 +3718,10 @@
     if ([cell isKindOfClass:[CCCellMain class]]) {
         
         // Share add Tap
-        if (_metadataFolder) {
-            isShare = [metadata.permissions containsString:k_permission_shared] && ![_metadataFolder.permissions containsString:k_permission_shared];
-            isMounted = [metadata.permissions containsString:k_permission_mounted] && ![_metadataFolder.permissions containsString:k_permission_mounted];
-        }
-        if (isShare || isMounted || shareCell) {
-            
-            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
-            [tap setNumberOfTapsRequired:1];
-            ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
-            [((CCCellMain *)cell).shared addGestureRecognizer:tap];
-        }
+        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
+        [tap setNumberOfTapsRequired:1];
+        ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
+        [((CCCellMain *)cell).shared addGestureRecognizer:tap];
         
         // More
         if ([self canOpenMenuAction:metadata]) {

+ 8 - 5
iOSClient/Main/Cell/CCCellMain.xib

@@ -19,13 +19,13 @@
                 <autoresizingMask key="autoresizingMask"/>
                 <subviews>
                     <label opaque="NO" userInteractionEnabled="NO" tag="101" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QNC-8X-DAC">
-                        <rect key="frame" x="65" y="13" width="430" height="18"/>
+                        <rect key="frame" x="65" y="13" width="416" height="18"/>
                         <fontDescription key="fontDescription" type="system" pointSize="15"/>
                         <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <nil key="highlightedColor"/>
                     </label>
                     <label opaque="NO" userInteractionEnabled="NO" tag="102" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p7I-KN-FVZ">
-                        <rect key="frame" x="65" y="30.5" width="430" height="15"/>
+                        <rect key="frame" x="65" y="30.5" width="416" height="15"/>
                         <fontDescription key="fontDescription" type="system" pointSize="12"/>
                         <color key="textColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
                         <nil key="highlightedColor"/>
@@ -58,11 +58,11 @@
                             <constraint firstAttribute="height" constant="15" id="Oxa-YI-vu7"/>
                         </constraints>
                     </imageView>
-                    <imageView userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="qhJ-el-R92" userLabel="Shared Image View">
-                        <rect key="frame" x="505" y="-0.5" width="40" height="60.5"/>
+                    <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="491" y="-0.5" width="54" height="60.5"/>
                         <constraints>
                             <constraint firstAttribute="height" constant="60" id="3Kr-Hv-AdZ"/>
-                            <constraint firstAttribute="width" constant="40" id="Ijp-se-6KO"/>
+                            <constraint firstAttribute="width" constant="54" id="Ijp-se-6KO"/>
                         </constraints>
                     </imageView>
                     <imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="aRp-Ql-cyA" userLabel="More">
@@ -109,4 +109,7 @@
             <point key="canvasLocation" x="664" y="152.02398800599701"/>
         </tableViewCell>
     </objects>
+    <resources>
+        <image name="avatar" width="25" height="25"/>
+    </resources>
 </document>

+ 29 - 12
iOSClient/Main/NCMainCommon.swift

@@ -555,18 +555,18 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                 // File Image & Image Title Segue
                 if metadata.e2eEncrypted {
                     image = UIImage.init(named: "folderEncrypted")
-                } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
-                    image = UIImage.init(named: "folderAutomaticUpload")
-                } else if metadata.mountType == "group" {
-                    image = UIImage.init(named: "folder_group")
                 } else if isShare {
                     image = UIImage.init(named: "folder_shared_with_me")
-                } else if isMounted {
-                    image = UIImage.init(named: "folder_external")
                 } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_shared_with_me")
                 } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_public")
+                } else if metadata.mountType == "group" {
+                    image = UIImage.init(named: "folder_group")
+                } else if isMounted {
+                    image = UIImage.init(named: "folder_external")
+                } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
+                    image = UIImage.init(named: "folderAutomaticUpload")
                 } else {
                     image = UIImage.init(named: "folder")
                 }
@@ -625,15 +625,32 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                 cell.favorite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), multiplier: 2, color: NCBrandColor.sharedInstance.yellowFavorite)
             }
             
-            // Share
+            // Share image
             if (isShare) {
-                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
-            } else if (isMounted) {
-                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMounted"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
+                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 30, height: 30, color: .black)
             } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
-                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
+                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 30, height: 30, color: .black)
             } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
-                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
+                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 30, height: 30, color: .black)
+            } else {
+                cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 30, height: 30, color: NCBrandColor.sharedInstance.graySoft)
+            }
+            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)
+                } else {
+                    let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/128"
+                    let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
+                    OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
+                        if errorCode == 0 && UIImage(data: data!) != nil {
+                            do {
+                                try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
+                            } catch {  }
+                        }
+                    })
+                }
             }
             
             // More Image

+ 19 - 0
iOSClient/Utility/NCUtility.swift

@@ -394,5 +394,24 @@ class NCUtility: NSObject {
         
         CCUtility.deleteAllChainStore()
     }
+    
+    @objc func createAvatar(image: UIImage?, size: Int) -> UIImage? {
+        
+        if image == nil { return image }
+        
+        UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, 0)
+        image?.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
+        var image = UIGraphicsGetImageFromCurrentImageContext()
+        UIGraphicsEndImageContext()
+
+        UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, 0)
+        let avatarImageView = CCAvatar.init(image: image, borderColor: .lightGray, borderWidth: 0.5)
+        guard let context = UIGraphicsGetCurrentContext() else { return nil }
+        avatarImageView?.layer.render(in: context)
+        image = UIGraphicsGetImageFromCurrentImageContext()
+        UIGraphicsEndImageContext()
+        
+        return image
+    }
 }