Skip to content

Commit e9b32d4

Browse files
Merge pull request #428 from woocommerce/issue/nuking-orderstatus-viewmodel
Deprecating OrderStatusViewModel
2 parents 9e9d7d9 + b609327 commit e9b32d4

File tree

8 files changed

+162
-141
lines changed

8 files changed

+162
-141
lines changed

WooCommerce/Classes/Extensions/UILabel+Helpers.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,6 @@ extension UILabel {
3333
textColor = StyleManager.defaultTextColor
3434
}
3535

36-
func applyStatusStyle(for status: OrderStatus) {
37-
adjustsFontForContentSizeCategory = true
38-
layer.borderWidth = 1.0
39-
layer.cornerRadius = 4.0
40-
font = .footnote
41-
42-
switch status {
43-
case .processing:
44-
fallthrough
45-
case .pending:
46-
backgroundColor = StyleManager.statusSuccessColor
47-
layer.borderColor = StyleManager.statusSuccessBoldColor.cgColor
48-
case .failed:
49-
fallthrough
50-
case .refunded:
51-
backgroundColor = StyleManager.statusDangerColor
52-
layer.borderColor = StyleManager.statusDangerBoldColor.cgColor
53-
case .completed:
54-
backgroundColor = StyleManager.statusPrimaryColor
55-
layer.borderColor = StyleManager.statusPrimaryBoldColor.cgColor
56-
case .onHold:
57-
fallthrough
58-
case .cancelled:
59-
fallthrough
60-
case .custom:
61-
fallthrough
62-
default:
63-
backgroundColor = StyleManager.statusNotIdentifiedColor
64-
layer.borderColor = StyleManager.statusNotIdentifiedBoldColor.cgColor
65-
}
66-
}
67-
6836
func applyPaddedLabelDefaultStyles() {
6937
adjustsFontForContentSizeCategory = true
7038
layer.borderWidth = 1.0
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import Foundation
2+
import UIKit
3+
import Yosemite
4+
5+
6+
// MARK: - UILabel + OrderStatus Methods
7+
//
8+
extension UILabel {
9+
10+
/// Applies the appropriate Style for a given OrderStatus
11+
///
12+
func applyStyle(for status: OrderStatus) {
13+
applyFootnoteStyle()
14+
applyLayerSettings()
15+
applyBackground(for: status)
16+
}
17+
18+
/// Setup: Layer
19+
///
20+
private func applyLayerSettings() {
21+
layer.borderWidth = OrderStatusSettings.borderWidth
22+
layer.cornerRadius = OrderStatusSettings.cornerRadius
23+
}
24+
25+
/// Setup: Background Color
26+
///
27+
private func applyBackground(for status: OrderStatus) {
28+
switch status {
29+
case .processing:
30+
fallthrough
31+
case .pending:
32+
backgroundColor = StyleManager.statusSuccessColor
33+
layer.borderColor = StyleManager.statusSuccessBoldColor.cgColor
34+
case .failed:
35+
fallthrough
36+
case .refunded:
37+
backgroundColor = StyleManager.statusDangerColor
38+
layer.borderColor = StyleManager.statusDangerBoldColor.cgColor
39+
case .completed:
40+
backgroundColor = StyleManager.statusPrimaryColor
41+
layer.borderColor = StyleManager.statusPrimaryBoldColor.cgColor
42+
case .onHold:
43+
fallthrough
44+
case .cancelled:
45+
fallthrough
46+
case .custom:
47+
fallthrough
48+
default:
49+
backgroundColor = StyleManager.statusNotIdentifiedColor
50+
layer.borderColor = StyleManager.statusNotIdentifiedBoldColor.cgColor
51+
}
52+
}
53+
}
54+
55+
56+
// MARK: - Private
57+
//
58+
private extension UILabel {
59+
60+
enum OrderStatusSettings {
61+
static let borderWidth = CGFloat(1.0)
62+
static let cornerRadius = CGFloat(4.0)
63+
}
64+
}

WooCommerce/Classes/ViewModels/OrderDetailsViewModel.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ class OrderDetailsViewModel {
88
let moneyFormatter: MoneyFormatter
99
let couponLines: [OrderCouponLine]?
1010

11-
let orderStatusViewModel: OrderStatusViewModel
12-
1311
init(order: Order) {
1412
self.order = order
1513
self.moneyFormatter = MoneyFormatter()
1614
self.couponLines = order.coupons
17-
self.orderStatusViewModel = OrderStatusViewModel(orderStatus: order.status)
1815
}
1916

2017
var summaryTitle: String? {
@@ -39,18 +36,6 @@ class OrderDetailsViewModel {
3936

4037
let fulfillTitle = NSLocalizedString("Fulfill order", comment: "Fulfill order button title")
4138

42-
var paymentStatus: String {
43-
return order.status.description
44-
}
45-
46-
var paymentBackgroundColor: UIColor {
47-
return orderStatusViewModel.backgroundColor
48-
}
49-
50-
var paymentBorderColor: CGColor {
51-
return orderStatusViewModel.borderColor
52-
}
53-
5439
var isProcessingPayment: Bool {
5540
return order.status == .processing
5641
}

WooCommerce/Classes/ViewModels/OrderStatusViewModel.swift

Lines changed: 0 additions & 56 deletions
This file was deleted.

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/OrderDetailsViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,8 @@ private extension OrderDetailsViewController {
432432
func configureSummary(cell: SummaryTableViewCell) {
433433
cell.title = viewModel.summaryTitle
434434
cell.dateCreated = viewModel.summaryDateCreated
435-
cell.paymentStatus = viewModel.paymentStatus
436-
cell.paymentBackgroundColor = viewModel.paymentBackgroundColor
437-
cell.paymentBorderColor = viewModel.paymentBorderColor
435+
436+
cell.display(orderStatus: viewModel.order.status)
438437
}
439438

440439
// MARK: - Get order note
Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
import UIKit
2+
import Yosemite
23

4+
5+
// MARK: - SummaryTableViewCell
6+
//
37
class SummaryTableViewCell: UITableViewCell {
8+
9+
/// Label: Title
10+
///
411
@IBOutlet private weak var titleLabel: UILabel!
5-
@IBOutlet private weak var createdLabel: UILabel!
6-
@IBOutlet private weak var paymentStatusLabel: PaddedLabel!
712

8-
public var paymentBackgroundColor: UIColor = .clear
13+
/// Label: Creation / Update Date
14+
///
15+
@IBOutlet private weak var createdLabel: UILabel!
916

17+
/// Label: Payment Status
18+
///
19+
@IBOutlet private weak var paymentStatusLabel: PaddedLabel!
1020

11-
public var title: String? {
21+
/// Title
22+
///
23+
var title: String? {
1224
get {
1325
return titleLabel.text
1426
}
1527
set {
1628
titleLabel.text = newValue
17-
titleLabel.applyHeadlineStyle()
1829
}
1930
}
2031

21-
public var dateCreated: String? {
32+
/// Date
33+
///
34+
var dateCreated: String? {
2235
get {
2336
return createdLabel.text
2437
}
2538
set {
2639
createdLabel.text = newValue
27-
createdLabel.applyFootnoteStyle()
2840
}
2941
}
3042

31-
public var paymentStatus: String? {
32-
get {
33-
return paymentStatusLabel.text
34-
}
35-
set {
36-
paymentStatusLabel.text = newValue
37-
paymentStatusLabel.applyPaddedLabelDefaultStyles()
38-
paymentStatusLabel.backgroundColor = paymentBackgroundColor
39-
}
43+
/// Displays the specified OrderStatus, and applies the right Label Style
44+
///
45+
func display(orderStatus: OrderStatus) {
46+
paymentStatusLabel.text = orderStatus.description
47+
paymentStatusLabel.applyStyle(for: orderStatus)
4048
}
4149

42-
public var paymentBorderColor: CGColor? {
43-
get {
44-
return paymentStatusLabel.layer.borderColor
45-
}
46-
set {
47-
paymentStatusLabel.layer.borderColor = newValue
48-
}
50+
51+
// MARK: - Overridden Methods
52+
53+
override func awakeFromNib() {
54+
super.awakeFromNib()
55+
configureLabels()
4956
}
5057

5158
override func setSelected(_ selected: Bool, animated: Bool) {
@@ -59,9 +66,28 @@ class SummaryTableViewCell: UITableViewCell {
5966
super.setHighlighted(highlighted, animated: animated)
6067
}
6168
}
69+
}
70+
6271

72+
// MARK: - Private
73+
//
74+
private extension SummaryTableViewCell {
75+
76+
/// Preserves the current Payment BG Color
77+
///
6378
func preserveLabelColors(action: () -> Void) {
79+
let paymentColor = paymentStatusLabel.backgroundColor
80+
6481
action()
65-
paymentStatusLabel.backgroundColor = paymentBackgroundColor
82+
83+
paymentStatusLabel.backgroundColor = paymentColor
84+
}
85+
86+
/// Setup: Labels
87+
///
88+
func configureLabels() {
89+
titleLabel.applyHeadlineStyle()
90+
createdLabel.applyFootnoteStyle()
91+
paymentStatusLabel.applyPaddedLabelDefaultStyles()
6692
}
6793
}

WooCommerce/Classes/ViewRelated/Orders/OrderListCell.swift

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
import UIKit
22

33

4+
// MARK: - OrderListCell
5+
//
46
class OrderListCell: UITableViewCell {
5-
@IBOutlet var titleLabel: UILabel!
6-
@IBOutlet var totalLabel: UILabel!
7-
@IBOutlet var paymentStatusLabel: PaddedLabel!
87

8+
/// Order's Title
9+
///
10+
@IBOutlet private var titleLabel: UILabel!
911

12+
/// Order's Total
13+
///
14+
@IBOutlet private var totalLabel: UILabel!
15+
16+
/// Payment
17+
///
18+
@IBOutlet private var paymentStatusLabel: PaddedLabel!
19+
20+
21+
/// Renders the specified Order ViewModel
22+
///
1023
func configureCell(viewModel: OrderDetailsViewModel) {
1124
titleLabel.text = viewModel.summaryTitle
12-
titleLabel.applyHeadlineStyle()
1325

1426
totalLabel.text = viewModel.totalFriendlyString
15-
totalLabel.applyBodyStyle()
1627

17-
paymentStatusLabel.text = viewModel.paymentStatus
18-
paymentStatusLabel.applyStatusStyle(for: viewModel.orderStatusViewModel.orderStatus)
28+
paymentStatusLabel.text = viewModel.order.status.description
29+
paymentStatusLabel.applyStyle(for: viewModel.order.status)
30+
}
31+
32+
33+
// MARK: - Overridden Methods
34+
35+
override func awakeFromNib() {
36+
super.awakeFromNib()
37+
configureLabels()
1938
}
2039

2140
override func setSelected(_ selected: Bool, animated: Bool) {
@@ -34,12 +53,28 @@ class OrderListCell: UITableViewCell {
3453
super.prepareForReuse()
3554
paymentStatusLabel.layer.borderColor = UIColor.clear.cgColor
3655
}
56+
}
57+
58+
59+
// MARK: - Private
60+
//
61+
private extension OrderListCell {
3762

63+
/// Preserves the current Payment BG Color
64+
///
3865
func preserveLabelColors(action: () -> Void) {
3966
let paymentColor = paymentStatusLabel.backgroundColor
4067

4168
action()
4269

4370
paymentStatusLabel.backgroundColor = paymentColor
4471
}
72+
73+
/// Setup: Labels
74+
///
75+
func configureLabels() {
76+
titleLabel.applyHeadlineStyle()
77+
totalLabel.applyBodyStyle()
78+
paymentStatusLabel.applyFootnoteStyle()
79+
}
4580
}

0 commit comments

Comments
 (0)