64 lines
1.7 KiB
Swift
64 lines
1.7 KiB
Swift
//
|
|
// AlertsPriorityServiceTableViewCell.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 04/10/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class AlertsPriorityServiceTableViewCell: EQNBaseTableViewCell {
|
|
|
|
@objc var smartphoneNetwork: EQNReteSmartphone? {
|
|
didSet {
|
|
updateUI()
|
|
}
|
|
}
|
|
|
|
// MARK: - Internal
|
|
|
|
@IBOutlet private weak var headerLabel: UILabel!
|
|
@IBOutlet private weak var descriptionLabel: UILabel!
|
|
@IBOutlet private weak var lastSubscriptionLabel: UILabel!
|
|
|
|
// MARK: - View Lifecycle
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
|
|
localizeUI()
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func localizeUI() {
|
|
headerLabel.text = NSLocalizedString("inapp_list", comment: "")
|
|
descriptionLabel.text = NSLocalizedString("inapp_adv", comment: "")
|
|
}
|
|
|
|
private func updateUI() {
|
|
guard let smartphoneNetwork = smartphoneNetwork else { return }
|
|
|
|
lastSubscriptionLabel.text = subscriptionText(for: smartphoneNetwork.lastSubscriptionDiff)
|
|
}
|
|
|
|
private func subscriptionText(for time: Int) -> String {
|
|
var format = ""
|
|
var finalValue = time
|
|
|
|
// check for minutes, hours or days
|
|
if time < 60 {
|
|
format = NSLocalizedString("inapp_adv_minutes", comment: "")
|
|
} else if time < 1440 {
|
|
finalValue = time / 60
|
|
format = NSLocalizedString("inapp_adv_hours", comment: "")
|
|
} else {
|
|
finalValue = time / 1440
|
|
format = NSLocalizedString("inapp_adv_days", comment: "")
|
|
}
|
|
|
|
return String.localizedStringWithFormat(format, finalValue)
|
|
}
|
|
}
|