Skip to content

Commit e559a0d

Browse files
committed
8082 Extract shared progress logic to protocol ext
1 parent b7a4f85 commit e559a0d

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalBuiltInConfigurationProgress.swift

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

33
/// Modal presented when a firmware update is being installed
44
///
5-
final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsModalViewModel {
5+
final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsModalViewModel, CardPresentModalProgressDisplaying {
66
/// Called when cancel button is tapped
77
private let cancelAction: (() -> Void)?
88

@@ -13,29 +13,26 @@ final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsMod
1313

1414
var topSubtitle: String? = nil
1515

16-
let image: UIImage
16+
var progress: Float
1717

1818
let primaryButtonTitle: String? = nil
1919

2020
let secondaryButtonTitle: String? = Localization.cancel
2121

2222
let auxiliaryButtonTitle: String? = nil
2323

24-
let bottomTitle: String?
25-
2624
var bottomSubtitle: String? = nil
2725

2826
var accessibilityLabel: String? {
2927
Localization.title
3028
}
3129

3230
init(progress: Float, cancel: (() -> Void)?) {
31+
self.progress = progress
3332
self.cancelAction = cancel
3433

3534
let isComplete = progress == 1
3635
topTitle = isComplete ? Localization.titleComplete : Localization.title
37-
image = .softwareUpdateProgress(progress: CGFloat(progress))
38-
bottomTitle = String(format: Localization.percentComplete, 100 * progress)
3936
bottomSubtitle = isComplete ? Localization.messageComplete : Localization.message
4037
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
4138
}
@@ -61,11 +58,6 @@ private extension CardPresentModalBuiltInConfigurationProgress {
6158
comment: "Dialog title that displays when a configuration update just finished installing"
6259
)
6360

64-
static let percentComplete = NSLocalizedString(
65-
"%.0f%% complete",
66-
comment: "Label that describes the completed progress of a software update being installed (e.g. 15% complete). Keep the %.0f%% exactly as is"
67-
)
68-
6961
static let message = NSLocalizedString(
7062
"Your iPhone needs to be configured to collect payments.",
7163
comment: "Label that displays when a configuration update is happening"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import UIKit
2+
3+
protocol CardPresentModalProgressDisplaying: CardPresentPaymentsModalViewModel {
4+
var progress: Float { get }
5+
}
6+
7+
extension CardPresentModalProgressDisplaying {
8+
var image: UIImage {
9+
.softwareUpdateProgress(progress: CGFloat(progress))
10+
}
11+
12+
var bottomTitle: String? {
13+
String(format: CardPresentModalProgressDisplayingLocalization.percentComplete, 100 * progress)
14+
}
15+
}
16+
17+
fileprivate enum CardPresentModalProgressDisplayingLocalization {
18+
static let percentComplete = NSLocalizedString(
19+
"%.0f%% complete",
20+
comment: "Label that describes the completed progress of an update being installed (e.g. 15% complete). Keep the %.0f%% exactly as is"
21+
)
22+
}

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalUpdateProgress.swift

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

33
/// Modal presented when a firmware update is being installed
44
///
5-
final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel {
5+
final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel, CardPresentModalProgressDisplaying {
66
/// Called when cancel button is tapped
77
private let cancelAction: (() -> Void)?
88

@@ -13,29 +13,26 @@ final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel {
1313

1414
var topSubtitle: String? = nil
1515

16-
let image: UIImage
16+
var progress: Float
1717

1818
let primaryButtonTitle: String? = nil
1919

2020
let secondaryButtonTitle: String? = Localization.cancel
2121

2222
let auxiliaryButtonTitle: String? = nil
2323

24-
let bottomTitle: String?
25-
2624
var bottomSubtitle: String? = nil
2725

2826
var accessibilityLabel: String? {
2927
Localization.title
3028
}
3129

3230
init(requiredUpdate: Bool, progress: Float, cancel: (() -> Void)?) {
31+
self.progress = progress
3332
self.cancelAction = cancel
3433

3534
let isComplete = progress == 1
3635
topTitle = isComplete ? Localization.titleComplete : Localization.title
37-
image = .softwareUpdateProgress(progress: CGFloat(progress))
38-
bottomTitle = String(format: Localization.percentComplete, 100 * progress)
3936
if !isComplete {
4037
bottomSubtitle = requiredUpdate ? Localization.messageRequired : Localization.messageOptional
4138
}
@@ -63,12 +60,6 @@ private extension CardPresentModalUpdateProgress {
6360
comment: "Dialog title that displays when a software update just finished installing"
6461
)
6562

66-
67-
static let percentComplete = NSLocalizedString(
68-
"%.0f%% complete",
69-
comment: "Label that describes the completed progress of a software update being installed (e.g. 15% complete). Keep the %.0f%% exactly as is"
70-
)
71-
7263
static let messageRequired = NSLocalizedString(
7364
"Your card reader software needs to be updated to collect payments. Cancelling will block your reader connection.",
7465
comment: "Label that displays when a mandatory software update is happening"

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@
501501
03E471C6293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C5293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift */; };
502502
03E471C8293A3076001A58AD /* CardPresentModalBuiltInConnectingToReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C7293A3075001A58AD /* CardPresentModalBuiltInConnectingToReader.swift */; };
503503
03E471CA293E0A30001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C9293E0A2F001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift */; };
504+
03E471CC293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471CB293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift */; };
504505
03EF24FA28BF5D21006A033E /* InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EF24F928BF5D21006A033E /* InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift */; };
505506
03EF24FC28BF996F006A033E /* InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EF24FB28BF996F006A033E /* InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift */; };
506507
03EF24FE28C0B356006A033E /* CardPresentPaymentsPlugin+CashOnDelivery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EF24FD28C0B356006A033E /* CardPresentPaymentsPlugin+CashOnDelivery.swift */; };
@@ -2513,6 +2514,7 @@
25132514
03E471C5293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardPresentModalBuiltInReaderCheckingDeviceSupport.swift; sourceTree = "<group>"; };
25142515
03E471C7293A3075001A58AD /* CardPresentModalBuiltInConnectingToReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardPresentModalBuiltInConnectingToReader.swift; sourceTree = "<group>"; };
25152516
03E471C9293E0A2F001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardPresentModalBuiltInConfigurationProgress.swift; sourceTree = "<group>"; };
2517+
03E471CB293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalProgressDisplaying.swift; sourceTree = "<group>"; };
25162518
03EF24F928BF5D21006A033E /* InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift; sourceTree = "<group>"; };
25172519
03EF24FB28BF996F006A033E /* InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift; sourceTree = "<group>"; };
25182520
03EF24FD28C0B356006A033E /* CardPresentPaymentsPlugin+CashOnDelivery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CardPresentPaymentsPlugin+CashOnDelivery.swift"; sourceTree = "<group>"; };
@@ -8558,6 +8560,7 @@
85588560
D8815AE626383FD600EDAD62 /* CardPresentPaymentsModalViewModel.swift */,
85598561
03E471C5293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift */,
85608562
03E471C9293E0A2F001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift */,
8563+
03E471CB293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift */,
85618564
03E471C7293A3075001A58AD /* CardPresentModalBuiltInConnectingToReader.swift */,
85628565
311237ED2714DA240033C44E /* CardPresentModalDisplayMessage.swift */,
85638566
D8815B0026385E3F00EDAD62 /* CardPresentModalTapCard.swift */,
@@ -9995,6 +9998,7 @@
99959998
E138D4FC269EEAFE006EA5C6 /* InPersonPaymentsViewModel.swift in Sources */,
99969999
039D948F276113490044EF38 /* UIView+SuperviewConstraints.swift in Sources */,
999710000
D8736B5322EF4F5900A14A29 /* NotificationsBadgeController.swift in Sources */,
10001+
03E471CC293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift in Sources */,
999810002
B541B220218A007C008FE7C1 /* NSMutableParagraphStyle+Helpers.swift in Sources */,
999910003
45AE582C230D9D35001901E3 /* OrderNoteHeaderTableViewCell.swift in Sources */,
1000010004
6832C7CA26DA5C4500BA4088 /* LabeledTextViewTableViewCell.swift in Sources */,

0 commit comments

Comments
 (0)