marinofaggiana 4 lat temu
rodzic
commit
201d062462

+ 35 - 38
iOSClient/Activity/NCActivity.swift

@@ -440,15 +440,31 @@ extension activityTableViewCell: UICollectionViewDataSource {
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
-        if let cell: activityCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as? activityCollectionViewCell {
+        let cell: activityCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as! activityCollectionViewCell
             
-            cell.imageView.image = nil
+        cell.imageView.image = nil
+        
+        let activityPreview = activityPreviews[indexPath.row]
+        let fileId = String(activityPreview.fileId)
+        
+        // Trashbin
+        if activityPreview.view == "trashbin" {
+            
+            let source = activityPreview.source
+            
+            NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false, account: appDelegate.account) { (imageNamePath) in
+                if imageNamePath != nil {
+                    if let image = UIImage(contentsOfFile: imageNamePath!) {
+                        cell.imageView.image = image
+                    }
+                } else {
+                     cell.imageView.image = UIImage.init(named: "file")
+                }
+            }
             
-            let activityPreview = activityPreviews[indexPath.row]
-            let fileId = String(activityPreview.fileId)
+        } else {
             
-            // Trashbin
-            if activityPreview.view == "trashbin" {
+            if activityPreview.isMimeTypeIcon {
                 
                 let source = activityPreview.source
                 
@@ -458,54 +474,35 @@ extension activityTableViewCell: UICollectionViewDataSource {
                             cell.imageView.image = image
                         }
                     } else {
-                         cell.imageView.image = UIImage.init(named: "file")
+                        cell.imageView.image = UIImage.init(named: "file")
                     }
                 }
                 
             } else {
                 
-                if activityPreview.isMimeTypeIcon {
+                if let activitySubjectRich = NCManageDatabase.sharedInstance.getActivitySubjectRich(account: account, idActivity: idActivity, id: fileId) {
                     
-                    let source = activityPreview.source
+                    let fileNamePath = CCUtility.getDirectoryUserData() + "/" + activitySubjectRich.name
                     
-                    NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false, account: appDelegate.account) { (imageNamePath) in
-                        if imageNamePath != nil {
-                            if let image = UIImage(contentsOfFile: imageNamePath!) {
-                                cell.imageView.image = image
-                            }
-                        } else {
-                            cell.imageView.image = UIImage.init(named: "file")
+                    if FileManager.default.fileExists(atPath: fileNamePath) {
+                        
+                        if let image = UIImage(contentsOfFile: fileNamePath) {
+                            cell.imageView.image = image
                         }
-                    }
-                    
-                } else {
-                    
-                    if let activitySubjectRich = NCManageDatabase.sharedInstance.getActivitySubjectRich(account: account, idActivity: idActivity, id: fileId) {
                         
-                        let fileNamePath = CCUtility.getDirectoryUserData() + "/" + activitySubjectRich.name
+                    } else {
                         
-                        if FileManager.default.fileExists(atPath: fileNamePath) {
-                            
-                            if let image = UIImage(contentsOfFile: fileNamePath) {
-                                cell.imageView.image = image
-                            }
-                            
-                        } else {
-                            
-                            NCCommunication.shared.downloadPreview(fileNamePathOrFileId: activityPreview.source, fileNamePreviewLocalPath: fileNamePath, widthPreview: 0, heightPreview: 0, useInternalEndpoint: false) { (account, imagePreview, imageIcon, errorCode, errorDescription) in
-                                if errorCode == 0 && imagePreview != nil {
-                                    cell.imageView.image = imagePreview
-                                }
+                        NCCommunication.shared.downloadPreview(fileNamePathOrFileId: activityPreview.source, fileNamePreviewLocalPath: fileNamePath, widthPreview: 0, heightPreview: 0, useInternalEndpoint: false) { (account, imagePreview, imageIcon, errorCode, errorDescription) in
+                            if errorCode == 0 && imagePreview != nil {
+                                cell.imageView.image = imagePreview
                             }
                         }
                     }
                 }
             }
-            
-            return cell
         }
-        
-        return UICollectionViewCell()
+            
+        return cell
     }
     
 }

+ 18 - 9
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -407,10 +407,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String , let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
                 if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                     let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.reloadItems(at: [indexPath])
+                    if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                        collectionView?.reloadItems(at: [indexPath])
+                    }
                 }
             }
         }
@@ -448,13 +450,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    
                     if let row = dataSource.addMetadata(metadata) {
                         let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.insertItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
+                        if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                            collectionView?.performBatchUpdates({
+                                collectionView?.insertItems(at: [indexPath])
+                            }, completion: { (_) in
+                                self.collectionView?.reloadData()
+                            })
+                        }
                     }
                 }
             }
@@ -1305,7 +1310,11 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                 
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
-            return UICollectionViewCell()
+            if layout == k_layout_list {
+                return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
+            } else {
+                return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
+            }
         }
         
         var tableShare: tableShare?
@@ -1619,7 +1628,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             return cell
         }
         
-        return UICollectionViewCell()
+        return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
     }
 }
 

+ 7 - 6
iOSClient/Media/NCMedia.swift

@@ -567,10 +567,9 @@ extension NCMedia: UICollectionViewDataSource {
 
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
-        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridMediaCell
-
-        if indexPath.section <  collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+        if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
         
+            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridMediaCell
             let metadata = metadatas[indexPath.row]
             
             self.cellHeigth = cell.frame.size.height
@@ -604,11 +603,13 @@ extension NCMedia: UICollectionViewDataSource {
             } else {
                 cell.selectMode(false)
             }
+            
+            return cell
+            
         } else {
-            print("error")
+            
+            return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridMediaCell
         }
-        
-        return cell
     }
 }
 

+ 6 - 2
iOSClient/Select/NCSelect.swift

@@ -450,7 +450,11 @@ extension NCSelect: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
-            return UICollectionViewCell()
+            if layout == k_layout_list {
+                return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
+            } else {
+                return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
+            }
         }
         
         var tableShare: tableShare?
@@ -692,7 +696,7 @@ extension NCSelect: UICollectionViewDataSource {
             return cell
         }
         
-        return UICollectionViewCell()
+        return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
     }
 }
 

+ 1 - 1
iOSClient/Transfers/NCTransfers.swift

@@ -227,7 +227,7 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
     override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
-            return UICollectionViewCell()
+            return collectionView.dequeueReusableCell(withReuseIdentifier: "transferCell", for: indexPath) as! NCTransferCell
         }
                 
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "transferCell", for: indexPath) as! NCTransferCell