Files
eqn.ios/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsPositionDataTableViewCell.swift
T
2020-10-08 22:18:51 +02:00

53 lines
1.5 KiB
Swift

//
// AlertsPositionDataTableViewCell.swift
// Earthquake Network
//
// Created by Busi Andrea on 08/10/2020.
// Copyright © 2020 Earthquake Network. All rights reserved.
//
import UIKit
import Solar
class AlertsPositionDataTableViewCell: EQNBaseTableViewCell {
@objc var position: CLLocation? {
didSet {
updateUI()
}
}
// MARK: - Internal
@IBOutlet private weak var positionLabel: UILabel!
@IBOutlet private weak var sunriseTimeLabel: UILabel!
@IBOutlet private weak var sunsetTimeLabel: UILabel!
private lazy var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .short
return formatter
}()
// MARK: - Private
private func updateUI() {
positionLabel.text = "Non disponibile"
sunriseTimeLabel.text = "Non disponibile"
sunsetTimeLabel.text = "Non disponibile"
guard let position = position else { return }
positionLabel.text = EQNUtility.coordinateString(coordinate: position.coordinate)
if let solar = Solar(coordinate: position.coordinate) {
if let sunrise = solar.sunrise {
sunriseTimeLabel.text = dateFormatter.string(from: sunrise) + " (\(TimeZone.current.identifier))"
}
if let sunset = solar.sunset {
sunsetTimeLabel.text = dateFormatter.string(from: sunset) + " (\(TimeZone.current.identifier))"
}
}
}
}