Skip to content

Commit 2fa7ddb

Browse files
committed
Add subtype for TitleAndSubtitleAndStatusTableViewCell's cell view model
1 parent a7f3064 commit 2fa7ddb

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

WooCommerce/Classes/ViewRelated/Coupons/CouponListViewController.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,13 @@ extension CouponListViewController: UITableViewDataSource {
212212

213213
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
214214
let cell = tableView.dequeueReusableCell(withIdentifier: TitleAndSubtitleAndStatusTableViewCell.reuseIdentifier, for: indexPath)
215-
if let cellViewModel = viewModel.couponViewModels[safe: indexPath.row] {
216-
configure(cell as? TitleAndSubtitleAndStatusTableViewCell, with: cellViewModel)
215+
if let cellViewModel = viewModel.couponViewModels[safe: indexPath.row],
216+
let cell = cell as? TitleAndSubtitleAndStatusTableViewCell {
217+
cell.configureCell(viewModel: cellViewModel)
217218
}
218219

219220
return cell
220221
}
221-
222-
func configure(_ cell: TitleAndSubtitleAndStatusTableViewCell?, with cellViewModel: CouponListCellViewModel) {
223-
cell?.titleLabel.text = cellViewModel.title
224-
cell?.subtitleLabel.text = cellViewModel.subtitle
225-
cell?.accessibilityLabel = cellViewModel.accessibilityLabel
226-
cell?.statusLabel.text = cellViewModel.status
227-
cell?.statusLabel.backgroundColor = cellViewModel.statusBackgroundColor
228-
}
229222
}
230223

231224

WooCommerce/Classes/ViewRelated/Coupons/CouponListViewModel.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import protocol Storage.StorageManagerType
44
import class AutomatticTracks.CrashLogging
55
import UIKit
66

