marinofaggiana 4 éve
szülő
commit
89ab2b4b08

+ 2 - 2
iOSClient/Networking/NCNetworking.swift

@@ -275,7 +275,7 @@ import Queuer
                     
                     NCEndToEndEncryption.sharedManager()?.decryptFileName(metadata.fileName, fileNameView: metadata.fileNameView, ocId: metadata.ocId, key: result.key, initializationVector: result.initializationVector, authenticationTag: result.authenticationTag)
                 }
-                CCUtility.setExif(metadata)
+                CCUtility.setExif(metadata) { (latitude, longitude, location, date) in };
                 #endif
                                 
             } else {
@@ -504,7 +504,7 @@ import Queuer
                         appDelegate.networkingAutoUpload.startProcess()
                     }
                 }
-                CCUtility.setExif(metadata)
+                CCUtility.setExif(metadata) { (latitude, longitude, location, date) in };
                 #endif                
                 
                 NCCommunicationCommon.shared.writeLog("Upload complete " + serverUrl + "/" + fileName + ", result: success(\(size) bytes)")

+ 1 - 1
iOSClient/Utility/CCUtility.h

@@ -267,7 +267,7 @@
 
 // ===== EXIF =====
 
-+ (void)setExif:(tableMetadata *)metadata;
++ (void)setExif:(tableMetadata *)metadata withCompletionHandler:(void(^)(double latitude, double longitude, NSString *location, NSDate *date))completition;
 
 // ===== Third parts =====
 

+ 17 - 11
iOSClient/Utility/CCUtility.m

@@ -1684,13 +1684,14 @@
 #pragma mark ===== EXIF =====
 #pragma --------------------------------------------------------------------------------------------
 
-+ (void)setExif:(tableMetadata *)metadata
++ (void)setExif:(tableMetadata *)metadata withCompletionHandler:(void(^)(double latitude, double longitude, NSString *location, NSDate *date))completition
 {
     NSString *dateTime;
     NSString *latitudeRef;
     NSString *longitudeRef;
     NSString *stringLatitude = @"0";
     NSString *stringLongitude = @"0";
+    __block NSString *location = @"";
     
     double latitude = 0;
     double longitude = 0;
@@ -1698,18 +1699,20 @@
     NSDate *date = [NSDate new];
     
     if (![metadata.typeFile isEqualToString:k_metadataTypeFile_image] || ![CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
+        completition(latitude, longitude, location, date);
         return;
     }
     
     NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]];
-
     CGImageSourceRef originalSource =  CGImageSourceCreateWithURL((CFURLRef) url, NULL);
     if (!originalSource) {
+        completition(latitude, longitude, location, date);
         return;
     }
     
     CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(originalSource, 0, NULL);
     if (!imageProperties) {
+        completition(latitude, longitude, location,date);
         return;
     }
     
@@ -1765,14 +1768,16 @@
         if ([stringLatitude doubleValue] != 0 || [stringLongitude doubleValue] != 0) {
             
             // If exists already geocoder data in TableGPS exit
-            if ([[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:stringLatitude longitude:stringLongitude]) {
+            location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:stringLatitude longitude:stringLongitude];
+            if (location != nil) {
+                completition(latitude, longitude, location, date);
                 return;
             }
             
             CLGeocoder *geocoder = [[CLGeocoder alloc] init];
-            CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
+            CLLocation *llocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
             
-            [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
+            [geocoder reverseGeocodeLocation:llocation completionHandler:^(NSArray *placemarks, NSError *error) {
                         
                 if (error == nil && [placemarks count] > 0) {
                     
@@ -1790,7 +1795,7 @@
                     if (placemark.administrativeArea) administrativeArea = placemark.administrativeArea;
                     if (placemark.country) country = placemark.country;
                     
-                    NSString *location = [NSString stringWithFormat:@"%@ %@ %@ %@ %@", thoroughfare, postalCode, locality, administrativeArea, country];
+                    location = [NSString stringWithFormat:@"%@ %@ %@ %@ %@", thoroughfare, postalCode, locality, administrativeArea, country];
                     location = [location stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
                     
                     // GPS
@@ -1798,20 +1803,21 @@
                         
                         [[NCManageDatabase sharedInstance] addGeocoderLocation:location placemarkAdministrativeArea:placemark.administrativeArea placemarkCountry:placemark.country placemarkLocality:placemark.locality placemarkPostalCode:placemark.postalCode placemarkThoroughfare:placemark.thoroughfare latitude:stringLatitude longitude:stringLongitude];
                     }
+                    
+                    completition(latitude, longitude, location, date);
                 }
             }];
+        } else {
+            completition(latitude, longitude, location, date);
         }
+    } else {
+        completition(latitude, longitude, location, date);
     }
        
     CFRelease(originalSource);
     CFRelease(imageProperties);
 }
 
