Skip to content

Commit a8bdd40

Browse files
committed
Spin and disable disconnect button while disconnecting, same for update button
1 parent bf3c15a commit a8bdd40

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/CardReaderSettingsConnectedViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ private extension CardReaderSettingsConnectedViewController {
213213
cell.configure(style: .primary, title: Localization.updateButtonTitle, bottomSpacing: 0) {
214214
self.viewModel?.startCardReaderUpdate()
215215
}
216+
217+
let readerDisconnectInProgress = viewModel?.readerDisconnectInProgress ?? false
218+
let readerUpdateInProgress = viewModel?.readerUpdateInProgress ?? false
219+
cell.enableButton(!readerDisconnectInProgress && !readerUpdateInProgress)
220+
cell.showActivityIndicator(readerUpdateInProgress)
221+
216222
cell.selectionStyle = .none
217223
cell.backgroundColor = .clear
218224
}
@@ -222,6 +228,12 @@ private extension CardReaderSettingsConnectedViewController {
222228
cell.configure(style: style, title: Localization.disconnectButtonTitle) { [weak self] in
223229
self?.viewModel?.disconnectReader()
224230
}
231+
232+
let readerDisconnectInProgress = viewModel?.readerDisconnectInProgress ?? false
233+
let readerUpdateInProgress = viewModel?.readerUpdateInProgress ?? false
234+
cell.enableButton(!readerDisconnectInProgress && !readerUpdateInProgress)
235+
cell.showActivityIndicator(readerDisconnectInProgress)
236+
225237
cell.selectionStyle = .none
226238
cell.backgroundColor = .clear
227239
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/CardReaderSettingsConnectedViewModel.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ final class CardReaderSettingsConnectedViewModel: CardReaderSettingsPresentedVie
1414
private(set) var readerUpdateInProgress: Bool = false
1515
private(set) var readerUpdateCompletedSuccessfully: Bool = false
1616

17+
private(set) var readerDisconnectInProgress: Bool = false
18+
1719
var connectedReaderID: String?
1820
var connectedReaderBatteryLevel: String?
1921

@@ -66,6 +68,9 @@ final class CardReaderSettingsConnectedViewModel: CardReaderSettingsPresentedVie
6668
guard let self = self else {
6769
return
6870
}
71+
guard !self.readerDisconnectInProgress else {
72+
return
73+
}
6974
switch result {
7075
case .success(let update):
7176
self.readerUpdateAvailable = update != nil ? .isTrue : .isFalse
@@ -112,11 +117,17 @@ final class CardReaderSettingsConnectedViewModel: CardReaderSettingsPresentedVie
112117
func disconnectReader() {
113118
ServiceLocator.analytics.track(.cardReaderDisconnectTapped)
114119

120+
self.readerDisconnectInProgress = true
121+
self.didUpdate?()
122+
115123
if connectedReaderID != nil {
116124
knownReadersProvider?.forgetCardReader(cardReaderID: connectedReaderID!)
117125
}
118126

119127
let action = CardPresentPaymentAction.disconnect() { result in
128+
self.readerDisconnectInProgress = false
129+
self.didUpdate?()
130+
120131
guard result.isSuccess else {
121132
DDLogError("Unexpected error when disconnecting reader")
122133
return

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Cells/ShippingLabelFormStepTableViewCell.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
77
<capability name="System colors in document resources" minToolsVersion="11.0"/>
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>

WooCommerce/Classes/ViewRelated/ReusableViews/ButtonTableViewCell.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import UIKit
33
/// Displays a button inside a `UITableViewCell`.
44
///
55
final class ButtonTableViewCell: UITableViewCell {
6-
@IBOutlet private var button: UIButton!
6+
@IBOutlet private var button: ButtonActivityIndicator!
77
@IBOutlet private weak var topConstraint: NSLayoutConstraint!
88
@IBOutlet private weak var bottomConstraint: NSLayoutConstraint!
99

@@ -49,6 +49,14 @@ final class ButtonTableViewCell: UITableViewCell {
4949
func enableButton(_ enabled: Bool) {
5050
button.isEnabled = enabled
5151
}
52+
53+
func showActivityIndicator(_ show: Bool) {
54+
guard show else {
55+
button.hideActivityIndicator()
56+
return
57+
}
58+
button.showActivityIndicator()
59+
}
5260
}
5361

5462
private extension ButtonTableViewCell {

WooCommerce/Classes/ViewRelated/ReusableViews/ButtonTableViewCell.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
77
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
88
</dependencies>
@@ -16,7 +16,7 @@
1616
<rect key="frame" x="0.0" y="0.0" width="331" height="75"/>
1717
<autoresizingMask key="autoresizingMask"/>
1818
<subviews>
19-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rng-8C-l5l">
19+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rng-8C-l5l" customClass="ButtonActivityIndicator" customModule="WooCommerce" customModuleProvider="target">
2020
<rect key="frame" x="16" y="20" width="299" height="35"/>
2121
<state key="normal" title="Button"/>
2222
<connections>

0 commit comments

Comments
 (0)