marinofaggiana 4 жил өмнө
parent
commit
edf305a08f

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -199,6 +199,7 @@
 		F77D49A91DC238E500CDC568 /* loading.gif in Resources */ = {isa = PBXBuildFile; fileRef = F77D49A71DC238E500CDC568 /* loading.gif */; };
 		F78071091EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */; };
 		F780710A1EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */; };
+		F78111692507AEB500CB218B /* NCCollectionCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78111682507AEB500CB218B /* NCCollectionCommon.swift */; };
 		F78295311F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
 		F782FDC424E6933900666099 /* NCUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70BFC7320E0FA7C00C67599 /* NCUtility.swift */; };
 		F785EE9D246196DF00B3F945 /* NCNetworkingE2EE.swift in Sources */ = {isa = PBXBuildFile; fileRef = F785EE9C246196DF00B3F945 /* NCNetworkingE2EE.swift */; };
@@ -556,6 +557,7 @@
 		F77D49A71DC238E500CDC568 /* loading.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = loading.gif; sourceTree = "<group>"; };
 		F78071071EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNotificationCenter+MainThread.h"; sourceTree = "<group>"; };
 		F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSNotificationCenter+MainThread.m"; sourceTree = "<group>"; };
+		F78111682507AEB500CB218B /* NCCollectionCommon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCCollectionCommon.swift; sourceTree = "<group>"; };
 		F785EE9C246196DF00B3F945 /* NCNetworkingE2EE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCNetworkingE2EE.swift; sourceTree = "<group>"; };
 		F787704E22E7019900F287A9 /* NCShareLinkCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareLinkCell.xib; sourceTree = "<group>"; };
 		F78A18B523CDD07D00F681F3 /* NCViewerRichWorkspaceWebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewerRichWorkspaceWebView.swift; sourceTree = "<group>"; };
@@ -814,6 +816,7 @@
 				F70211FA1BAC56E9003FC03E /* CCMain.h */,
 				F70211FB1BAC56E9003FC03E /* CCMain.m */,
 				F73F537E1E929C8500F8678D /* CCMore.swift */,
+				F78111682507AEB500CB218B /* NCCollectionCommon.swift */,
 				F78F6FAE1CC8CCB700F4EA25 /* CCSection.h */,
 				F78F6FAF1CC8CCB700F4EA25 /* CCSection.m */,
 				F7C1EEA425053A9C00866ACC /* NCDataSource.swift */,
@@ -1981,6 +1984,7 @@
 				F78ACD4021903CC20088454D /* NCGridCell.swift in Sources */,
 				37ECC83B23D0C7410082EFA2 /* NCMenuAction.swift in Sources */,
 				F75B0ABD244C4DBB00E58DCA /* NCNetworkingNotificationCenter.swift in Sources */,
+				F78111692507AEB500CB218B /* NCCollectionCommon.swift in Sources */,
 				F79018B8240962C7007C9B6D /* NCViewerImageViewController.swift in Sources */,
 				F769454022E9F077000A798A /* NCSharePaging.swift in Sources */,
 				F78ACD4221903CE00088454D /* NCListCell.swift in Sources */,

+ 1 - 1
iOSClient/Favorites/NCFavorite.swift

@@ -512,7 +512,7 @@ extension NCFavorite: UICollectionViewDataSource {
         
         let shares = NCManageDatabase.sharedInstance.getTableShares(account: metadata.account, serverUrl: metadata.serverUrl, fileName: metadata.fileName)
         
-        NCMainCommon.shared.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectocId: selectocId, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: false, downloadThumbnail: true, shares: shares, source: self)
+        NCCollectionCommon.shared.cellForItemAt(indexPath: indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectocId: selectocId, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: false, downloadThumbnail: true, shares: shares, source: self)
         
         return cell
     }

+ 339 - 0
iOSClient/Main/NCCollectionCommon.swift

