NCViewerImageDetailView.swift 4.1 KB

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