marinofaggiana 3 vuotta sitten
vanhempi
commit
52bd24b671

+ 37 - 7
iOSClient/Viewer/NCViewerMedia/NCViewerMediaDetailView.swift

@@ -65,9 +65,9 @@ class NCViewerMediaDetailView: UIView {
         print("deinit NCViewerMediaDetailView")
     }
     
-    func show(metadata: tableMetadata, image: UIImage?, textColor: UIColor?, detailView: UIView) {
+    func show(metadata: tableMetadata, image: UIImage?, textColor: UIColor?, completion: @escaping (_ showMap: Bool)->()) {
                         
-        func updateContent(date: Date?, lensModel: String?, location: String?) {
+        func updateContent(date: Date?, lensModel: String?, location: String?, showMap: Bool) {
             
             // Size
             sizeLabel.text = NSLocalizedString("_size_", comment: "")
@@ -122,6 +122,8 @@ class NCViewerMediaDetailView: UIView {
             if let location = location {
                 self.locationButton.setTitle(location, for: .normal)
             }
+            
+            completion(showMap)
         }
         
         if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
@@ -136,22 +138,35 @@ class NCViewerMediaDetailView: UIView {
                     let annotation = MKPointAnnotation()
                     annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
                     
-                    let mapView = MKMapView.init(frame: self.frame)
-                    mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+                    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)
-                    self.addSubview(mapView)
+
+                    updateContent(date: date, lensModel: lensModel, location: location, showMap: true)
+                    
+                } else {
+                    
+                    updateContent(date: date, lensModel: lensModel, location: location, showMap: false)
                 }
                 
-                updateContent(date: date, lensModel: lensModel, location: location)
                 self.isHidden = false
             };
         } else {
-            updateContent(date: nil, lensModel: nil, location: nil)
+            updateContent(date: nil, lensModel: nil, location: nil, showMap: false)
             self.isHidden = false
         }
     }
@@ -163,6 +178,21 @@ class NCViewerMediaDetailView: UIView {
     func isShow() -> Bool {
         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
 

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

@@ -219,11 +219,16 @@ class NCViewerMediaZoom: UIViewController {
             // gesture moving Up
             if velocity.y < 0 {
                 var heightDetailView = (view.bounds.height / 2)
-                if view.bounds.width < view.bounds.height {
+                if view.bounds.width > view.bounds.height {
                     heightDetailView = (view.bounds.width / 2)
                 }
-                detailViewHeighConstraint.constant = heightDetailView
-                //detailView.update(metadata: metadata, image: image)
+                detailView.isMapAvailable(metadata: metadata, completion: { available in
+                    if available {
+                        self.detailViewHeighConstraint.constant = heightDetailView
+                    } else {
+                        self.detailViewHeighConstraint.constant = 0
+                    }
+                })
             }
 
         case .ended:
@@ -274,28 +279,29 @@ extension NCViewerMediaZoom {
     
     private func openDetail() {
         
-        self.detailView.show(metadata: metadata, image: image, textColor: self.viewerMedia?.textColor, detailView: self.detailView)
-        
-        if let image = imageVideoContainer.image {
-            let ratioW = imageVideoContainer.frame.width / image.size.width
-            let ratioH = imageVideoContainer.frame.height / image.size.height
-            let ratio = ratioW < ratioH ? ratioW : ratioH
-            let imageHeight = image.size.height * ratio
-            imageViewConstraint = self.detailView.frame.height - ((self.view.frame.height - imageHeight) / 2) + self.view.safeAreaInsets.bottom
-            if imageViewConstraint < 0 { imageViewConstraint = 0 }
-        }
-        
-        UIView.animate(withDuration: 0.3) {
-            self.imageViewTopConstraint.constant = -self.imageViewConstraint
-            self.imageViewBottomConstraint.constant = self.imageViewConstraint
-            self.detailViewTopConstraint.constant = self.detailView.frame.height
-            self.view.layoutIfNeeded()
-        } completion: { (_) in
+        self.detailView.show(metadata: metadata, image: image, textColor: self.viewerMedia?.textColor) { showMap in
+            
+            if let image = self.imageVideoContainer.image {
+                let ratioW = self.imageVideoContainer.frame.width / image.size.width
+                let ratioH = self.imageVideoContainer.frame.height / image.size.height
+                let ratio = ratioW < ratioH ? ratioW : ratioH
+                let imageHeight = image.size.height * ratio
+                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
+                self.detailViewTopConstraint.constant = self.detailView.frame.height
+                self.view.layoutIfNeeded()
+            } completion: { (_) in
+            }
+            
+            self.scrollView.pinchGestureRecognizer?.isEnabled = false
+            
+            self.playerToolBar.hideToolBar()
         }
-        
-        scrollView.pinchGestureRecognizer?.isEnabled = false
-        
-        playerToolBar.hideToolBar()
     }
     
     private func closeDetail() {