NCViewerImageDetailView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // NCViewerImageDetailView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 31/10/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. import MapKit
  10. class NCViewerImageDetailView: UIView {
  11. @IBOutlet weak var dateLabel: UILabel!
  12. @IBOutlet weak var mapView: MKMapView!
  13. @IBOutlet weak var locationButton: UIButton!
  14. var annotation = MKPointAnnotation()
  15. var latitude: Double = 0
  16. var longitude: Double = 0
  17. var location: String = ""
  18. var date: NSDate?
  19. override func awakeFromNib() {
  20. super.awakeFromNib()
  21. mapView.layer.cornerRadius = 6
  22. mapView.isZoomEnabled = false
  23. mapView.isScrollEnabled = false
  24. mapView.isUserInteractionEnabled = false
  25. }
  26. @IBAction func touchLocation(_ sender: Any) {
  27. if self.latitude > 0 && self.longitude > 0 {
  28. openMapForPlace()
  29. }
  30. }
  31. func openMapForPlace() {
  32. let latitude: CLLocationDegrees = self.latitude
  33. let longitude: CLLocationDegrees = self.longitude
  34. let regionDistance:CLLocationDistance = 10000
  35. let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
  36. let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
  37. let options = [
  38. MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
  39. MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
  40. ]
  41. let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
  42. let mapItem = MKMapItem(placemark: placemark)
  43. mapItem.name = location
  44. mapItem.openInMaps(launchOptions: options)
  45. }
  46. func updateExifLocal(metadata: tableMetadata) {
  47. if metadata.typeFile == k_metadataTypeFile_image {
  48. //CCExifGeo.sharedInstance()?.setExif(metadata)
  49. }
  50. if let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  51. let latitudeString = localFile.exifLatitude
  52. let longitudeString = localFile.exifLongitude
  53. self.latitude = Double(localFile.exifLatitude) ?? 0
  54. self.longitude = Double(localFile.exifLongitude) ?? 0
  55. self.date = localFile.exifDate
  56. if let location = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(latitudeString, longitude: longitudeString) {
  57. self.location = location
  58. }
  59. if self.latitude > 0 && self.longitude > 0 {
  60. if let date = self.date {
  61. let formatter = DateFormatter()
  62. formatter.dateStyle = .full
  63. let dateString = formatter.string(from: date as Date)
  64. formatter.dateFormat = "HH:mm"
  65. let timeString = formatter.string(from: date as Date)
  66. self.dateLabel.text = dateString + ", " + timeString
  67. }
  68. self.annotation.coordinate = CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude)
  69. self.mapView.addAnnotation(self.annotation)
  70. self.mapView.setRegion(MKCoordinateRegion(center: self.annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
  71. self.locationButton.setTitle(self.location, for: .normal)
  72. }
  73. }
  74. }
  75. func hasData() -> Bool {
  76. if self.latitude > 0 && self.longitude > 0 {
  77. return true
  78. } else {
  79. return false
  80. }
  81. }
  82. func show(textColor: UIColor) {
  83. self.dateLabel.textColor = textColor
  84. self.isHidden = false
  85. }
  86. func hide() {
  87. self.isHidden = true
  88. }
  89. func isShow() -> Bool {
  90. return !self.isHidden
  91. }
  92. }