Browse Source

improved code

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
b609c5bc20
1 changed files with 41 additions and 44 deletions
  1. 41 44
      iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

+ 41 - 44
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -221,15 +221,15 @@ class NCViewerMediaPage: UIViewController {
 
 
     @objc func triggerProgressTask(_ notification: NSNotification) {
     @objc func triggerProgressTask(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
+        guard let userInfo = notification.userInfo as NSDictionary?,
-            if let progressNumber = userInfo["progress"] as? NSNumber {
+              let progressNumber = userInfo["progress"] as? NSNumber
-                let progress = progressNumber.floatValue
+        else { return }
-                if progress == 1 {
+
-                    self.progressView.progress = 0
+        let progress = progressNumber.floatValue
-                } else {
+        if progress == 1 {
-                    self.progressView.progress = progress
+            self.progressView.progress = 0
-                }
+        } else {
-            }
+            self.progressView.progress = progress
         }
         }
     }
     }
 
 
@@ -238,63 +238,60 @@ class NCViewerMediaPage: UIViewController {
         guard let userInfo = notification.userInfo as NSDictionary?,
         guard let userInfo = notification.userInfo as NSDictionary?,
               let ocId = userInfo["ocId"] as? String,
               let ocId = userInfo["ocId"] as? String,
               let errorCode = userInfo["errorCode"] as? Int,
               let errorCode = userInfo["errorCode"] as? Int,
-              errorCode == 0
+              errorCode == 0,
+              let index = metadatas.firstIndex(where: {$0.ocId == ocId}),
+              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
         else {
         else {
             return
             return
         }
         }
-        
+
-        if let index = metadatas.firstIndex(where: {$0.ocId == ocId}), let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+        metadatas[index] = metadata
-            metadatas[index] = metadata
+        if currentViewController.metadata.ocId == ocId {
-            if currentViewController.metadata.ocId == ocId {
+            currentViewController.reloadImage()
-                currentViewController.reloadImage()
+        } else {
-            } else {
+            modifiedOcId.append(ocId)
-                modifiedOcId.append(ocId)
-            }
         }
         }
     }
     }
 
 
     @objc func deleteFile(_ notification: NSNotification) {
     @objc func deleteFile(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
+        guard let userInfo = notification.userInfo as NSDictionary?,
-            if let ocId = userInfo["ocId"] as? String {
+              let ocId = userInfo["ocId"] as? String
+        else { return }
 
 
-                let metadatas = self.metadatas.filter { $0.ocId != ocId }
+        let metadatas = self.metadatas.filter { $0.ocId != ocId }
-                if self.metadatas.count == metadatas.count { return }
+        if self.metadatas.count == metadatas.count { return }
-                self.metadatas = metadatas
+        self.metadatas = metadatas
 
 
-                if ocId == currentViewController.metadata.ocId {
+        if ocId == currentViewController.metadata.ocId {
-                    shiftCurrentPage()
+            shiftCurrentPage()
-                }
-            }
         }
         }
     }
     }
 
 
     @objc func renameFile(_ notification: NSNotification) {
     @objc func renameFile(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
+        guard let userInfo = notification.userInfo as NSDictionary?,
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+              let ocId = userInfo["ocId"] as? String,
+              let index = metadatas.firstIndex(where: {$0.ocId == ocId}),
+              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
+        else { return }
 
 
-                if let index = metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) {
+        metadatas[index] = metadata
-                    metadatas[index] = metadata
+        if index == currentIndex {
-                    if index == currentIndex {
+            navigationItem.title = metadata.fileNameView
-                        navigationItem.title = metadata.fileNameView
+            currentViewController.metadata = metadata
-                        currentViewController.metadata = metadata
+            self.currentViewController.metadata = metadata
-                        self.currentViewController.metadata = metadata
-                    }
-                }
-            }
         }
         }
     }
     }
 
 
     @objc func moveFile(_ notification: NSNotification) {
     @objc func moveFile(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
+        guard let userInfo = notification.userInfo as NSDictionary?,
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+              let ocId = userInfo["ocId"] as? String
+        else { return }
 
 
-                if metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) != nil {
+        if metadatas.firstIndex(where: {$0.ocId == ocId}) != nil {
-                    deleteFile(notification)
+            deleteFile(notification)
-                }
-            }
         }
         }
     }
     }