@@ -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,25 @@ 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- )
95+ sections. append (
96+ Section ( title: nil ,
97+ rows: [
98+ . updatePrompt
99+ ]
109100 )
110- }
101+ )
111102
112103 /// This section displays details about the connected reader
113104 ///
114- var rows : [ Row ] = [ . connectedReader]
115-
116- if shouldShowUpdateControls ( ) {
117- rows. append ( . updateButton)
118- }
119-
120- rows. append ( . disconnectButton)
121-
122105 sections. append (
123106 Section ( title: Localization . sectionHeaderTitle. uppercased ( ) ,
124- rows: rows
107+ rows: [
108+ . connectedReader,
109+ . updateButton,
110+ . disconnectButton
111+ ]
125112 )
126113 )
127114 }
@@ -192,10 +179,26 @@ private extension CardReaderSettingsConnectedViewController {
192179 }
193180
194181 private func configureUpdatePrompt( cell: LeftImageTableViewCell ) {
195- cell. configure ( image: . infoOutlineImage, text: Localization . updatePromptText)
182+ guard let readerUpdateAvailable = viewModel? . readerUpdateAvailable else {
183+ return
184+ }
185+
186+ switch readerUpdateAvailable {
187+ case . isUnknown:
188+ cell. configure ( image: . infoOutlineImage, text: Localization . updateChecking)
189+ cell. backgroundColor = . none
190+ cell. imageView? . tintColor = . warning
191+ case . isFalse:
192+ cell. configure ( image: . infoOutlineImage, text: Localization . updateNotNeeded)
193+ cell. backgroundColor = . none
194+ cell. imageView? . tintColor = . info
195+ case . isTrue:
196+ cell. configure ( image: . infoOutlineImage, text: Localization . updateAvailable)
197+ cell. backgroundColor = . warningBackground
198+ cell. imageView? . tintColor = . warning
199+ }
200+
196201 cell. selectionStyle = . none
197- cell. backgroundColor = . warningBackground
198- cell. imageView? . tintColor = . warning
199202 cell. textLabel? . numberOfLines = 0
200203 cell. textLabel? . textColor = . text
201204 }
@@ -210,29 +213,39 @@ private extension CardReaderSettingsConnectedViewController {
210213 cell. selectionStyle = . none
211214 }
212215
216+ /// If a reader update is available, make the update button primary
217+ /// If a reader update is available and a disconnect or update isn't already in progress, enable the button
218+ ///
213219 private func configureUpdateButton( cell: ButtonTableViewCell ) {
214- cell. configure ( style: . primary, title: Localization . updateButtonTitle, bottomSpacing: 0 ) {
220+ let readerUpdateAvailable = viewModel? . readerUpdateAvailable == . isTrue
221+ let style : ButtonTableViewCell . Style = readerUpdateAvailable ? . primary : . secondary
222+ cell. configure ( style: style, title: Localization . updateButtonTitle, bottomSpacing: 0 ) {
215223 self . viewModel? . startCardReaderUpdate ( )
216224 }
217225
218226 let readerDisconnectInProgress = viewModel? . readerDisconnectInProgress ?? false
219227 let readerUpdateInProgress = viewModel? . readerUpdateInProgress ?? false
220- cell. enableButton ( !readerDisconnectInProgress && !readerUpdateInProgress)
228+ cell. enableButton ( readerUpdateAvailable && !readerDisconnectInProgress && !readerUpdateInProgress)
221229 cell. showActivityIndicator ( readerUpdateInProgress)
222230
223231 cell. selectionStyle = . none
224232 cell. backgroundColor = . clear
225233 }
226234
235+ /// If a reader update is not available, make the disconnect button primary
236+ /// If a check for updates, a disconnect or an update isn't already in progress, enable the disconnect button
237+ ///
227238 private func configureDisconnectButton( cell: ButtonTableViewCell ) {
228- let style : ButtonTableViewCell . Style = shouldShowUpdateControls ( ) ? . secondary : . primary
239+ let checkForReaderUpdateInProgress = viewModel? . checkForReaderUpdateInProgress ?? false
240+ let readerUpdateAvailable = viewModel? . readerUpdateAvailable == . isTrue
241+ let style : ButtonTableViewCell . Style = readerUpdateAvailable ? . secondary : . primary
229242 cell. configure ( style: style, title: Localization . disconnectButtonTitle) { [ weak self] in
230243 self ? . viewModel? . disconnectReader ( )
231244 }
232245
233246 let readerDisconnectInProgress = viewModel? . readerDisconnectInProgress ?? false
234247 let readerUpdateInProgress = viewModel? . readerUpdateInProgress ?? false
235- cell. enableButton ( !readerDisconnectInProgress && !readerUpdateInProgress)
248+ cell. enableButton ( !checkForReaderUpdateInProgress && ! readerDisconnectInProgress && !readerUpdateInProgress)
236249 cell. showActivityIndicator ( readerDisconnectInProgress)
237250
238251 cell. selectionStyle = . none
@@ -262,10 +275,7 @@ extension CardReaderSettingsConnectedViewController: UITableViewDataSource {
262275 }
263276
264277 func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
265- if shouldShowUpdateControls ( ) {
266- return section == 0 ? CGFloat . leastNonzeroMagnitude : UITableView . automaticDimension
267- }
268- return UITableView . automaticDimension
278+ return section == 0 ? CGFloat . leastNonzeroMagnitude : UITableView . automaticDimension
269279 }
270280
271281 func tableView( _ tableView: UITableView , heightForFooterInSection section: Int ) -> CGFloat {
@@ -349,11 +359,21 @@ private extension CardReaderSettingsConnectedViewController {
349359 comment: " Settings > Manage Card Reader > Title for the reader connected screen in settings. "
350360 )
351361
352- static let updatePromptText = NSLocalizedString (
362+ static let updateChecking = NSLocalizedString (
363+ " Checking for reader software updates " ,
364+ comment: " Settings > Manage Card Reader > Connected Reader > A prompt to indicate we are checking for reader updates "
365+ )
366+
367+ static let updateAvailable = NSLocalizedString (
353368 " Please update your reader software to keep accepting payments " ,
354369 comment: " Settings > Manage Card Reader > Connected Reader > A prompt to update a reader running older software "
355370 )
356371
372+ static let updateNotNeeded = NSLocalizedString (
373+ " Congratulations! Your reader is running the latest software " ,
374+ comment: " Settings > Manage Card Reader > Connected Reader > A prompt to update a reader running older software "
375+ )
376+
357377 static let sectionHeaderTitle = NSLocalizedString (
358378 " Connected Reader " ,
359379 comment: " Settings > Manage Card Reader > Connected Reader Table Section Heading "
0 commit comments