7-
struct CouponListCellViewModel {
8-
var title: String
9-
var subtitle: String
10-
var accessibilityLabel: String
11-
var status: String
12-
var statusBackgroundColor: UIColor
13-
}
14-
157
enum CouponListState {
168
case initialized // ViewModel ready to recieve actions
179
case loading // View should show ghost cells
@@ -23,6 +15,8 @@ enum CouponListState {
2315

2416
final class CouponListViewModel {
2517

18+
typealias CouponListCellViewModel = TitleAndSubtitleAndStatusTableViewCell.CellViewModel
19+
2620
/// Active state
2721
///
2822
@Published private(set) var state: CouponListState = .initialized

WooCommerce/Classes/ViewRelated/ReusableViews/TitleAndSubtitleAndStatusTableViewCell.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import UIKit
22

33
final class TitleAndSubtitleAndStatusTableViewCell: UITableViewCell {
44

5-
@IBOutlet var subtitleLabel: UILabel!
6-
@IBOutlet var titleLabel: UILabel!
7-
@IBOutlet var statusContainerView: UIView!
8-
@IBOutlet var statusLabel: PaddedLabel!
5+
@IBOutlet private var subtitleLabel: UILabel!
6+
@IBOutlet private var titleLabel: UILabel!
7+
@IBOutlet private var statusContainerView: UIView!
8+
@IBOutlet private var statusLabel: PaddedLabel!
99

1010
static func register(for tableView: UITableView) {
1111
tableView.registerNib(for: self)
@@ -17,14 +17,30 @@ final class TitleAndSubtitleAndStatusTableViewCell: UITableViewCell {
1717
configureLabels()
1818
}
1919

20-
override func setSelected(_ selected: Bool, animated: Bool) {
21-
super.setSelected(selected, animated: animated)
20+
func configureCell(viewModel: CellViewModel) {
21+
titleLabel.text = viewModel.title
22+
subtitleLabel.text = viewModel.subtitle
23+
accessibilityLabel = viewModel.accessibilityLabel
24+
statusLabel.text = viewModel.status
25+
statusLabel.backgroundColor = viewModel.statusBackgroundColor
2226
}
2327

2428
}
2529

26-
// MARK: - Setup
30+
// MARK: - CellViewModel subtype
31+
//
32+
extension TitleAndSubtitleAndStatusTableViewCell {
33+
struct CellViewModel {
34+
var title: String
35+
var subtitle: String
36+
var accessibilityLabel: String
37+
var status: String
38+
var statusBackgroundColor: UIColor
39+
}
40+
}
2741

42+
// MARK: - Setup
43+
//
2844
private extension TitleAndSubtitleAndStatusTableViewCell {
2945
func configureBackground() {
3046
backgroundColor = .listForeground

WooCommerce/Classes/ViewRelated/ReusableViews/TitleAndSubtitleTableViewCell.xib renamed to WooCommerce/Classes/ViewRelated/ReusableViews/TitleAndSubtitleAndStatusTableViewCell.xib

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
34
<dependencies>
5+
<deployment identifier="iOS"/>
46
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
57
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
68
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
79
</dependencies>
810
<objects>
911
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1012
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
11-
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="TitleAndSubtitleTableViewCell" rowHeight="90" id="KGk-i7-Jjw" customClass="TitleAndSubtitleAndStatusTableViewCell" customModule="WooCommerce" customModuleProvider="target">
13+
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="TitleAndSubtitleAndStatusTableViewCell" rowHeight="90" id="KGk-i7-Jjw" customClass="TitleAndSubtitleAndStatusTableViewCell" customModule="WooCommerce" customModuleProvider="target">
1214
<rect key="frame" x="0.0" y="0.0" width="351" height="90"/>
1315
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1416
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
15-
<rect key="frame" x="0.0" y="0.0" width="325.5" height="90"/>
17+
<rect key="frame" x="0.0" y="0.0" width="321.5" height="90"/>
1618
<autoresizingMask key="autoresizingMask"/>
1719
<subviews>
1820
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="top" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="zx0-L0-tSe">
19-
<rect key="frame" x="16" y="8" width="292" height="74"/>
21+
<rect key="frame" x="16" y="8" width="288" height="74"/>
2022
<subviews>
2123
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="240" verticalHuggingPriority="260" text="Fixed product discount " textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kxr-JD-qZr" userLabel="Date Label">
2224
<rect key="frame" x="0.0" y="0.0" width="133.5" height="14.5"/>

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@
14921492
DEC6C51C27477890006832D3 /* JetpackInstallStepsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC6C51B27477890006832D3 /* JetpackInstallStepsView.swift */; };
14931493
DEC6C51E27479280006832D3 /* JetpackInstallSteps.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC6C51D27479280006832D3 /* JetpackInstallSteps.swift */; };
14941494
DECE13FB27993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DECE13F927993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.swift */; };
1495-
DECE13FC27993F6500816ECD /* TitleAndSubtitleTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DECE13FA27993F6500816ECD /* TitleAndSubtitleTableViewCell.xib */; };
1495+
DECE13FC27993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DECE13FA27993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.xib */; };
14961496
DECE1400279A595200816ECD /* Coupon+Woo.swift in Sources */ = {isa = PBXBuildFile; fileRef = DECE13FF279A595200816ECD /* Coupon+Woo.swift */; };
14971497
DEDB886B26E8531E00981595 /* ShippingLabelPackageAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEDB886A26E8531E00981595 /* ShippingLabelPackageAttributes.swift */; };
14981498
DEE6437626D87C4100888A75 /* PrintCustomsFormsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEE6437526D87C4100888A75 /* PrintCustomsFormsView.swift */; };
@@ -3102,7 +3102,7 @@
31023102
DEC6C51B27477890006832D3 /* JetpackInstallStepsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackInstallStepsView.swift; sourceTree = "<group>"; };
31033103
DEC6C51D27479280006832D3 /* JetpackInstallSteps.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackInstallSteps.swift; sourceTree = "<group>"; };
31043104
DECE13F927993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleAndSubtitleAndStatusTableViewCell.swift; sourceTree = "<group>"; };
3105-
DECE13FA27993F6500816ECD /* TitleAndSubtitleTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TitleAndSubtitleTableViewCell.xib; sourceTree = "<group>"; };
3105+
DECE13FA27993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TitleAndSubtitleAndStatusTableViewCell.xib; sourceTree = "<group>"; };
31063106
DECE13FF279A595200816ECD /* Coupon+Woo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Coupon+Woo.swift"; sourceTree = "<group>"; };
31073107
DEDB886A26E8531E00981595 /* ShippingLabelPackageAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPackageAttributes.swift; sourceTree = "<group>"; };
31083108
DEE6437526D87C4100888A75 /* PrintCustomsFormsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrintCustomsFormsView.swift; sourceTree = "<group>"; };
@@ -6903,7 +6903,7 @@
69036903
DE68B81E26F86B1700C86CFB /* OfflineBannerView.swift */,
69046904
E1E125B126EB8EE80068A9B0 /* UpdateProgressImage.swift */,
69056905
DECE13F927993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.swift */,
6906-
DECE13FA27993F6500816ECD /* TitleAndSubtitleTableViewCell.xib */,
6906+
DECE13FA27993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.xib */,
69076907
);
69086908
path = ReusableViews;
69096909
sourceTree = "<group>";
@@ -7765,7 +7765,7 @@
77657765
CE1EC8F020B8A408009762BF /* OrderNoteTableViewCell.xib in Resources */,
77667766
265BCA0E2430E771004E53EE /* ProductCategoryTableViewCell.xib in Resources */,
77677767
4515262F2577D56C0076B03C /* AddAttributeViewController.xib in Resources */,
7768-
DECE13FC27993F6500816ECD /* TitleAndSubtitleTableViewCell.xib in Resources */,
7768+
DECE13FC27993F6500816ECD /* TitleAndSubtitleAndStatusTableViewCell.xib in Resources */,
77697769
B55D4BFD20B5CDE700D7A50F /* replace_secrets.rb in Resources */,
77707770
020BE74E23B1F5EB007FE54C /* TitleAndTextFieldTableViewCell.xib in Resources */,
77717771
4580BA7523F192D400B5F764 /* ProductSettingsViewController.xib in Resources */,

0 commit comments

Comments
 (0)