瀏覽代碼

improved code

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 年之前
父節點
當前提交
0d5aa418ef
共有 2 個文件被更改,包括 24 次插入46 次删除
  1. 23 38
      iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
  2. 1 8
      iOSClient/Networking/NCNetworking.swift

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

@@ -358,9 +358,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let account = userInfo["account"] as? String,
               let onlyLocalCache = userInfo["onlyLocalCache"] as? Bool,
               (serverUrl == serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         if fileNameView.lowercased() == NCGlobal.shared.fileNameRichWorkspace.lowercased() {
             reloadDataSourceNetwork(forced: true)
         } else if onlyLocalCache {
@@ -389,9 +388,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let ocId = userInfo["ocId"] as? String,
               let serverUrlFrom = userInfo["serverUrlFrom"] as? String,
               serverUrlFrom == self.serverUrl
-        else {
-            return
-        }
+        else { return }
+
         let (indexPath, sameSections) = dataSource.deleteMetadata(ocId: ocId)
         if let indexPath = indexPath {
             if sameSections && (indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section)) {
@@ -413,9 +411,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         guard let userInfo = notification.userInfo as NSDictionary?,
               let serverUrlTo = userInfo["serverUrlTo"] as? String,
               serverUrlTo == self.serverUrl
-        else {
-            return
-        }
+        else { return }
+
         reloadDataSource()
     }
 
@@ -435,9 +432,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId),
               metadata.serverUrl == serverUrl,
               metadata.account == appDelegate.account
-        else {
-            return
-        }
+        else { return }
 
         pushMetadata(metadata)
     }
@@ -446,10 +441,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
         guard let userInfo = notification.userInfo as NSDictionary?,
               let ocId = userInfo["ocId"] as? String
-        else {
-            reloadDataSource()
-            return
-        }
+        else { return }
+
         dataSource.reloadMetadata(ocId: ocId)
         collectionView?.reloadData()
     }
@@ -461,9 +454,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
               (serverUrl == self.serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         let (indexPath, sameSections) = dataSource.reloadMetadata(ocId: ocId)
         if let indexPath = indexPath {
             if sameSections && (indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section)) {
@@ -483,9 +475,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
               (serverUrl == self.serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         let (indexPath, sameSections) = dataSource.reloadMetadata(ocId: ocId)
         if let indexPath = indexPath {
             if sameSections && (indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section)) {
@@ -505,9 +496,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
               (serverUrl == self.serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         let (indexPath, sameSections) = dataSource.reloadMetadata(ocId: ocId)
         if let indexPath = indexPath {
             if sameSections && (indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section)) {
@@ -527,9 +517,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
               (serverUrl == self.serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return }
         dataSource.addMetadata(metadata)
         self.collectionView?.reloadData()
@@ -543,9 +532,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
               (serverUrl == self.serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return }
         if metadata.livePhoto && metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue { return }
         let (indexPath, sameSections) = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
@@ -571,9 +559,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
               (serverUrl == self.serverUrl && account == appDelegate.account)
-        else {
-            return
-        }
+        else { return }
+
         let (indexPath, sameSections) = dataSource.deleteMetadata(ocId: ocId)
         if let indexPath = indexPath {
             if sameSections && (indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section)) {
@@ -598,11 +585,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let totalBytesExpected = userInfo["totalBytesExpected"] as? Int64,
               let ocId = userInfo["ocId"] as? String,
               let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: ocId) as? (IndexPath, NCMetadataForSection?)
-        else {
-            return
-        }
-        let status = userInfo["status"] as? Int ?? NCGlobal.shared.metadataStatusNormal
+        else { return }
 
+        let status = userInfo["status"] as? Int ?? NCGlobal.shared.metadataStatusNormal
         if let cell = collectionView?.cellForItem(at: indexPath) {
             if let cell = cell as? NCCellProtocol {
                 if progressNumber.floatValue == 1 && !(cell is NCTransferCell) {

+ 1 - 8
iOSClient/Networking/NCNetworking.swift

@@ -1149,22 +1149,15 @@ import Photos
         let ocId = metadata.ocId
 
         NCCommunication.shared.setFavorite(fileName: fileName, favorite: favorite) { account, errorCode, errorDescription in
-
             if errorCode == 0 && metadata.account == account {
-
                 NCManageDatabase.shared.setMetadataFavorite(ocId: metadata.ocId, favorite: favorite)
-
                 #if !EXTENSION
                 if favorite {
                     NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorReadFile)
                 }
                 #endif
-
-                if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": metadata.ocId])
-                }
+                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": ocId])
             }
-
             completion(errorCode, errorDescription)
         }
     }