refactor: Migrate AlertsPriorityServiceTableViewCell to code

This commit is contained in:
Andrea Busi
2024-06-14 13:11:47 +02:00
parent 52142486cf
commit 975f5ed5bc
5 changed files with 64 additions and 112 deletions
@@ -105,6 +105,7 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
self.tableView.estimatedRowHeight = 200.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
[self.tableView registerClass:[AlertsSmartphoneNetworkTableViewCell class] forCellReuseIdentifier:@"SmartphoneNetworkCell"];
[self.tableView registerClass:[AlertsPriorityServiceTableViewCell class] forCellReuseIdentifier:@"PriorityCell"];
if (EQNBackgroundPositionDebugHelper.shared.isEnabled) {
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(backgroundPositionDebugTapped:)];
@@ -330,7 +331,7 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
} else if (tableRow == AllerteTableRowServizioPriorita) {
AlertsPriorityServiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PriorityCell" forIndexPath:indexPath];
cell.smartphoneNetwork = [EQNManager defaultManager].rete_smartphone;
[cell updateWith:[EQNManager defaultManager].rete_smartphone];
return cell;
} else if (tableRow == AllerteTableRowDatiPosizione) {
@@ -8,37 +8,61 @@
import UIKit
class AlertsPriorityServiceTableViewCell: EQNBaseTableViewCell {
@objc var smartphoneNetwork: EQNReteSmartphone? {
didSet {
updateUI()
}
}
@objc
class AlertsPriorityServiceTableViewCell: EQNBaseContainerTableViewCell {
override var headerText: String { NSLocalizedString("inapp_list", comment: "") }
// MARK: - UI
private lazy var descriptionLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.textColor = AppTheme.Colors.darkGray
label.font = .preferredFont(forTextStyle: .body)
return label
}()
private lazy var lastSubscriptionLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.textColor = AppTheme.Colors.red
label.font = .preferredFont(forTextStyle: .body)
return label
}()
// 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()
override func setupUI() {
super.setupUI()
localizeUI()
containerView.addSubview(descriptionLabel)
containerView.addSubview(lastSubscriptionLabel)
descriptionLabel.topAnchor.constraint(equalTo: topView.bottomAnchor, constant: Self.DefaultVerticalSpacing).isActive = true
descriptionLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: Self.DefaultPadding).isActive = true
descriptionLabel.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -Self.DefaultPadding).isActive = true
lastSubscriptionLabel.topAnchor.constraint(equalTo: descriptionLabel.bottomAnchor, constant: Self.DefaultVerticalSpacing/2.0).isActive = true
lastSubscriptionLabel.leadingAnchor.constraint(equalTo: descriptionLabel.leadingAnchor).isActive = true
lastSubscriptionLabel.trailingAnchor.constraint(equalTo: descriptionLabel.trailingAnchor).isActive = true
lastSubscriptionLabel.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -Self.DefaultPadding).isActive = true
}
// MARK: - Private
private func localizeUI() {
headerLabel.text = NSLocalizedString("inapp_list", comment: "")
override func updateUI() {
super.updateUI()
containerView.backgroundColor = AppTheme.Colors.cardBackgroundRed
descriptionLabel.text = NSLocalizedString("inapp_adv", comment: "")
}
private func updateUI() {
guard let smartphoneNetwork = smartphoneNetwork else { return }
// MARK: - Public
@objc
func update(with smartphoneNetwork: EQNReteSmartphone?) {
guard let smartphoneNetwork else { return }
lastSubscriptionLabel.text = subscriptionText(for: smartphoneNetwork.lastSubscriptionDiff)
}
@@ -1846,91 +1846,8 @@ Sisma rilevato da 10 smartphone</string>
<outlet property="mapButton" destination="o3D-zn-NCG" id="ffU-12-HOz"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="PriorityCell" rowHeight="170" id="gXs-mo-UQM" customClass="AlertsPriorityServiceTableViewCell" customModule="Earthquake_Network" customModuleProvider="target">
<rect key="frame" x="0.0" y="1258" width="414" height="170"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="gXs-mo-UQM" id="ViI-oT-s00">
<rect key="frame" x="0.0" y="0.0" width="414" height="170"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="GF8-ah-qqT">
<rect key="frame" x="8" y="8" width="398" height="154"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Priority service" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JeR-MS-yEq" customClass="EQNEdgeInsetLabel" customModule="Earthquake_Network" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="117.5" height="26"/>
<color key="backgroundColor" red="0.50766238939999997" green="0.75272958739999996" blue="0.98132258650000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="26" id="yn0-mM-uof"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" axis="vertical" distribution="equalSpacing" translatesAutoresizingMaskIntoConstraints="NO" id="zHS-h1-Tdo">
<rect key="frame" x="8" y="34" width="284" height="112"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Be the first to be alerted when a quake is detected real time." textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1mF-xh-GVj">
<rect key="frame" x="0.0" y="0.0" width="284" height="42.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" name="Gray (dark)"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="A user has subscribed to the service only %d minute ago!" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3dQ-Eh-0Iw">
<rect key="frame" x="0.0" y="69.5" width="284" height="42.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.84313725490196079" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="priority" translatesAutoresizingMaskIntoConstraints="NO" id="3Hs-fb-4gz">
<rect key="frame" x="296" y="8" width="98" height="95"/>
<constraints>
<constraint firstAttribute="width" constant="98" id="e82-JS-FuC"/>
<constraint firstAttribute="height" constant="95" id="jV5-l5-FhY"/>
</constraints>
</imageView>
<button opaque="NO" tag="10" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fko-1v-doJ">
<rect key="frame" x="296" y="29.5" width="94" height="95"/>
<constraints>
<constraint firstAttribute="width" constant="94" id="f5j-RJ-bnc"/>
<constraint firstAttribute="height" constant="95" id="kBy-EW-KWq"/>
</constraints>
</button>
</subviews>
<color key="backgroundColor" name="Red (card background)"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="3Hs-fb-4gz" secondAttribute="trailing" constant="4" id="1Eb-F0-Of7"/>
<constraint firstItem="3Hs-fb-4gz" firstAttribute="top" secondItem="GF8-ah-qqT" secondAttribute="top" constant="8" id="ARk-iV-frQ"/>
<constraint firstItem="zHS-h1-Tdo" firstAttribute="top" secondItem="JeR-MS-yEq" secondAttribute="bottom" constant="8" id="JGz-fS-8Kh"/>
<constraint firstAttribute="trailing" secondItem="Fko-1v-doJ" secondAttribute="trailing" constant="8" id="JTA-LN-IyY"/>
<constraint firstAttribute="trailing" secondItem="JeR-MS-yEq" secondAttribute="trailing" priority="250" id="QUG-uF-cWh"/>
<constraint firstItem="3Hs-fb-4gz" firstAttribute="leading" secondItem="zHS-h1-Tdo" secondAttribute="trailing" constant="4" id="U6r-6B-2cm"/>
<constraint firstItem="JeR-MS-yEq" firstAttribute="top" secondItem="GF8-ah-qqT" secondAttribute="top" id="Z1r-LR-m79"/>
<constraint firstItem="zHS-h1-Tdo" firstAttribute="leading" secondItem="GF8-ah-qqT" secondAttribute="leading" constant="8" id="cu1-6D-3Ln"/>
<constraint firstAttribute="bottom" secondItem="zHS-h1-Tdo" secondAttribute="bottom" constant="8" id="dDY-Gd-ewA"/>
<constraint firstItem="JeR-MS-yEq" firstAttribute="leading" secondItem="GF8-ah-qqT" secondAttribute="leading" id="flJ-fC-fOT"/>
<constraint firstItem="Fko-1v-doJ" firstAttribute="centerY" secondItem="GF8-ah-qqT" secondAttribute="centerY" id="ik2-ll-PnQ"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="GF8-ah-qqT" secondAttribute="trailing" constant="8" id="3R2-gt-38x"/>
<constraint firstAttribute="bottom" secondItem="GF8-ah-qqT" secondAttribute="bottom" constant="8" id="EFZ-HC-nHp"/>
<constraint firstItem="GF8-ah-qqT" firstAttribute="top" secondItem="ViI-oT-s00" secondAttribute="top" constant="8" id="Su7-uc-Way"/>
<constraint firstItem="GF8-ah-qqT" firstAttribute="leading" secondItem="ViI-oT-s00" secondAttribute="leading" constant="8" id="vEU-lj-BhV"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="containerView" destination="GF8-ah-qqT" id="V5g-Wv-X9t"/>
<outlet property="descriptionLabel" destination="1mF-xh-GVj" id="j3X-ll-zWQ"/>
<outlet property="headerLabel" destination="JeR-MS-yEq" id="Gc0-Uf-vWQ"/>
<outlet property="lastSubscriptionLabel" destination="3dQ-Eh-0Iw" id="X5B-rI-e64"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="PositionDataCell" rowHeight="180" id="j9i-Sk-o3g" customClass="AlertsPositionDataTableViewCell" customModule="Earthquake_Network" customModuleProvider="target">
<rect key="frame" x="0.0" y="1428" width="414" height="180"/>
<rect key="frame" x="0.0" y="1258" width="414" height="180"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="j9i-Sk-o3g" id="sTW-Bj-7Bz">
<rect key="frame" x="0.0" y="0.0" width="414" height="180"/>
@@ -2097,7 +2014,6 @@ Sisma rilevato da 10 smartphone</string>
<image name="navbar-icon-filters" width="24" height="24"/>
<image name="navbar-icon-refresh" width="24" height="24"/>
<image name="navbar-icon-sort" width="24" height="24"/>
<image name="priority" width="100" height="100"/>
<image name="sunrise" width="85" height="85"/>
<image name="sunset" width="85" height="85"/>
<image name="tabbar-icon-alerts" width="25" height="25"/>
@@ -2157,9 +2073,6 @@ Sisma rilevato da 10 smartphone</string>
<namedColor name="Red">
<color red="1" green="0.14900000393390656" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Red (card background)">
<color red="0.99607843137254903" green="0.62745098039215685" blue="0.67843137254901964" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="groupTableViewBackgroundColor">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
@@ -19,6 +19,8 @@ class AppTheme: NSObject {
static let gray = UIColor(named: "Gray")!
static let darkGray = UIColor(named: "Gray (dark)")!
static let lightGray = UIColor(named: "Gray (light)")!
static let cardBackgroundRed = UIColor(named: "Red (card background)")!
}
static let shared = AppTheme()
@@ -37,9 +37,15 @@ class EQNBaseContainerTableViewCell: UITableViewCell {
label.textColor = .white
return label
}()
private lazy var emptyTopView: UIView = {
let view = UIView(frame: .zero)
view.backgroundColor = .clear
return view
}()
var topView: UIView {
isHeaderVisible ? headerLabel : containerView
isHeaderVisible ? headerLabel : emptyTopView
}
var isHeaderVisible: Bool { true }
@@ -77,6 +83,12 @@ class EQNBaseContainerTableViewCell: UITableViewCell {
headerLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
headerLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true
headerLabel.heightAnchor.constraint(equalToConstant: 26.0).isActive = true
} else {
containerView.addSubview(emptyTopView)
emptyTopView.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
emptyTopView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true
emptyTopView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor).isActive = true
emptyTopView.heightAnchor.constraint(equalToConstant: 0.0).isActive = true
}
}