@@ -0,0 +1,339 @@
+//
+//  NCCollectionCommon.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 08/09/2020.
+//  Copyright © 2020 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import Foundation
+import TLPhotoPicker
+import ZIPFoundation
+import NCCommunication
+
+class NCCollectionCommon: NSObject {
+    @objc static let shared: NCCollectionCommon = {
+        let instance = NCCollectionCommon()
+        instance.createImagesThemingColor()
+        return instance
+    }()
+
+    struct NCCollectionCommonImages {
+        static var cellSharedImage = UIImage()
+        static var cellCanShareImage = UIImage()
+        static var cellShareByLinkImage = UIImage()
+        static var cellFavouriteImage = UIImage()
+        static var cellMoreImage = UIImage()
+        static var cellCommentImage = UIImage()
+        static var cellLivePhotoImage = UIImage()
+
+        static var cellFolderEncryptedImage = UIImage()
+        static var cellFolderSharedWithMeImage = UIImage()
+        static var cellFolderPublicImage = UIImage()
+        static var cellFolderGroupImage = UIImage()
+        static var cellFolderExternalImage = UIImage()
+        static var cellFolderAutomaticUploadImage = UIImage()
+        static var cellFolderImage = UIImage()
+        
+        static var cellPlayImage = UIImage()
+    }
+    
+    @objc func createImagesThemingColor() {
+        NCCollectionCommonImages.cellSharedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
+        NCCollectionCommonImages.cellCanShareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.optionItem)
+        NCCollectionCommonImages.cellShareByLinkImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 100, height: 100, color: NCBrandColor.sharedInstance.optionItem)
+        NCCollectionCommonImages.cellFavouriteImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 100, height: 100, color: NCBrandColor.sharedInstance.yellowFavorite)
+        NCCollectionCommonImages.cellMoreImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
+        NCCollectionCommonImages.cellCommentImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "comment"), width: 30, height: 30, color: NCBrandColor.sharedInstance.graySoft)
+        NCCollectionCommonImages.cellLivePhotoImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "livePhoto"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
+        
+        NCCollectionCommonImages.cellFolderEncryptedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderEncrypted"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        NCCollectionCommonImages.cellFolderSharedWithMeImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_shared_with_me"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        NCCollectionCommonImages.cellFolderPublicImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_public"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        NCCollectionCommonImages.cellFolderGroupImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_group"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        NCCollectionCommonImages.cellFolderExternalImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_external"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        NCCollectionCommonImages.cellFolderAutomaticUploadImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderAutomaticUpload"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        NCCollectionCommonImages.cellFolderImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
+        
+        NCCollectionCommonImages.cellPlayImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "play"), width: 100, height: 100, color: .white)
+    }
+    
+    // MARK -
+    
+    func cellForItemAt(indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, selectocId: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController) {
+        
+        let appDelegate = UIApplication.shared.delegate as! AppDelegate
+        var tableShare: tableShare?
+        
+        // Share
+        if shares != nil {
+            for share in shares! {
+                if share.fileName == metadata.fileName {
+                    tableShare = share
+                    break
+                }
+            }
+        }
+        
+        // Download preview
+        if downloadThumbnail {
+            NCOperationQueue.shared.downloadThumbnail(metadata: metadata, urlBase: appDelegate.urlBase, view: collectionView, indexPath: indexPath)
+        }
+        
+        var isShare = false
+        var isMounted = false
+        
+        if metadataFolder != nil {
+            isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
+            isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
+        }
+        
+        if cell is NCListCell {
+            
+            let cell = cell as! NCListCell
+           
+            cell.delegate = source as? NCListCellDelegate
+            
+            cell.objectId = metadata.ocId
+            cell.indexPath = indexPath
+            cell.labelTitle.text = metadata.fileNameView
+            cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
+            cell.imageStatus.image = nil
+            cell.imageLocal.image = nil
+            cell.imageFavorite.image = nil
+            cell.imageShared.image = nil
+            
+            if metadata.directory {
+                
+                if metadata.e2eEncrypted {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderEncryptedImage
+                } else if isShare {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
+                } else if (tableShare != nil && tableShare!.shareType != 3) {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
+                } else if (tableShare != nil && tableShare!.shareType == 3) {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderPublicImage
+                } else if metadata.mountType == "group" {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderGroupImage
+                } else if isMounted {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderExternalImage
+                } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderAutomaticUploadImage
+                } else {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderImage
+                }
+                
+                cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
+                
+                let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
+                let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
+                
+                // Local image: offline
+                if tableDirectory != nil && tableDirectory!.offline {
+                    cell.imageLocal.image = UIImage.init(named: "offlineFlag")
+                }
+                
+            } else {
+                
+                if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
+                    cell.imageItem.image =  UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
+                } else if(!metadata.hasPreview) {
+                    if metadata.iconName.count > 0 {
+                        cell.imageItem.image = UIImage.init(named: metadata.iconName)
+                    } else {
+                        cell.imageItem.image = UIImage.init(named: "file")
+                    }
+                }
+                
+                cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
+                
+                //  image local
+                let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
+                if size > 0 {
+                    let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                    if tableLocalFile == nil && size == metadata.size {
+                        NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
+                    }
+                    if tableLocalFile?.offline ?? false {
+                        cell.imageLocal.image = UIImage.init(named: "offlineFlag")
+                    } else{
+                        cell.imageLocal.image = UIImage.init(named: "local")
+                    }
+                }
+            }
+            
+            // image Favorite
+            if metadata.favorite {
+                cell.imageFavorite.image = NCCollectionCommonImages.cellFavouriteImage
+            }
+            
+            // Share image
+            if (isShare) {
+                cell.imageShared.image = NCCollectionCommonImages.cellSharedImage
+            } else if (tableShare != nil && tableShare!.shareType == 3) {
+                cell.imageShared.image = NCCollectionCommonImages.cellShareByLinkImage
+            } else if (tableShare != nil && tableShare!.shareType != 3) {
+                cell.imageShared.image = NCCollectionCommonImages.cellSharedImage
+            } else {
+                cell.imageShared.image = NCCollectionCommonImages.cellCanShareImage
+            }
+            if metadata.ownerId != appDelegate.userID {
+                // Load avatar
+                let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId + ".png"
+                let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-avatar-" + metadata.ownerId + ".png"
+                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)
+                } else {
+                    NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size)) { (account, data, errorCode, errorMessage) in
+                        if errorCode == 0 && account == appDelegate.account {
+                            cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
+                        }
+                    }
+                }
+            }
+            
+            if isEditMode {
+                cell.imageItemLeftConstraint.constant = 45
+                cell.imageSelect.isHidden = false
+                
+                if selectocId.contains(metadata.ocId) {
+                    cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
+                    cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
+                } else {
+                    cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedNo"), to: CGSize(width: 50, height: 50), isAspectRation: true)
+                    cell.backgroundView = nil
+                }
+            } else {
+                cell.imageItemLeftConstraint.constant = 10
+                cell.imageSelect.isHidden = true
+                cell.backgroundView = nil
+            }
+            
+            // Transfer
+            if metadata.status == k_metadataStatusInDownload  ||  metadata.status >= k_metadataStatusTypeUpload {
+                cell.progressView.isHidden = false
+                cell.setButtonMore(named: "stop")
+            } else {
+                cell.progressView.isHidden = true
+                cell.progressView.progress = 0.0
+                cell.setButtonMore(named: "more")
+            }
+            
+            // Remove last separator
+            if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
+                cell.separator.isHidden = true
+            } else {
+                cell.separator.isHidden = false
+            }
+            
+        } else if cell is NCGridCell {
+            
+            let cell = cell as! NCGridCell
+
+            cell.delegate = source as? NCGridCellDelegate
+            
+            cell.objectId = metadata.ocId
+            cell.indexPath = indexPath
+            cell.labelTitle.text = metadata.fileNameView
+            cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
+            cell.imageStatus.image = nil
+            cell.imageLocal.image = nil
+            cell.imageFavorite.image = nil
+            
+            if metadata.directory {
+                
+                if metadata.e2eEncrypted {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderEncryptedImage
+                } else if isShare {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
+                } else if (tableShare != nil && tableShare!.shareType != 3) {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
+                } else if (tableShare != nil && tableShare!.shareType == 3) {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderPublicImage
+                } else if metadata.mountType == "group" {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderGroupImage
+                } else if isMounted {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderExternalImage
+                } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderAutomaticUploadImage
+                } else {
+                    cell.imageItem.image = NCCollectionCommonImages.cellFolderImage
+                }
+                
+    
+                let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
+                let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
+                                
+                // Local image: offline
+                if tableDirectory != nil && tableDirectory!.offline {
+                    cell.imageLocal.image = UIImage.init(named: "offlineFlag")
+                }
+                
+            } else {
+                
+                if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
+                    cell.imageItem.image =  UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
+                } else if(!metadata.hasPreview) {
+                    if metadata.iconName.count > 0 {
+                        cell.imageItem.image = UIImage.init(named: metadata.iconName)
+                    } else {
+                        cell.imageItem.image = UIImage.init(named: "file")
+                    }
+                }
+                
+                // image Local
+                let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                    if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
+                    else { cell.imageLocal.image = UIImage.init(named: "local") }
+                }
+            }
+            
+            // image Favorite
+            if metadata.favorite {
+                cell.imageFavorite.image = NCCollectionCommonImages.cellFavouriteImage
+            }
+            
+            if isEditMode {
+                cell.imageSelect.isHidden = false
+                if selectocId.contains(metadata.ocId) {
+                    cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
+                    cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
+                } else {
+                    cell.imageSelect.isHidden = true
+                    cell.backgroundView = nil
+                }
+            } else {
+                cell.imageSelect.isHidden = true
+                cell.backgroundView = nil
+            }
+            
+            // Transfer
+            if metadata.status == k_metadataStatusInDownload  ||  metadata.status >= k_metadataStatusTypeUpload {
+                cell.progressView.isHidden = false
+                cell.setButtonMore(named: "stop")
+            } else {
+                cell.progressView.isHidden = true
+                cell.progressView.progress = 0.0
+                cell.setButtonMore(named: "more")
+            }
+        }
+    }
+}

