marinofaggiana 4 rokov pred
rodič
commit
ef3a2268d8

+ 5 - 5
Nextcloud.xcodeproj/project.pbxproj

@@ -813,6 +813,11 @@
 			isa = PBXGroup;
 			children = (
 				F710D1FA24057E5E00A6033D /* ActionSheetHeaderView */,
+				F78ACD3E21903BA20088454D /* Cell */,
+				F7DFB7E9219C5A0500680748 /* Create cloud */,
+				F78ACD4D219043E70088454D /* Layout */,
+				371B5A2F23D0B04B00FAFAE9 /* Menu */,
+				F78ACD50219046AC0088454D /* Section */,
 				F70211FA1BAC56E9003FC03E /* CCMain.h */,
 				F70211FB1BAC56E9003FC03E /* CCMain.m */,
 				F73F537E1E929C8500F8678D /* CCMore.swift */,
@@ -820,11 +825,7 @@
 				F78F6FAE1CC8CCB700F4EA25 /* CCSection.h */,
 				F78F6FAF1CC8CCB700F4EA25 /* CCSection.m */,
 				F7C1EEA425053A9C00866ACC /* NCDataSource.swift */,
-				F78ACD3E21903BA20088454D /* Cell */,
-				F7DFB7E9219C5A0500680748 /* Create cloud */,
-				F78ACD4D219043E70088454D /* Layout */,
 				F7226EDB1EE4089300EBECB1 /* Main.storyboard */,
-				371B5A2F23D0B04B00FAFAE9 /* Menu */,
 				F710D1F624057C9400A6033D /* NCDetailNavigationController.swift */,
 				37C83A0C24532B7200618A3B /* AppDelegate+Swift.swift */,
 				37C83A0E24532BA600618A3B /* CCMain+Swift.swift */,
@@ -835,7 +836,6 @@
 				F7E09CE623E308AD00FB3E9E /* NCMasterNavigationController.swift */,
 				F77444F7222816D5000D5EB0 /* NCPhotosPickerViewController.swift */,
 				F7E09CE423E3088A00FB3E9E /* NCSplitViewController.swift */,
-				F78ACD50219046AC0088454D /* Section */,
 			);
 			path = Main;
 			sourceTree = "<group>";

+ 8 - 36
iOSClient/Favorites/NCFavorite.swift

@@ -148,14 +148,7 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata, let onlyLocal = userInfo["onlyLocal"] as? Bool, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
-                if errorCode == 0 {
-                    if !onlyLocal {
-                        self.dataSource?.deleteMetadata(ocId: metadata.ocId)
-                    }
-                    collectionView.reloadData()
-                } else {
-                    NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                }
+                NCCollectionCommon.shared.notificationDeleteFile(collectionView: collectionView, dataSource: dataSource, metadata: metadata, errorCode: errorCode, errorDescription: errorDescription, onlyLocal: onlyLocal)
             }
         }
     }
@@ -165,8 +158,7 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata, let _ = userInfo["errorCode"] as? Int {
-                    self.dataSource?.reloadMetadata(ocId: metadata.ocId)
-                    collectionView.reloadData()
+                NCCollectionCommon.shared.notificationDownloadedFile(collectionView: collectionView, dataSource: dataSource, metadata: metadata)
             }
         }
     }
@@ -175,11 +167,8 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
-                if errorCode == 0 {
-                    self.dataSource?.reloadMetadata(ocId: metadata.ocId)
-                    collectionView.reloadData()
-                }
+            if let metadata = userInfo["metadata"] as? tableMetadata, let _ = userInfo["errorCode"] as? Int {
+                NCCollectionCommon.shared.notificationUploadedFile(collectionView: collectionView, dataSource: dataSource, metadata: metadata)
             }
         }
     }
@@ -189,10 +178,7 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
-                if metadata.serverUrl == self.serverUrl && metadata.account == appDelegate.account {
-                    self.dataSource?.addMetadata(metadata)
-                    collectionView.reloadData()
-                }
+                NCCollectionCommon.shared.notificationUploadFileStart(collectionView: collectionView, dataSource: dataSource, metadata: metadata, serverUrl: serverUrl, account: appDelegate.account)
             }
         }
     }
@@ -202,23 +188,9 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String {
-                if let index = dataSource?.getIndexMetadata(ocId: ocId) {
-                    if let cell = collectionView?.cellForItem(at: IndexPath(row: index, section: 0)) {
-                        let progressNumber = userInfo["progress"] as? NSNumber ?? 0
-                        let progress = progressNumber.floatValue
-                        if layout == k_layout_grid {
-                            if progress > 0 {
-                                (cell as! NCGridCell).progressView.isHidden = false
-                                (cell as! NCGridCell).progressView.progress = progress
-                            }
-                        } else {
-                            if progress > 0 {
-                                (cell as! NCListCell).progressView.isHidden = false
-                                (cell as! NCListCell).progressView.progress = progress
-                            }
-                        }
-                    }
-                }
+                let progressNumber = userInfo["progress"] as? NSNumber ?? 0
+                let progress = progressNumber.floatValue
+                NCCollectionCommon.shared.notificationTriggerProgressTask(collectionView: collectionView, dataSource: dataSource, ocId: ocId, progress: progress)
             }
         }
     }

+ 50 - 0
iOSClient/Main/NCCollectionCommon.swift

@@ -336,4 +336,54 @@ class NCCollectionCommon: NSObject {
             }
         }
     }
+    
+    // MARK -
+    
+    func notificationDeleteFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata, errorCode: Int, errorDescription: String ,onlyLocal: Bool) {
+        if errorCode == 0 {
+            if !onlyLocal {
+                dataSource?.deleteMetadata(ocId: metadata.ocId)
+            }
+            collectionView?.reloadData()
+        } else {
+            NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+        }
+    }
+    
+    func notificationDownloadedFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata) {
+        dataSource?.reloadMetadata(ocId: metadata.ocId)
+        collectionView?.reloadData()
+    }
+    
+    func notificationUploadedFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata) {
+        dataSource?.reloadMetadata(ocId: metadata.ocId)
+        collectionView?.reloadData()
+    }
+    
+    func notificationUploadFileStart(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata, serverUrl: String, account: String) {
+        if metadata.serverUrl == serverUrl && metadata.account == account {
+            dataSource?.addMetadata(metadata)
+            collectionView?.reloadData()
+        }
+    }
+    
+    func notificationTriggerProgressTask(collectionView: UICollectionView?, dataSource: NCDataSource?, ocId: String, progress: Float) {
+        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
+                    if progress > 0 {
+                        cell.progressView?.isHidden = false
+                        cell.progressView?.progress = progress
+                    }
+                } else if cell is NCGridCell {
+                    let cell = cell as! NCGridCell
+                    if progress > 0 {
+                        cell.progressView.isHidden = false
+                        cell.progressView.progress = progress
+                    }
+                }
+            }
+        }
+    }
 }