-- (void)setGeocoder:(NSString *)ocId exifDate:(NSDate *)exifDate latitude:(NSString*)latitude longitude:(NSString*)longitude
-{
-    
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Third parts =====
 #pragma --------------------------------------------------------------------------------------------

+ 35 - 23
iOSClient/Viewer/NCViewerImage/NCViewerImageDetailView.swift

@@ -18,7 +18,7 @@ class NCViewerImageDetailView: UIView {
 
     var latitude: Double = 0
     var longitude: Double = 0
-    var location: String = ""
+    var location: String?
     var date: NSDate?
     
     override func awakeFromNib() {
@@ -57,7 +57,15 @@ class NCViewerImageDetailView: UIView {
     func updateExifLocal(metadata: tableMetadata) {
                     
         if metadata.typeFile == k_metadataTypeFile_image {
-            CCUtility.setExif(tableMetadata.init(value: metadata))
+            CCUtility.setExif(metadata) { (latitude, longitude, location, date) in
+                if latitude > 0 && longitude > 0 {
+                    self.latitude = latitude
+                    self.longitude = longitude
+                    self.location = location
+                    self.date = date as NSDate?
+                    self.setMapCoordinate()
+                }
+            };
         }
     
         if let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
@@ -68,29 +76,33 @@ class NCViewerImageDetailView: UIView {
             self.longitude = Double(localFile.exifLongitude) ?? 0
             self.date = localFile.exifDate
             
-            if let location = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(latitudeString, longitude: longitudeString) {
-                self.location = location
-            }
-            
-            if self.latitude > 0 && self.longitude > 0 {
-                
-                if let date = self.date {
-                    let formatter = DateFormatter()
-                    formatter.dateStyle = .full
-                    let dateString = formatter.string(from: date as Date)
-                    formatter.dateFormat = "HH:mm"
-                    let timeString = formatter.string(from: date as Date)
-                    self.dateLabel.text = dateString + ", " + timeString
-                }
-                
-                // Maps
-                let annotation = MKPointAnnotation()
-                annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
-                mapView.addAnnotation(annotation)
-                mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
-                locationButton.setTitle(location, for: .normal)
+            if let locationDB = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(latitudeString, longitude: longitudeString) {
+                location = locationDB
             }
+           
+            self.setMapCoordinate()
+        }
+    }
+    
+    //MARK: - Map
+    
+    func setMapCoordinate() {
+        
+        let annotation = MKPointAnnotation()
+        
+        if let date = self.date {
+            let formatter = DateFormatter()
+            formatter.dateStyle = .full
+            let dateString = formatter.string(from: date as Date)
+            formatter.dateFormat = "HH:mm"
+            let timeString = formatter.string(from: date as Date)
+            self.dateLabel.text = dateString + ", " + timeString
         }
+        
+        annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
+        mapView.addAnnotation(annotation)
+        mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
+        locationButton.setTitle(location, for: .normal)
     }
     
     //MARK: - Action