+ 0 - 262
iOSClient/Main/NCMainCommon.swift

@@ -214,268 +214,6 @@ class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentI
     
     //MARK: -
     
-    func collectionViewCellForItemAt(_ indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, selectocId: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController) {
-        
-        let appDelegate = UIApplication.shared.delegate as! AppDelegate
-        var tableShare: tableShare?
-        
-        // Share
-        if shares != nil {
-            for share in shares! {
-                if share.fileName == metadata.fileName {
-                    tableShare = share
-                    break
-                }
-            }
-        }
-        
-        // Download preview
-        if downloadThumbnail {
-            NCOperationQueue.shared.downloadThumbnail(metadata: metadata, urlBase: appDelegate.urlBase, view: collectionView, indexPath: indexPath)
-        }
-        
-        var isShare = false
-        var isMounted = false
-        
-        if metadataFolder != nil {
-            isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
-            isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
-        }
-        
-        if cell is NCListCell {
-            
-            let cell = cell as! NCListCell
-           
-            cell.delegate = source as? NCListCellDelegate
-            
-            cell.objectId = metadata.ocId
-            cell.indexPath = indexPath
-            cell.labelTitle.text = metadata.fileNameView
-            cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
-            cell.imageStatus.image = nil
-            cell.imageLocal.image = nil
-            cell.imageFavorite.image = nil
-            cell.imageShared.image = nil
-            
-            if metadata.directory {
-                
-                if metadata.e2eEncrypted {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderEncryptedImage
-                } else if isShare {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
-                } else if (tableShare != nil && tableShare!.shareType != 3) {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
-                } else if (tableShare != nil && tableShare!.shareType == 3) {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderPublicImage
-                } else if metadata.mountType == "group" {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderGroupImage
-                } else if isMounted {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderExternalImage
-                } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderAutomaticUploadImage
-                } else {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderImage
-                }
-                
-                cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
-                
-                let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
-                let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
-                
-                // Local image: offline
-                if tableDirectory != nil && tableDirectory!.offline {
-                    cell.imageLocal.image = UIImage.init(named: "offlineFlag")
-                }
-                
-            } else {
-                
-                if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
-                    cell.imageItem.image =  UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
-                } else if(!metadata.hasPreview) {
-                    if metadata.iconName.count > 0 {
-                        cell.imageItem.image = UIImage.init(named: metadata.iconName)
-                    } else {
-                        cell.imageItem.image = UIImage.init(named: "file")
-                    }
-                }
-                
-                cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
-                
-                //  image local
-                let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                if size > 0 {
-                    let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                    if tableLocalFile == nil && size == metadata.size {
-                        NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
-                    }
-                    if tableLocalFile?.offline ?? false {
-                        cell.imageLocal.image = UIImage.init(named: "offlineFlag")
-                    } else{
-                        cell.imageLocal.image = UIImage.init(named: "local")
-                    }
-                }
-            }
-            
-            // image Favorite
-            if metadata.favorite {
-                cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
-            }
-            
-            // Share image
-            if (isShare) {
-                cell.imageShared.image = NCMainCommonImages.cellSharedImage
-            } else if (tableShare != nil && tableShare!.shareType == 3) {
-                cell.imageShared.image = NCMainCommonImages.cellShareByLinkImage
-            } else if (tableShare != nil && tableShare!.shareType != 3) {
-                cell.imageShared.image = NCMainCommonImages.cellSharedImage
-            } else {
-                cell.imageShared.image = NCMainCommonImages.cellCanShareImage
-            }
-            if metadata.ownerId != appDelegate.userID {
-                // Load avatar
-                let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId + ".png"
-                let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-avatar-" + metadata.ownerId + ".png"
-                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)
-                } else {
-                    NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size)) { (account, data, errorCode, errorMessage) in
-                        if errorCode == 0 && account == appDelegate.account {
-                            cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
-                        }
-                    }
-                }
-            }
-            
-            if isEditMode {
-                cell.imageItemLeftConstraint.constant = 45
-                cell.imageSelect.isHidden = false
-                
-                if selectocId.contains(metadata.ocId) {
-                    cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
-                    cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
-                } else {
-                    cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedNo"), to: CGSize(width: 50, height: 50), isAspectRation: true)
-                    cell.backgroundView = nil
-                }
-            } else {
-                cell.imageItemLeftConstraint.constant = 10
-                cell.imageSelect.isHidden = true
-                cell.backgroundView = nil
-            }
-            
-            // Transfer
-            if metadata.status == k_metadataStatusInDownload  ||  metadata.status >= k_metadataStatusTypeUpload {
-                cell.progressView.isHidden = false
-                cell.setButtonMore(named: "stop")
-            } else {
-                cell.progressView.isHidden = true
-                cell.progressView.progress = 0.0
-                cell.setButtonMore(named: "more")
-            }
-            
-            // Remove last separator
-            if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
-                cell.separator.isHidden = true
-            } else {
-                cell.separator.isHidden = false
-            }
-            
-        } else if cell is NCGridCell {
-            
-            let cell = cell as! NCGridCell
-
-            cell.delegate = source as? NCGridCellDelegate
-            
-            cell.objectId = metadata.ocId
-            cell.indexPath = indexPath
-            cell.labelTitle.text = metadata.fileNameView
-            cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
-            cell.imageStatus.image = nil
-            cell.imageLocal.image = nil
-            cell.imageFavorite.image = nil
-            
-            if metadata.directory {
-                
-                if metadata.e2eEncrypted {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderEncryptedImage
-                } else if isShare {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
-                } else if (tableShare != nil && tableShare!.shareType != 3) {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
-                } else if (tableShare != nil && tableShare!.shareType == 3) {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderPublicImage
-                } else if metadata.mountType == "group" {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderGroupImage
-                } else if isMounted {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderExternalImage
-                } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderAutomaticUploadImage
-                } else {
-                    cell.imageItem.image = NCMainCommonImages.cellFolderImage
-                }
-                
-    
-                let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
-                let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
-                                
-                // Local image: offline
-                if tableDirectory != nil && tableDirectory!.offline {
-                    cell.imageLocal.image = UIImage.init(named: "offlineFlag")
-                }
-                
-            } else {
-                
-                if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
-                    cell.imageItem.image =  UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
-                } else if(!metadata.hasPreview) {
-                    if metadata.iconName.count > 0 {
-                        cell.imageItem.image = UIImage.init(named: metadata.iconName)
-                    } else {
-                        cell.imageItem.image = UIImage.init(named: "file")
-                    }
-                }
-                
-                // image Local
-                let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-                    if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
-                    else { cell.imageLocal.image = UIImage.init(named: "local") }
-                }
-            }
-            
-            // image Favorite
-            if metadata.favorite {
-                cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
-            }
-            
-            if isEditMode {
-                cell.imageSelect.isHidden = false
-                if selectocId.contains(metadata.ocId) {
-                    cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
-                    cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
-                } else {
-                    cell.imageSelect.isHidden = true
-                    cell.backgroundView = nil
-                }
-            } else {
-                cell.imageSelect.isHidden = true
-                cell.backgroundView = nil
-            }
-            
-            // Transfer
-            if metadata.status == k_metadataStatusInDownload  ||  metadata.status >= k_metadataStatusTypeUpload {
-                cell.progressView.isHidden = false
-                cell.setButtonMore(named: "stop")
-            } else {
-                cell.progressView.isHidden = true
-                cell.progressView.progress = 0.0
-                cell.setButtonMore(named: "more")
-            }
-        }
-    }
-    
     @objc func cellForRowAtIndexPath(_ indexPath: IndexPath, tableView: UITableView ,metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, autoUploadFileName: String, autoUploadDirectory: String, tableShare: tableShare?, livePhoto: Bool) -> UITableViewCell {
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
 

+ 1 - 1
iOSClient/Offline/NCOffline.swift

@@ -515,7 +515,7 @@ extension NCOffline: UICollectionViewDataSource {
         
         let shares = NCManageDatabase.sharedInstance.getTableShares(account: metadata.account, serverUrl: metadata.serverUrl, fileName: metadata.fileName)
         
-        NCMainCommon.shared.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectocId: selectocId, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: false, downloadThumbnail: true, shares: shares, source: self)
+        NCCollectionCommon.shared.cellForItemAt(indexPath: indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectocId: selectocId, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: false, downloadThumbnail: true, shares: shares, source: self)
         
         return cell
     }

+ 1 - 1
iOSClient/Select/NCSelect.swift

@@ -475,7 +475,7 @@ extension NCSelect: UICollectionViewDataSource {
             cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
         }
         
-        NCMainCommon.shared.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: metadataFolder, serverUrl: serverUrl, isEditMode: isEditMode, selectocId: selectocId, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory ,hideButtonMore: true, downloadThumbnail: true, shares: shares, source: self)
+        NCCollectionCommon.shared.cellForItemAt(indexPath: indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: metadataFolder, serverUrl: serverUrl, isEditMode: isEditMode, selectocId: selectocId, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory ,hideButtonMore: true, downloadThumbnail: true, shares: shares, source: self)
         
         if layout == k_layout_grid {
             let cell = cell as! NCGridCell