marinofaggiana 4 år sedan
förälder
incheckning
89c4afa0e3

+ 12 - 13
iOSClient/Main/Collection/NCCollectionCommon.swift

@@ -39,6 +39,8 @@ class NCCollectionCommon: NSObject {
         static var cellMoreImage = UIImage()
         static var cellCommentImage = UIImage()
         static var cellLivePhotoImage = UIImage()
+        static var cellOfflineFlag = UIImage()
+        static var cellLocal = UIImage()
 
         static var cellFolderEncryptedImage = UIImage()
         static var cellFolderSharedWithMeImage = UIImage()
@@ -64,7 +66,9 @@ class NCCollectionCommon: NSObject {
         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.cellOfflineFlag = UIImage.init(named: "offlineFlag")!
+        NCCollectionCommonImages.cellLocal = UIImage.init(named: "local")!
+            
         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)
@@ -81,7 +85,7 @@ class NCCollectionCommon: NSObject {
     
     // MARK: -
     
-    func cellForItemAt(indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, isEncryptedFolder: Bool, selectocId: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController, dataSource: NCDataSource?) {
+    func cellForItemAt(indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, isEncryptedFolder: Bool, selectocId: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController, dataSource: NCDataSource) {
         
         var tableShare: tableShare?
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -165,6 +169,7 @@ class NCCollectionCommon: NSObject {
                 
             } 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 {
@@ -182,18 +187,12 @@ class NCCollectionCommon: NSObject {
                 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")
-                    }
+                if dataSource.metadataLocalImage[metadata.ocId] == "offlineFlag" {
+                    cell.imageLocal.image = NCCollectionCommonImages.cellOfflineFlag
+                } else if dataSource.metadataLocalImage[metadata.ocId] == "local" {
+                    cell.imageLocal.image = NCCollectionCommonImages.cellLocal
                 }
+                
             }
             
             // image Favorite

+ 23 - 23
iOSClient/Main/Collection/NCCollectionViewCommon.swift

@@ -41,7 +41,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     internal var metadatasSource: [tableMetadata] = []
     internal var metadataFolder: tableMetadata?
     internal var metadataTouch: tableMetadata?
-    internal var dataSource: NCDataSource?
+    internal var dataSource = NCDataSource()
     internal var richWorkspaceText: String?
         
     internal var layout = ""
@@ -253,12 +253,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if let metadata = userInfo["metadata"] as? tableMetadata, let onlyLocal = userInfo["onlyLocal"] as? Bool {
                 
                 if onlyLocal {
-                    if let row = dataSource?.reloadMetadata(ocId: metadata.ocId) {
+                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.reloadItems(at: [indexPath])
                     }
                 } else {
-                    if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.deleteItems(at: [indexPath])
@@ -278,7 +278,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if let metadata = userInfo["metadata"] as? tableMetadata, let metadataNew = userInfo["metadataNew"] as? tableMetadata {
                 
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                    if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.deleteItems(at: [indexPath])
@@ -287,7 +287,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                         })
                     }
                 } else if metadataNew.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                    if let row = dataSource?.addMetadata(metadataNew) {
+                    if let row = dataSource.addMetadata(metadataNew) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.insertItems(at: [indexPath])
@@ -318,7 +318,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
                 
-                if let row = dataSource?.reloadMetadata(ocId: metadata.ocId) {
+                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                     let indexPath = IndexPath(row: row, section: 0)
                     collectionView?.performBatchUpdates({
                         collectionView?.reloadItems(at: [indexPath])
@@ -336,7 +336,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                    if let row = dataSource?.addMetadata(metadata) {
+                    if let row = dataSource.addMetadata(metadata) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.insertItems(at: [indexPath])
@@ -356,7 +356,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
-                if dataSource?.getIndexMetadata(ocId: metadata.ocId) != nil {
+                if dataSource.getIndexMetadata(ocId: metadata.ocId) != nil {
                     self.reloadDataSource()
                 }
             }
@@ -369,7 +369,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
                 
-                if let row = dataSource?.reloadMetadata(ocId: metadata.ocId) {
+                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                     let indexPath = IndexPath(row: row, section: 0)
                     collectionView?.reloadItems(at: [indexPath])
                 }
@@ -383,7 +383,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata, let _ = userInfo["errorCode"] as? Int {
                 
-               if let row = dataSource?.reloadMetadata(ocId: metadata.ocId) {
+               if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                    let indexPath = IndexPath(row: row, section: 0)
                    collectionView?.reloadItems(at: [indexPath])
                }
@@ -397,7 +397,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
                
-                if let row = dataSource?.reloadMetadata(ocId: metadata.ocId) {
+                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                     let indexPath = IndexPath(row: row, section: 0)
                     collectionView?.reloadItems(at: [indexPath])
                 }
@@ -412,7 +412,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if let metadata = userInfo["metadata"] as? tableMetadata {
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
                     
-                    if let row = dataSource?.addMetadata(metadata) {
+                    if let row = dataSource.addMetadata(metadata) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.insertItems(at: [indexPath])
@@ -432,7 +432,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if let metadata = userInfo["metadata"] as? tableMetadata, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int {
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
                    
-                    dataSource?.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
+                    dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
                     collectionView?.reloadData()
                 }
             }
@@ -446,7 +446,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if let metadata = userInfo["metadata"] as? tableMetadata {
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
                     
-                    if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.deleteItems(at: [indexPath])
@@ -477,7 +477,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 
                 appDelegate.listProgressMetadata.setObject([progress as NSNumber, totalBytes as NSNumber, totalBytesExpected as NSNumber], forKey: userInfo["ocId"] as? NSString ?? "")
                 
-                if let index = dataSource?.getIndexMetadata(ocId: ocId) {
+                if let index = dataSource.getIndexMetadata(ocId: ocId) {
                     if let cell = collectionView?.cellForItem(at: IndexPath(row: index, section: 0)) {
                         if cell is NCListCell {
                             let cell = cell as! NCListCell
@@ -893,7 +893,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         let photoDataSource: NSMutableArray = []
         
-        for metadata in (dataSource?.metadatas ?? [tableMetadata]()) {
+        for metadata in (dataSource.metadatas) {
             if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video {
                 photoDataSource.add(metadata)
             }
@@ -1013,7 +1013,7 @@ extension NCCollectionViewCommon: UIViewControllerPreviewingDelegate {
         
         guard let point = collectionView?.convert(location, from: collectionView?.superview) else { return nil }
         guard let indexPath = collectionView?.indexPathForItem(at: point) else { return nil }
-        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return nil }
+        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return nil }
         guard let viewController = UIStoryboard(name: "CCPeekPop", bundle: nil).instantiateViewController(withIdentifier: "PeekPopImagePreview") as? CCPeekPop else { return nil }
 
         viewController.metadata = metadata
@@ -1049,7 +1049,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
 
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         
-        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return }
+        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
         metadataTouch = metadata
         
         if isEditMode {
@@ -1221,7 +1221,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             header.delegate = self
             header.backgroundColor = NCBrandColor.sharedInstance.backgroundView
             header.separator.backgroundColor = NCBrandColor.sharedInstance.separator
-            header.setStatusButton(count: dataSource?.metadatas.count ?? 0)
+            header.setStatusButton(count: dataSource.metadatas.count)
             header.setTitleSorted(datasourceTitleButton: titleButton)
             header.viewRichWorkspaceHeightConstraint.constant = headerRichWorkspaceHeight
             header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
@@ -1232,8 +1232,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             
             let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
             
-            let info = dataSource?.getFilesInformation()
-            footer.setTitleLabel(directories: info?.directories ?? 0, files: info?.files ?? 0, size: info?.size ?? 0)
+            let info = dataSource.getFilesInformation()
+            footer.setTitleLabel(directories: info.directories, files: info.files, size: info.size )
             
             return footer
         }
@@ -1244,14 +1244,14 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return dataSource?.numberOfItems() ?? 0
+        return dataSource.numberOfItems()
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
         let cell: UICollectionViewCell
         
-        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else {
+        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
             return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
         }
         

+ 27 - 4
iOSClient/Main/NCDataSource.swift

@@ -23,10 +23,12 @@
 
 import Foundation
 
-@objc class NCDataSource: NSObject {
+class NCDataSource: NSObject {
+    
+    public var metadatas: [tableMetadata] = []
+    public var metadataPreview: [String:String] = [:]
+    public var metadataLocalImage: [String:String] = [:]
     
-    @objc var metadatas: [tableMetadata] = []
-
     private var sort: String = ""
     private var ascending: Bool = true
     private var directoryOnTop: Bool = true
@@ -36,7 +38,7 @@ import Foundation
         super.init()
     }
     
-    @objc init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, directoryOnTop: Bool, filterLivePhoto: Bool) {
+    init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, directoryOnTop: Bool, filterLivePhoto: Bool) {
         super.init()
         
         self.sort = sort
@@ -100,6 +102,27 @@ import Foundation
                 continue
             }
             
+            // Preview
+            if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
+                metadataPreview[metadata.ocId] = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
+            }
+            
+            // is Local / offline
+            if !metadata.directory {
+                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 {
+                        metadataLocalImage[metadata.ocId] = "offlineFlag"
+                    } else {
+                        metadataLocalImage[metadata.ocId] = "local"
+                    }
+                }
+            }
+            
             if metadata.directory && directoryOnTop {
                 if metadata.favorite {
                     metadatasTemp.insert(metadata, at: numDirectoryFavorite)

+ 7 - 7
iOSClient/Select/NCSelect.swift

@@ -74,7 +74,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, NCListCellDelegat
     private var selectocId: [String] = []
     private var overwrite = false
     
-    private var dataSource: NCDataSource?
+    private var dataSource = NCDataSource()
     internal var richWorkspaceText: String?
 
     private var layout = ""
@@ -361,7 +361,7 @@ extension NCSelect: UICollectionViewDelegate {
 
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         
-        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return }
+        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
         
         if isEditMode {
             if let index = selectocId.firstIndex(of: metadata.ocId) {
@@ -422,7 +422,7 @@ extension NCSelect: UICollectionViewDataSource {
             }
             
             header.delegate = self
-            header.setStatusButton(count: dataSource?.metadatas.count ?? 0)
+            header.setStatusButton(count: dataSource.metadatas.count)
             header.setTitleSorted(datasourceTitleButton: titleButton)
             header.viewRichWorkspaceHeightConstraint.constant = headerRichWorkspaceHeight
             header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
@@ -433,8 +433,8 @@ extension NCSelect: UICollectionViewDataSource {
             
             let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
             
-            let info = dataSource?.getFilesInformation()
-            footer.setTitleLabel(directories: info?.directories ?? 0, files: info?.files ?? 0, size: info?.size ?? 0)
+            let info = dataSource.getFilesInformation()
+            footer.setTitleLabel(directories: info.directories, files: info.files, size: info.size)
             
             return footer
         }
@@ -446,14 +446,14 @@ extension NCSelect: UICollectionViewDataSource {
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return dataSource?.numberOfItems() ?? 0
+        return dataSource.numberOfItems()
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
         let cell: UICollectionViewCell
         
-        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else {
+        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
             return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
         }
         

+ 4 - 4
iOSClient/Transfers/NCTransfers.swift

@@ -68,7 +68,7 @@ class NCTransfers: NCCollectionViewCommon  {
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
 
-                if let row = dataSource?.addMetadata(metadata) {
+                if let row = dataSource.addMetadata(metadata) {
                     let indexPath = IndexPath(row: row, section: 0)
                     collectionView?.performBatchUpdates({
                         collectionView?.insertItems(at: [indexPath])
@@ -87,7 +87,7 @@ class NCTransfers: NCCollectionViewCommon  {
             if let metadata = userInfo["metadata"] as? tableMetadata, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int {
                 if errorCode == 0 {
                     
-                    if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.deleteItems(at: [indexPath])
@@ -100,7 +100,7 @@ class NCTransfers: NCCollectionViewCommon  {
                     
                 } else if errorCode != NSURLErrorCancelled {
                     
-                    if let row = dataSource?.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
+                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
                         let indexPath = IndexPath(row: row, section: 0)
                         collectionView?.performBatchUpdates({
                             collectionView?.reloadItems(at: [indexPath])
@@ -121,7 +121,7 @@ class NCTransfers: NCCollectionViewCommon  {
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
                     
-                if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
+                if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
                     let indexPath = IndexPath(row: row, section: 0)
                     collectionView?.performBatchUpdates({
                         collectionView?.deleteItems(at: [indexPath])