marinofaggiana 3 gadi atpakaļ
vecāks
revīzija
22b5466c89

+ 89 - 106
iOSClient/Viewer/NCViewerMedia/NCViewerMediaDetailView.swift

@@ -43,6 +43,10 @@ class NCViewerMediaDetailView: UIView {
     var latitude: Double = 0
     var longitude: Double = 0
     var location: String?
+    var date: Date?
+    var lensModel: String?
+    
+    var mapView: MKMapView?
         
     override func awakeFromNib() {
         super.awakeFromNib()
@@ -63,115 +67,109 @@ class NCViewerMediaDetailView: UIView {
     
     deinit {
         print("deinit NCViewerMediaDetailView")
+        
+        self.mapView?.removeFromSuperview()
+        self.mapView = nil
     }
     
-    func show(metadata: tableMetadata, image: UIImage?, textColor: UIColor?, completion: @escaping (_ showMap: Bool)->()) {
+    func show(metadata: tableMetadata, image: UIImage?, textColor: UIColor?, latitude: Double, longitude: Double, location: String?, date: Date?, lensModel: String?) {
                         
-        func updateContent(date: Date?, lensModel: String?, location: String?, showMap: Bool) {
+        self.latitude = latitude
+        self.longitude = longitude
+        self.location = location
+        self.date = date
+        self.lensModel = lensModel
+        
+        if (latitude != -1 && latitude != 0 && longitude != -1 && longitude != 0) {
             
-            // Size
-            sizeLabel.text = NSLocalizedString("_size_", comment: "")
-            sizeValue.text = CCUtility.transformedSize(metadata.size)
-            sizeValue.textColor = textColor
+            let annotation = MKPointAnnotation()
+            annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
             
-            // Date
-            if let date = date {
-                let formatter = DateFormatter()
-                formatter.dateStyle = .full
-                formatter.timeStyle = .medium
-                let dateString = formatter.string(from: date as Date)
+            self.mapView?.removeFromSuperview()
+            self.mapView = nil
+            self.mapView = MKMapView.init()
+            if let mapView = self.mapView {
+                mapView.translatesAutoresizingMaskIntoConstraints = false
+                self.mapContainer.addSubview(mapView)
                 
-                dateLabel.text = NSLocalizedString("_date_", comment: "")
-                dateValue.text = dateString
-            } else {
-                dateLabel.text = NSLocalizedString("_date_", comment: "")
-                dateValue.text = NSLocalizedString("_not_available_", comment: "")
+                NSLayoutConstraint.activate([
+                    mapView.topAnchor.constraint(equalTo: self.mapContainer.topAnchor),
+                    mapView.bottomAnchor.constraint(equalTo: self.mapContainer.bottomAnchor),
+                    mapView.leadingAnchor.constraint(equalTo: self.mapContainer.leadingAnchor),
+                    mapView.trailingAnchor.constraint(equalTo: self.mapContainer.trailingAnchor),
+                ])
+                
+                mapView.layer.cornerRadius = 6
+                mapView.isZoomEnabled = false
+                mapView.isScrollEnabled = false
+                mapView.isUserInteractionEnabled = false
+                mapView.addAnnotation(annotation)
+                mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
             }
-            dateValue.textColor = textColor
-
+        }
+        
+        // Size
+        sizeLabel.text = NSLocalizedString("_size_", comment: "")
+        sizeValue.text = CCUtility.transformedSize(metadata.size)
+        sizeValue.textColor = textColor
+        
+        // Date
+        if let date = date {
+            let formatter = DateFormatter()
+            formatter.dateStyle = .full
+            formatter.timeStyle = .medium
+            let dateString = formatter.string(from: date as Date)
             
-            // Dimension / Duration
-            if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
-                if let image = image {
-                    dimLabel.text = NSLocalizedString("_resolution_", comment: "")
-                    dimValue.text = "\(Int(image.size.width)) x \(Int(image.size.height))"
-                }
-            } else if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue  {
-                if let durationTime = NCManageDatabase.shared.getVideoDurationTime(metadata: metadata) {
-                    self.dimLabel.text = NSLocalizedString("_duration_", comment: "")
-                    self.dimValue.text = NCUtility.shared.stringFromTime(durationTime)
-                }
-            }
-            dimValue.textColor = textColor
+            dateLabel.text = NSLocalizedString("_date_", comment: "")
+            dateValue.text = dateString
+        } else {
+            dateLabel.text = NSLocalizedString("_date_", comment: "")
+            dateValue.text = NSLocalizedString("_not_available_", comment: "")
+        }
+        dateValue.textColor = textColor
 
-            // Model
-            if let lensModel = lensModel {
-                lensModelLabel.text = NSLocalizedString("_model_", comment: "")
-                lensModelValue.text = lensModel
-                lensModelValue.textColor = textColor
-            }
-            
-            // Message
-            if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && metadata.session == "" {
-                messageLabel.text = NSLocalizedString("_try_download_full_resolution_", comment: "")
-            } else {
-                messageLabel.text = ""
+        
+        // Dimension / Duration
+        if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
+            if let image = image {
+                dimLabel.text = NSLocalizedString("_resolution_", comment: "")
+                dimValue.text = "\(Int(image.size.width)) x \(Int(image.size.height))"
             }
-            
-            // Location
-            if let location = location {
-                self.locationButton.setTitle(location, for: .normal)
+        } else if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue  {
+            if let durationTime = NCManageDatabase.shared.getVideoDurationTime(metadata: metadata) {
+                self.dimLabel.text = NSLocalizedString("_duration_", comment: "")
+                self.dimValue.text = NCUtility.shared.stringFromTime(durationTime)
             }
-            
-            completion(showMap)
         }
-        
-        if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
-            CCUtility.setExif(metadata) { (latitude, longitude, location, date, lensModel) in
-            
-                self.latitude = latitude
-                self.longitude = longitude
-                self.location = location
-                
-                if latitude != -1 && latitude != 0 && longitude != -1 && longitude != 0 {
-                                        
-                    let annotation = MKPointAnnotation()
-                    annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
-                    
-                    let mapView = MKMapView.init()
-                    mapView.translatesAutoresizingMaskIntoConstraints = false
-                    self.mapContainer.addSubview(mapView)
-                    
-                    NSLayoutConstraint.activate([
-                        mapView.topAnchor.constraint(equalTo: self.mapContainer.topAnchor),
-                        mapView.bottomAnchor.constraint(equalTo: self.mapContainer.bottomAnchor),
-                        mapView.leadingAnchor.constraint(equalTo: self.mapContainer.leadingAnchor),
-                        mapView.trailingAnchor.constraint(equalTo: self.mapContainer.trailingAnchor),
-                    ])
-                    
-                    mapView.layer.cornerRadius = 6
-                    mapView.isZoomEnabled = false
-                    mapView.isScrollEnabled = false
-                    mapView.isUserInteractionEnabled = false
-                    mapView.addAnnotation(annotation)
-                    mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
+        dimValue.textColor = textColor
 
-                    updateContent(date: date, lensModel: lensModel, location: location, showMap: true)
-                    
-                } else {
-                    
-                    updateContent(date: date, lensModel: lensModel, location: location, showMap: false)
-                }
-                
-                self.isHidden = false
-            };
+        // Model
+        if let lensModel = lensModel {
+            lensModelLabel.text = NSLocalizedString("_model_", comment: "")
+            lensModelValue.text = lensModel
+            lensModelValue.textColor = textColor
+        }
+        
+        // Message
+        if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && metadata.session == "" {
+            messageLabel.text = NSLocalizedString("_try_download_full_resolution_", comment: "")
         } else {
-            updateContent(date: nil, lensModel: nil, location: nil, showMap: false)
-            self.isHidden = false
+            messageLabel.text = ""
+        }
+        
+        // Location
+        if let location = location {
+            self.locationButton.setTitle(location, for: .normal)
         }
+        
+        self.isHidden = false
     }
     
     func hide() {
+        
+        self.mapView?.removeFromSuperview()
+        self.mapView = nil
+        
         self.isHidden = true
     }
     
@@ -179,21 +177,6 @@ class NCViewerMediaDetailView: UIView {
         return !self.isHidden
     }
     
-    func isMapAvailable(metadata: tableMetadata, completion: @escaping (_ available: Bool)->()) {
-        
-        if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
-            CCUtility.setExif(metadata) { (latitude, longitude, location, date, lensModel) in
-                if latitude != -1 && latitude != 0 && longitude != -1 && longitude != 0 {
-                    completion(true)
-                } else {
-                    completion(false)
-                }
-            }
-        } else {
-            completion(false)
-        }
-    }
-        
     //MARK: - Action
 
     @IBAction func touchLocation(_ sender: Any) {

+ 24 - 23
iOSClient/Viewer/NCViewerMedia/NCViewerMediaZoom.swift

@@ -163,10 +163,7 @@ class NCViewerMediaZoom: UIViewController {
             self.scrollView.zoom(to: CGRect(x: 0, y: 0, width: self.scrollView.bounds.width, height: self.scrollView.bounds.height), animated: false)
             self.view.layoutIfNeeded()
             UIView.animate(withDuration: context.transitionDuration) {
-                // resize detail
-                if self.detailView.isShow() {
-                    self.openDetail()
-                }
+                self.closeDetail()
             }
         }) { (_) in }
     }
@@ -210,26 +207,23 @@ class NCViewerMediaZoom: UIViewController {
     @objc func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
                 
         let currentLocation = gestureRecognizer.translation(in: self.view)
-        let velocity = gestureRecognizer.velocity(in: self.view)
+//        let velocity = gestureRecognizer.velocity(in: self.view)
         
         switch gestureRecognizer.state {
         
         case .began:
             
-            // gesture moving Up
-            if velocity.y < 0 {
-                var heightDetailView = (view.bounds.height / 2)
-                if view.bounds.width > view.bounds.height {
-                    heightDetailView = (view.bounds.width / 2)
-                }
-                detailView.isMapAvailable(metadata: metadata, completion: { available in
-                    if available {
-                        self.detailViewHeighConstraint.constant = heightDetailView
-                    } else {
-                        self.detailViewHeighConstraint.constant = 0
-                    }
-                })
-            }
+//            gesture moving Up
+//            if velocity.y < 0 {
+//                detailView.isMapAvailable(metadata: metadata, completion: { available in
+//                    if available {
+//                        self.detailViewHeighConstraint.constant = self.view.frame.height / 2
+//                    } else {
+//                        self.detailViewHeighConstraint.constant = 0
+//                    }
+//                })
+//            }
+            break
 
         case .ended:
             
@@ -279,8 +273,16 @@ extension NCViewerMediaZoom {
     
     private func openDetail() {
         
-        self.detailView.show(metadata: metadata, image: image, textColor: self.viewerMedia?.textColor) { showMap in
+        CCUtility.setExif(metadata) { (latitude, longitude, location, date, lensModel) in
+            
+            if (latitude != -1 && latitude != 0 && longitude != -1 && longitude != 0) {
+                self.detailViewHeighConstraint.constant = self.view.frame.height / 2
+            } else {
+                self.detailViewHeighConstraint.constant = 0
+            }
             
+            self.detailView.show(metadata:self.metadata, image: self.image, textColor: self.viewerMedia?.textColor, latitude: latitude, longitude: longitude, location: location, date: date, lensModel: lensModel)
+                
             if let image = self.imageVideoContainer.image {
                 let ratioW = self.imageVideoContainer.frame.width / image.size.width
                 let ratioH = self.imageVideoContainer.frame.height / image.size.height
@@ -289,7 +291,7 @@ extension NCViewerMediaZoom {
                 self.imageViewConstraint = self.detailView.frame.height - ((self.view.frame.height - imageHeight) / 2) + self.view.safeAreaInsets.bottom
                 if self.imageViewConstraint < 0 { self.imageViewConstraint = 0 }
             }
-            
+                
             UIView.animate(withDuration: 0.3) {
                 self.imageViewTopConstraint.constant = -self.imageViewConstraint
                 self.imageViewBottomConstraint.constant = self.imageViewConstraint
@@ -297,9 +299,8 @@ extension NCViewerMediaZoom {
                 self.view.layoutIfNeeded()
             } completion: { (_) in
             }
-            
+                
             self.scrollView.pinchGestureRecognizer?.isEnabled = false
-            
             self.playerToolBar.hideToolBar()
         }
     }