Browse Source

Optimized memory

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 years ago
parent
commit
0704d0e711

+ 0 - 1
iOSClient/Media/NCMedia.swift

@@ -80,7 +80,6 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         collectionView.alwaysBounceVertical = true
         collectionView.contentInset = UIEdgeInsets(top: insetsTop, left: 0, bottom: 50, right: 0);
         collectionView.backgroundColor = NCBrandColor.shared.systemBackground
-        collectionView.bounces = false
                 
         gridLayout = NCGridMediaLayout()
         gridLayout.itemForLine = CGFloat(min(CCUtility.getMediaWidthImage(), 5))

+ 7 - 10
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -86,7 +86,7 @@ class NCPlayer: NSObject {
                     
                     self.activateObserver(playerToolBar: playerToolBar)
                     
-                    if let imageVideoContainer = self.imageVideoContainer {
+                    if let imageVideoContainer = imageVideoContainer {
                         
                         self.imageVideoContainer = imageVideoContainer
                         self.videoLayer = AVPlayerLayer(player: self.player)
@@ -148,14 +148,6 @@ class NCPlayer: NSObject {
 
     deinit {
         print("deinit NCPlayer")
-        
-        deactivateObserver()
-        
-        self.videoLayer?.removeFromSuperlayer()
-        self.videoLayer = nil
-        self.imageVideoContainer = nil
-        self.playerToolBar = nil
-        self.metadata = nil
     }
     
     func activateObserver(playerToolBar: NCPlayerToolBar?) {
@@ -186,7 +178,7 @@ class NCPlayer: NSObject {
         NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
     }
     
-    func deactivateObserver() {
+    func deactivateObserver(livePhoto: Bool) {
         
         if isPlay() {
             playerPause()
@@ -195,6 +187,11 @@ class NCPlayer: NSObject {
         self.playerToolBar?.disableCommandCenter()
         self.playerToolBar = nil
         
+        if livePhoto {
+            self.videoLayer?.removeFromSuperlayer()
+            self.videoLayer = nil
+        }
+        
         if let observerAVPlayerItemDidPlayToEndTime = self.observerAVPlayerItemDidPlayToEndTime {
             NotificationCenter.default.removeObserver(observerAVPlayerItemDidPlayToEndTime)
         }

+ 2 - 2
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -490,7 +490,7 @@ extension NCViewerMedia: UIPageViewControllerDelegate, UIPageViewControllerDataS
         if (completed && nextIndex != nil) {
             previousViewControllers.forEach { viewController in
                 let viewerMediaZoom = viewController as! NCViewerMediaZoom
-                viewerMediaZoom.ncplayer?.deactivateObserver()
+                viewerMediaZoom.ncplayer?.deactivateObserver(livePhoto: false)
                 viewerMediaZoom.scrollView.zoomScale = viewerMediaZoom.scrollView.minimumZoomScale
             }
             currentIndex = nextIndex!
@@ -620,7 +620,7 @@ extension NCViewerMedia: UIGestureRecognizerDelegate {
             
             currentViewController.statusViewImage.isHidden = false
             currentViewController.statusLabel.isHidden = false
-//            self.ncplayerLivePhoto?.clearResource()
+            self.ncplayerLivePhoto?.deactivateObserver(livePhoto: true)
         }
     }
 }