refactor: Migrate AlertsPastEartquakesTableViewCell to code
This commit is contained in:
@@ -107,6 +107,7 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
|
||||
[self.tableView registerClass:[AlertsSmartphoneNetworkTableViewCell class] forCellReuseIdentifier:@"SmartphoneNetworkCell"];
|
||||
[self.tableView registerClass:[AlertsPriorityServiceTableViewCell class] forCellReuseIdentifier:@"PriorityCell"];
|
||||
[self.tableView registerClass:[AlertsNoLocationTableViewCell class] forCellReuseIdentifier:@"NoLocationCell"];
|
||||
[self.tableView registerClass:[AlertsPastEartquakesTableViewCell class] forCellReuseIdentifier:@"PastEarthquakesCell"];
|
||||
|
||||
if (EQNBackgroundPositionDebugHelper.shared.isEnabled) {
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(backgroundPositionDebugTapped:)];
|
||||
@@ -315,8 +316,9 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
|
||||
|
||||
} else if (tableRow == AllerteTableRowAllertePassate) {
|
||||
AlertsPastEartquakesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PastEarthquakesCell" forIndexPath:indexPath];
|
||||
cell.smartphoneNetwork = [EQNManager defaultManager].rete_smartphone;
|
||||
cell.onTapMapButton = ^{
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
[cell updateWith:[EQNManager defaultManager].rete_smartphone];
|
||||
cell.onTapMap = ^{
|
||||
PasquakesMapViewController *controller = [[PasquakesMapViewController alloc] init];
|
||||
[self presentViewController:controller animated:YES completion:nil];
|
||||
};
|
||||
|
||||
+63
-26
@@ -8,50 +8,87 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
class AlertsPastEartquakesTableViewCell: EQNBaseTableViewCell {
|
||||
|
||||
@objc var smartphoneNetwork: EQNReteSmartphone? {
|
||||
didSet {
|
||||
updateUI()
|
||||
}
|
||||
}
|
||||
@objc
|
||||
class AlertsPastEartquakesTableViewCell: EQNBaseContainerTableViewCell {
|
||||
|
||||
@objc var onTapMapButton: (() -> Void)?
|
||||
@objc var onTapMap: (() -> Void)?
|
||||
|
||||
override var headerText: String { NSLocalizedString("main_past_quakes", comment: "") }
|
||||
|
||||
// MARK: - UI
|
||||
|
||||
private lazy var last24hLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label.numberOfLines = 0
|
||||
label.textColor = AppTheme.shared.cardTextColor
|
||||
label.font = .preferredFont(forTextStyle: .title3)
|
||||
label.textAlignment = .center
|
||||
return label
|
||||
}()
|
||||
|
||||
|
||||
private lazy var from2013Label: UILabel = {
|
||||
let label = UILabel()
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label.numberOfLines = 0
|
||||
label.textColor = AppTheme.shared.cardTextColor
|
||||
label.font = .preferredFont(forTextStyle: .title3)
|
||||
label.textAlignment = .center
|
||||
return label
|
||||
}()
|
||||
|
||||
private lazy var mapButton: UIButton = {
|
||||
let button = EQNRoundedButton.make(target: self, action: #selector(mapTapped(_:)))
|
||||
return button
|
||||
}()
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
@IBOutlet private weak var headerLabel: UILabel!
|
||||
@IBOutlet private weak var last24hLabel: UILabel!
|
||||
@IBOutlet private weak var from2013Label: UILabel!
|
||||
@IBOutlet private weak var mapButton: UIButton!
|
||||
|
||||
// MARK: - View Lifecycle
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
override func setupUI() {
|
||||
super.setupUI()
|
||||
|
||||
localizeUI()
|
||||
containerView.addSubview(last24hLabel)
|
||||
containerView.addSubview(from2013Label)
|
||||
containerView.addSubview(mapButton)
|
||||
|
||||
last24hLabel.topAnchor.constraint(equalTo: topView.bottomAnchor, constant: Self.DefaultVerticalSpacing).isActive = true
|
||||
last24hLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: Self.DefaultPadding).isActive = true
|
||||
last24hLabel.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -Self.DefaultPadding).isActive = true
|
||||
|
||||
from2013Label.topAnchor.constraint(equalTo: last24hLabel.bottomAnchor, constant: Self.DefaultVerticalSpacing).isActive = true
|
||||
from2013Label.leadingAnchor.constraint(equalTo: last24hLabel.leadingAnchor).isActive = true
|
||||
from2013Label.trailingAnchor.constraint(equalTo: last24hLabel.trailingAnchor).isActive = true
|
||||
|
||||
mapButton.heightAnchor.constraint(greaterThanOrEqualToConstant: 40.0).isActive = true
|
||||
mapButton.topAnchor.constraint(equalTo: from2013Label.bottomAnchor, constant: Self.DefaultVerticalSpacing).isActive = true
|
||||
mapButton.leadingAnchor.constraint(equalTo: from2013Label.leadingAnchor).isActive = true
|
||||
mapButton.trailingAnchor.constraint(equalTo: from2013Label.trailingAnchor).isActive = true
|
||||
mapButton.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -Self.DefaultPadding).isActive = true
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func localizeUI() {
|
||||
headerLabel.text = NSLocalizedString("main_past_quakes", comment: "")
|
||||
override func updateUI() {
|
||||
super.updateUI()
|
||||
|
||||
last24hLabel.text = NSLocalizedString("main_recent_quakes_initial", comment: "")
|
||||
from2013Label.text = NSLocalizedString("main_total_quakes_initial", comment: "")
|
||||
mapButton.setLocalizedTitle(key: "official_button_map", uppercased: true, emoji: "🗺")
|
||||
}
|
||||
|
||||
private func updateUI() {
|
||||
guard let smartphoneNetwork = smartphoneNetwork else { return }
|
||||
// MARK: - Public
|
||||
|
||||
@objc
|
||||
func update(with smartphoneNetwork: EQNReteSmartphone?) {
|
||||
guard let smartphoneNetwork else { return }
|
||||
|
||||
last24hLabel.text = String(format: NSLocalizedString("main_recent_quakes", comment: ""), smartphoneNetwork.counterLastDayAlerts)
|
||||
from2013Label.text = String(format: NSLocalizedString("main_total_quakes", comment: ""), smartphoneNetwork.counterTotalAlerts)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func mapTapped(_ sender: UIButton) {
|
||||
onTapMapButton?()
|
||||
@objc private func mapTapped(_ sender: UIButton) {
|
||||
onTapMap?()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user