@@ -416,50 +416,53 @@ extension SettingsView {
416
416
/*
417
417
DIY loop specific component to show users the amount of time remaining on their build before a rebuild is necessary.
418
418
*/
419
- private func profileExpirationSection ( profileExpiration: Date ) -> some View {
419
+ private func appExpirationSection ( profileExpiration: Date ) -> some View {
420
420
let expirationDate = AppExpirationAlerter . calculateExpirationDate ( profileExpiration: profileExpiration)
421
421
let isTestFlight = AppExpirationAlerter . isTestFlightBuild ( )
422
-
423
- let nearExpiration : Bool = AppExpirationAlerter . isNearExpiration ( expirationDate: expirationDate)
422
+ let nearExpiration = AppExpirationAlerter . isNearExpiration ( expirationDate: expirationDate)
424
423
let profileExpirationMsg = AppExpirationAlerter . createProfileExpirationSettingsMessage ( expirationDate: expirationDate)
425
424
let readableExpirationTime = Self . dateFormatter. string ( from: expirationDate)
426
425
427
426
if isTestFlight {
428
- return Section ( header: SectionHeader ( label: NSLocalizedString ( " TestFlight " , comment: " Settings app TestFlight section " ) ) ,
429
- footer: Text ( NSLocalizedString ( " TestFlight expires " , comment: " Time that build expires " ) + readableExpirationTime) ) {
430
- if ( nearExpiration) {
431
- Text ( profileExpirationMsg) . foregroundColor ( . red)
432
- } else {
433
- HStack {
434
- Text ( " TestFlight Expiration " , comment: " Settings TestFlight expiration view " )
435
- Spacer ( )
436
- Text ( profileExpirationMsg) . foregroundColor ( Color . secondary)
437
- }
438
- }
439
- Button ( action: {
440
- UIApplication . shared. open ( URL ( string: " https://loopkit.github.io/loopdocs/gh-actions/gh-update/ " ) !)
441
- } ) {
442
- Text ( NSLocalizedString ( " How to update (LoopDocs) " , comment: " The title text for how to update " ) )
443
- }
444
- }
427
+ return createAppExpirationSection (
428
+ headerLabel: NSLocalizedString ( " TestFlight " , comment: " Settings app TestFlight section " ) ,
429
+ footerLabel: NSLocalizedString ( " TestFlight expires " , comment: " Time that build expires " ) + readableExpirationTime,
430
+ expirationLabel: NSLocalizedString ( " TestFlight Expiration " , comment: " Settings TestFlight expiration view " ) ,
431
+ updateURL: " https://loopkit.github.io/loopdocs/gh-actions/gh-update/ " ,
432
+ nearExpiration: nearExpiration,
433
+ expirationMessage: profileExpirationMsg
434
+ )
445
435
} else {
446
- return Section ( header: SectionHeader ( label: NSLocalizedString ( " App Profile " , comment: " Settings app profile section " ) ) ,
447
- footer: Text ( NSLocalizedString ( " Profile expires " , comment: " Time that profile expires " ) + readableExpirationTime) ) {
448
- if ( nearExpiration) {
449
- Text ( profileExpirationMsg) . foregroundColor ( . red)
450
- } else {
451
- HStack {
452
- Text ( " Profile Expiration " , comment: " Settings App Profile expiration view " )
453
- Spacer ( )
454
- Text ( profileExpirationMsg) . foregroundColor ( Color . secondary)
455
- }
456
- }
457
- Button ( action: {
458
- UIApplication . shared. open ( URL ( string: " https://loopkit.github.io/loopdocs/build/updating/ " ) !)
459
- } ) {
460
- Text ( NSLocalizedString ( " How to update (LoopDocs) " , comment: " The title text for how to update " ) )
436
+ return createAppExpirationSection (
437
+ headerLabel: NSLocalizedString ( " App Profile " , comment: " Settings app profile section " ) ,
438
+ footerLabel: NSLocalizedString ( " Profile expires " , comment: " Time that profile expires " ) + readableExpirationTime,
439
+ expirationLabel: NSLocalizedString ( " Profile Expiration " , comment: " Settings App Profile expiration view " ) ,
440
+ updateURL: " https://loopkit.github.io/loopdocs/build/updating/ " ,
441
+ nearExpiration: nearExpiration,
442
+ expirationMessage: profileExpirationMsg
443
+ )
444
+ }
445
+ }
446
+
447
+ private func createAppExpirationSection( headerLabel: String , footerLabel: String , expirationLabel: String , updateURL: String , nearExpiration: Bool , expirationMessage: String ) -> some View {
448
+ return Section (
449
+ header: SectionHeader ( label: headerLabel) ,
450
+ footer: Text ( footerLabel)
451
+ ) {
452
+ if nearExpiration {
453
+ Text ( expirationMessage) . foregroundColor ( . red)
454
+ } else {
455
+ HStack {
456
+ Text ( expirationLabel)
457
+ Spacer ( )
458
+ Text ( expirationMessage) . foregroundColor ( Color . secondary)
461
459
}
462
460
}
461
+ Button ( action: {
462
+ UIApplication . shared. open ( URL ( string: updateURL) !)
463
+ } ) {
464
+ Text ( NSLocalizedString ( " How to update (LoopDocs) " , comment: " The title text for how to update " ) )
465
+ }
463
466
}
464
467
}
465
468
0 commit comments