@@ -79,13 +79,6 @@ private extension CardReaderSettingsConnectedViewController {
7979 configureUpdateView ( )
8080 }
8181
82- func shouldShowUpdateControls( ) -> Bool {
83- guard let viewModel = viewModel else {
84- return false
85- }
86- return viewModel. readerUpdateAvailable == . isTrue
87- }
88-
8982 /// Set the title and back button.
9083 ///
9184 func configureNavigation( ) {
@@ -97,31 +90,27 @@ private extension CardReaderSettingsConnectedViewController {
9790 func configureSections( ) {
9891 sections = [ ]
9992
100- /// This section, if present, displays a prompt to update a reader running old software
93+ /// This section displays whether or not there is update for the reader software
10194 ///
102- if shouldShowUpdateControls ( ) {
103- sections. append (
104- Section ( title: nil ,
105- rows: [
106- . updatePrompt
107- ]
108- )
109- )
95+ let checkForReaderUpdateInProgress = viewModel? . checkForReaderUpdateInProgress ?? false
96+ var rows = [ Row] ( )
97+ if checkForReaderUpdateInProgress {
98+ rows = [ . checkingForUpdate]
99+ } else {
100+ rows = [ . updatePrompt]
110101 }
111102
103+ sections. append ( Section ( title: nil , rows: rows) )
104+
112105 /// This section displays details about the connected reader
113106 ///
114- var rows : [ Row ] = [ . connectedReader]
115-
116- if shouldShowUpdateControls ( ) {
117- rows. append ( . updateButton)
118- }
119-
120- rows. append ( . disconnectButton)
121-
122107 sections. append (
123108 Section ( title: Localization . sectionHeaderTitle. uppercased ( ) ,
124- rows: rows
109+ rows: [
110+ . connectedReader,
111+ . updateButton,
112+ . disconnectButton
113+ ]
125114 )
126115 )
127116 }
@@ -178,6 +167,8 @@ private extension CardReaderSettingsConnectedViewController {
178167 ///
179168 func configure( _ cell: UITableViewCell , for row: Row , at indexPath: IndexPath ) {
180169 switch cell {
170+ case let cell as ActivitySpinnerAndLabelTableViewCell where row == . checkingForUpdate:
171+ configureCheckingForUpdate ( cell: cell)
181172 case let cell as LeftImageTableViewCell where row == . updatePrompt:
182173 configureUpdatePrompt ( cell: cell)
183174 case let cell as ConnectedReaderTableViewCell where row == . connectedReader:
@@ -191,11 +182,29 @@ private extension CardReaderSettingsConnectedViewController {
191182 }
192183 }
193184
185+ private func configureCheckingForUpdate( cell: ActivitySpinnerAndLabelTableViewCell ) {
186+ cell. configure ( labelText: Localization . updateChecking)
187+ cell. selectionStyle = . none
188+ }
189+
194190 private func configureUpdatePrompt( cell: LeftImageTableViewCell ) {
195- cell. configure ( image: . infoOutlineImage, text: Localization . updatePromptText)
191+ guard let readerUpdateAvailable = viewModel? . readerUpdateAvailable else {
192+ return
193+ }
194+
195+ if readerUpdateAvailable == . isFalse {
196+ cell. configure ( image: . infoOutlineImage, text: Localization . updateNotNeeded)
197+ cell. backgroundColor = . none
198+ cell. imageView? . tintColor = . info
199+ }
200+
201+ if readerUpdateAvailable == . isTrue {
202+ cell. configure ( image: . infoOutlineImage, text: Localization . updateAvailable)
203+ cell. backgroundColor = . warningBackground
204+ cell. imageView? . tintColor = . warning
205+ }
206+
196207 cell. selectionStyle = . none
197- cell. backgroundColor = . warningBackground
198- cell. imageView? . tintColor = . warning
199208 cell. textLabel? . numberOfLines = 0
200209 cell. textLabel? . textColor = . text
201210 }
@@ -210,29 +219,39 @@ private extension CardReaderSettingsConnectedViewController {
210219 cell. selectionStyle = . none
211220 }
212221
222+ /// If a reader update is available, make the update button primary
223+ /// If a reader update is available and a disconnect or update isn't already in progress, enable the button
224+ ///
213225 private func configureUpdateButton( cell: ButtonTableViewCell ) {
214- cell. configure ( style: . primary, title: Localization . updateButtonTitle, bottomSpacing: 0 ) {
226+ let readerUpdateAvailable = viewModel? . readerUpdateAvailable == . isTrue
227+ let style : ButtonTableViewCell . Style = readerUpdateAvailable ? . primary : . secondary
228+ cell. configure ( style: style, title: Localization . updateButtonTitle, bottomSpacing: 0 ) {
215229 self . viewModel? . startCardReaderUpdate ( )
216230 }
217231
218232 let readerDisconnectInProgress = viewModel? . readerDisconnectInProgress ?? false
219233 let readerUpdateInProgress = viewModel? . readerUpdateInProgress ?? false
220- cell. enableButton ( !readerDisconnectInProgress && !readerUpdateInProgress)
234+ cell. enableButton ( readerUpdateAvailable && !readerDisconnectInProgress && !readerUpdateInProgress)
221235 cell. showActivityIndicator ( readerUpdateInProgress)
222236
223237 cell. selectionStyle = . none
224238 cell. backgroundColor = . clear
225239 }
226240
241+ /// If a reader update is not available, make the disconnect button primary
242+ /// If a check for updates, a disconnect or an update isn't already in progress, enable the disconnect button
243+ ///
227244 private func configureDisconnectButton( cell: ButtonTableViewCell ) {
228- let style : ButtonTableViewCell . Style = shouldShowUpdateControls ( ) ? . secondary : . primary
245+ let checkForReaderUpdateInProgress = viewModel? . checkForReaderUpdateInProgress ?? false
246+ let readerUpdateAvailable = viewModel? . readerUpdateAvailable == . isTrue
247+ let style : ButtonTableViewCell . Style = readerUpdateAvailable ? . secondary : . primary
229248 cell. configure ( style: style, title: Localization . disconnectButtonTitle) { [ weak self] in
230249 self ? . viewModel? . disconnectReader ( )
231250 }
232251
233252 let readerDisconnectInProgress = viewModel? . readerDisconnectInProgress ?? false
234253 let readerUpdateInProgress = viewModel? . readerUpdateInProgress ?? false
235- cell. enableButton ( !readerDisconnectInProgress && !readerUpdateInProgress)
254+ cell. enableButton ( !checkForReaderUpdateInProgress && ! readerDisconnectInProgress && !readerUpdateInProgress)
236255 cell. showActivityIndicator ( readerDisconnectInProgress)
237256
238257 cell. selectionStyle = . none
@@ -262,10 +281,7 @@ extension CardReaderSettingsConnectedViewController: UITableViewDataSource {
262281 }
263282
264283 func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
265- if shouldShowUpdateControls ( ) {
266- return section == 0 ? CGFloat . leastNonzeroMagnitude : UITableView . automaticDimension
267- }
268- return UITableView . automaticDimension
284+ return section == 0 ? CGFloat . leastNonzeroMagnitude : UITableView . automaticDimension
269285 }
270286
271287 func tableView( _ tableView: UITableView , heightForFooterInSection section: Int ) -> CGFloat {
@@ -317,13 +333,16 @@ private struct Section {
317333}
318334
319335private enum Row : CaseIterable {
336+ case checkingForUpdate
320337 case updatePrompt
321338 case connectedReader
322339 case updateButton
323340 case disconnectButton
324341
325342 var type : UITableViewCell . Type {
326343 switch self {
344+ case . checkingForUpdate:
345+ return ActivitySpinnerAndLabelTableViewCell . self
327346 case . updatePrompt:
328347 return LeftImageTableViewCell . self
329348 case . connectedReader:
@@ -349,11 +368,21 @@ private extension CardReaderSettingsConnectedViewController {
349368 comment: " Settings > Manage Card Reader > Title for the reader connected screen in settings. "
350369 )
351370
352- static let updatePromptText = NSLocalizedString (
371+ static let updateChecking = NSLocalizedString (
372+ " Checking for reader software updates " ,
373+ comment: " Settings > Manage Card Reader > Connected Reader > A prompt to indicate we are checking for reader updates "
374+ )
375+
376+ static let updateAvailable = NSLocalizedString (
353377 " Please update your reader software to keep accepting payments " ,
354378 comment: " Settings > Manage Card Reader > Connected Reader > A prompt to update a reader running older software "
355379 )
356380
381+ static let updateNotNeeded = NSLocalizedString (
382+ " Congratulations! Your reader is running the latest software " ,
383+ comment: " Settings > Manage Card Reader > Connected Reader > A prompt to update a reader running older software "
384+ )
385+
357386 static let sectionHeaderTitle = NSLocalizedString (
358387 " Connected Reader " ,
359388 comment: " Settings > Manage Card Reader > Connected Reader Table Section Heading "
0 commit comments