Skip to content

Commit 0af2f5e

Browse files
committed
8082 Extract progress alert title and message logic
1 parent e559a0d commit 0af2f5e

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalBuiltInConfigurationProgress.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsMod
99
let textMode: PaymentsModalTextMode = .fullInfo
1010
let actionsMode: PaymentsModalActionsMode
1111

12-
var topTitle: String
13-
1412
var topSubtitle: String? = nil
1513

1614
var progress: Float
@@ -21,7 +19,13 @@ final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsMod
2119

2220
let auxiliaryButtonTitle: String? = nil
2321

24-
var bottomSubtitle: String? = nil
22+
var titleComplete: String
23+
24+
var titleInProgress: String
25+
26+
var messageComplete: String?
27+
28+
var messageInProgress: String?
2529

2630
var accessibilityLabel: String? {
2731
Localization.title
@@ -31,9 +35,10 @@ final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsMod
3135
self.progress = progress
3236
self.cancelAction = cancel
3337

34-
let isComplete = progress == 1
35-
topTitle = isComplete ? Localization.titleComplete : Localization.title
36-
bottomSubtitle = isComplete ? Localization.messageComplete : Localization.message
38+
titleComplete = Localization.titleComplete
39+
titleInProgress = Localization.title
40+
messageComplete = Localization.messageComplete
41+
messageInProgress = Localization.message
3742
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
3843
}
3944

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalProgressDisplaying.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,33 @@ import UIKit
22

33
protocol CardPresentModalProgressDisplaying: CardPresentPaymentsModalViewModel {
44
var progress: Float { get }
5+
var isComplete: Bool { get }
6+
var titleComplete: String { get }
7+
var titleInProgress: String { get }
8+
var messageComplete: String? { get }
9+
var messageInProgress: String? { get }
510
}
611

712
extension CardPresentModalProgressDisplaying {
813
var image: UIImage {
914
.softwareUpdateProgress(progress: CGFloat(progress))
1015
}
1116

17+
var isComplete: Bool {
18+
progress == 1
19+
}
20+
21+
var topTitle: String {
22+
isComplete ? titleComplete : titleInProgress
23+
}
24+
1225
var bottomTitle: String? {
1326
String(format: CardPresentModalProgressDisplayingLocalization.percentComplete, 100 * progress)
1427
}
28+
29+
var bottomSubtitle: String? {
30+
isComplete ? messageComplete : messageInProgress
31+
}
1532
}
1633

1734
fileprivate enum CardPresentModalProgressDisplayingLocalization {

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalUpdateProgress.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel, C
99
let textMode: PaymentsModalTextMode = .fullInfo
1010
let actionsMode: PaymentsModalActionsMode
1111

12-
var topTitle: String
13-
1412
var topSubtitle: String? = nil
1513

1614
var progress: Float
@@ -21,7 +19,13 @@ final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel, C
2119

2220
let auxiliaryButtonTitle: String? = nil
2321

24-
var bottomSubtitle: String? = nil
22+
var titleComplete: String
23+
24+
var titleInProgress: String
25+
26+
var messageComplete: String?
27+
28+
var messageInProgress: String?
2529

2630
var accessibilityLabel: String? {
2731
Localization.title
@@ -30,13 +34,13 @@ final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel, C
3034
init(requiredUpdate: Bool, progress: Float, cancel: (() -> Void)?) {
3135
self.progress = progress
3236
self.cancelAction = cancel
37+
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
38+
titleComplete = Localization.titleComplete
39+
titleInProgress = Localization.title
3340

34-
let isComplete = progress == 1
35-
topTitle = isComplete ? Localization.titleComplete : Localization.title
3641
if !isComplete {
37-
bottomSubtitle = requiredUpdate ? Localization.messageRequired : Localization.messageOptional
42+
messageInProgress = requiredUpdate ? Localization.messageRequired : Localization.messageOptional
3843
}
39-
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
4044
}
4145

4246
func didTapPrimaryButton(in viewController: UIViewController?) {}

0 commit comments

Comments
 (0)