Browse Source

Merge pull request #1933 from nextcloud/ImprovedModifyQL

Update the viewer after modify
Marino Faggiana 3 years ago
parent
commit
19fca71d1f

+ 19 - 8
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -101,14 +101,7 @@ class NCViewerMedia: UIViewController {
         self.image = nil
         self.imageVideoContainer.image = nil
 
-        loadImage(metadata: metadata) { _, image in
-            self.image = image
-            // do not update if is present the videoLayer
-            let numSublayers = self.imageVideoContainer.layer.sublayers?.count
-            if numSublayers == nil {
-                self.imageVideoContainer.image = image
-            }
-        }
+        reloadImage()
     }
 
     override func viewWillAppear(_ animated: Bool) {
@@ -119,6 +112,10 @@ class NCViewerMedia: UIViewController {
 
         if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue, let viewerMediaPage = self.viewerMediaPage {
             viewerMediaPage.currentScreenMode = viewerMediaPage.saveScreenModeImage
+            if viewerMediaPage.modifiedOcId.contains(metadata.ocId) {
+                viewerMediaPage.modifiedOcId.removeAll(where: { $0 == metadata.ocId })
+                reloadImage()
+            }
         }
 
         if viewerMediaPage?.currentScreenMode == .full {
@@ -196,6 +193,20 @@ class NCViewerMedia: UIViewController {
 
     // MARK: - Image
 
+    func reloadImage() {
+        if let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) {
+            self.metadata = metadata
+            loadImage(metadata: metadata) { _, image in
+                self.image = image
+                // do not update if is present the videoLayer
+                let numSublayers = self.imageVideoContainer.layer.sublayers?.count
+                if numSublayers == nil {
+                    self.imageVideoContainer.image = image
+                }
+            }
+        }
+    }
+
     func loadImage(metadata: tableMetadata, completion: @escaping (_ ocId: String, _ image: UIImage?) -> Void) {
 
         // Download preview

+ 21 - 0
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -44,6 +44,7 @@ class NCViewerMediaPage: UIViewController {
     }
 
     var metadatas: [tableMetadata] = []
+    var modifiedOcId: [String] = []
     var currentIndex = 0
     var nextIndex: Int?
     var ncplayerLivePhoto: NCPlayer?
@@ -96,6 +97,8 @@ class NCViewerMediaPage: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
 
+        NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
+
         NotificationCenter.default.addObserver(self, selector: #selector(hidePlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(showPlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
         
@@ -129,6 +132,8 @@ class NCViewerMediaPage: UIViewController {
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
 
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
+
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
 
@@ -228,6 +233,22 @@ class NCViewerMediaPage: UIViewController {
         }
     }
 
+    @objc func uploadedFile(_ notification: NSNotification) {
+
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId), let errorCode = userInfo["errorCode"] as? Int {
+                if errorCode == 0, let index = metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) {
+                    metadatas[index] = metadata
+                    if currentViewController.metadata.ocId == ocId {
+                        currentViewController.reloadImage()
+                    } else {
+                        modifiedOcId.append(ocId)
+                    }
+                }
+            }
+        }
+    }
+
     @objc func deleteFile(_ notification: NSNotification) {
 
         if let userInfo = notification.userInfo as NSDictionary? {