From 4d538cd19cd3148e977140a7627e0ed5f187dec3 Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Sun, 4 Aug 2024 14:52:34 -0600 Subject: [PATCH 1/8] Half Unit on Cannula Insertion public static let cannulaInsertionUnitsExtra = 0.5 // edit to add a fixed additional amount of insulin during cannula insertion --- OmniBLE/OmnipodCommon/Pod.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OmniBLE/OmnipodCommon/Pod.swift b/OmniBLE/OmnipodCommon/Pod.swift index d0daef2e..513a11c6 100644 --- a/OmniBLE/OmnipodCommon/Pod.swift +++ b/OmniBLE/OmnipodCommon/Pod.swift @@ -79,7 +79,7 @@ public struct Pod { // Checked to verify it agrees with value returned by pod during the pairing process. public static let cannulaInsertionUnits = 0.5 - public static let cannulaInsertionUnitsExtra = 0.0 // edit to add a fixed additional amount of insulin during cannula insertion + public static let cannulaInsertionUnitsExtra = 0.5 // edit to add a fixed additional amount of insulin during cannula insertion // Default and limits for expiration reminder alerts public static let defaultExpirationReminderOffset = TimeInterval(hours: 2) From ef6c8013ed87cf64c111161df7a5192597b02553 Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Sun, 4 Aug 2024 15:17:10 -0600 Subject: [PATCH 2/8] Timer Enhancements --- OmniBLE/PumpManager/OmniBLEPumpManager.swift | 1 + .../ViewModels/OmniBLESettingsViewModel.swift | 85 ++++++++++++++++--- .../Views/OmniBLESettingsView.swift | 33 ++++++- 3 files changed, 103 insertions(+), 16 deletions(-) diff --git a/OmniBLE/PumpManager/OmniBLEPumpManager.swift b/OmniBLE/PumpManager/OmniBLEPumpManager.swift index afea8dc1..27288eba 100644 --- a/OmniBLE/PumpManager/OmniBLEPumpManager.swift +++ b/OmniBLE/PumpManager/OmniBLEPumpManager.swift @@ -489,6 +489,7 @@ extension OmniBLEPumpManager { // If time remaining is negative, the pod has been expired for that amount of time. public var podTimeRemaining: TimeInterval? { guard let expiresAt = state.podState?.expiresAt else { return nil } + // return -32000 // for testing expired pods return expiresAt.timeIntervalSince(dateGenerator()) } diff --git a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift index 8aca8d42..a7a32922 100644 --- a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift +++ b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift @@ -46,23 +46,46 @@ class OmniBLESettingsViewModel: ObservableObject { var activatedAtString: String { if let activatedAt = activatedAt { - return dateFormatter.string(from: activatedAt) + print("ptm: relDateAndTimeFormatter :" + relDateAndTimeFormatter.string(from: activatedAt)) + if relDateFormatter.string(from: activatedAt) == absDateFormatter.string(from: activatedAt) { + return altRelFormatter.string(from: activatedAt) + } + return relDateAndTimeFormatter.string(from: activatedAt) + } else { + return "—" + } + } + + var expiresAtString: String { + if let expiresAt = expiresAt { + if relDateFormatter.string(from: expiresAt) == absDateFormatter.string(from: expiresAt) { + return altRelFormatter.string(from: expiresAt) + } + return relDateAndTimeFormatter.string(from: expiresAt) } else { return "—" } } - - var expiresAtString: String { - if let expiresAt = expiresAt { - return dateFormatter.string(from: expiresAt) + + var deliveryStopsAtString: String { + if let serviceTimeRemaining = pumpManager.podServiceTimeRemaining { + let deliveryStopsAt = Date().addingTimeInterval(serviceTimeRemaining) + if relDateFormatter.string(from: deliveryStopsAt) == absDateFormatter.string(from: deliveryStopsAt) { + return altRelFormatter.string(from: deliveryStopsAt) + } + return relDateAndTimeFormatter.string(from: deliveryStopsAt) } else { return "—" } } var serviceTimeRemainingString: String? { - if let serviceTimeRemaining = pumpManager.podServiceTimeRemaining, let serviceTimeRemainingString = timeRemainingFormatter.string(from: serviceTimeRemaining) { - return serviceTimeRemainingString + if let serviceTimeRemaining = pumpManager.podServiceTimeRemaining { + timeRemainingFormatter.allowedUnits = [.day, .hour, .minute, .second] + timeRemainingFormatter.maximumUnitCount = 2 + if let serviceTimeRemainingString = timeRemainingFormatter.string(from: serviceTimeRemaining) { + return serviceTimeRemainingString + } } else { return nil } @@ -151,7 +174,12 @@ class OmniBLESettingsViewModel: ObservableObject { return nil } } - + var podServiceTimeRemainingString: String { + if let serviceTimeRemainingString = serviceTimeRemainingString { + return serviceTimeRemainingString + } + return "-" + } var notice: DashSettingsNotice? { if pumpManager.isClockOffset { return DashSettingsNotice( @@ -170,19 +198,52 @@ class OmniBLESettingsViewModel: ObservableObject { return false } } - + let timeFormatter: DateFormatter = { + let dateFormatter = DateFormatter() + dateFormatter.timeStyle = .short + dateFormatter.dateStyle = .none + return dateFormatter + }() + let dateFormatter: DateFormatter = { let dateFormatter = DateFormatter() dateFormatter.timeStyle = .short dateFormatter.dateStyle = .medium + dateFormatter.locale = Locale.current dateFormatter.doesRelativeDateFormatting = true return dateFormatter }() - let timeFormatter: DateFormatter = { + let relDateFormatter: DateFormatter = { + let dateFormatter = DateFormatter() + dateFormatter.timeStyle = .none + dateFormatter.dateStyle = .medium + dateFormatter.locale = Locale.current + dateFormatter.doesRelativeDateFormatting = true + return dateFormatter + }() + let absDateFormatter: DateFormatter = { + let dateFormatter = DateFormatter() + dateFormatter.timeStyle = .none + dateFormatter.dateStyle = .medium + dateFormatter.locale = Locale.current + dateFormatter.doesRelativeDateFormatting = false + return dateFormatter + }() + + let altRelFormatter: DateFormatter = { + let fullDF = DateFormatter() + fullDF.locale = Locale.current + fullDF.setLocalizedDateFormatFromTemplate("E, hh:mm a") + return fullDF + }() + + let relDateAndTimeFormatter: DateFormatter = { let dateFormatter = DateFormatter() dateFormatter.timeStyle = .short - dateFormatter.dateStyle = .none + dateFormatter.dateStyle = .medium + dateFormatter.locale = Locale.current + dateFormatter.doesRelativeDateFormatting = true return dateFormatter }() @@ -566,7 +627,7 @@ extension OmniBLEPumpManager { guard let podTimeRemaining = podTimeRemaining else { return nil; } - return max(0, Pod.serviceDuration - Pod.nominalPodLife + podTimeRemaining); + return Pod.serviceDuration - Pod.nominalPodLife + podTimeRemaining; } private func podDetails(fromPodState podState: PodState, andDeviceName deviceName: String?) -> PodDetails { diff --git a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift index 364a322a..7d32c266 100644 --- a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift +++ b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift @@ -47,7 +47,7 @@ struct OmniBLESettingsView: View { } private var minutesRemaining: Int? { - if case .timeRemaining(let remaining, _) = viewModel.lifeState, remaining < .hours(2) { + if case .timeRemaining(let remaining, _) = viewModel.lifeState, remaining < .days(1) { return Int(remaining.minutes.truncatingRemainder(dividingBy: 60)) } return nil @@ -358,14 +358,39 @@ struct OmniBLESettingsView: View { HStack { if let expiresAt = viewModel.expiresAt, expiresAt < Date() { FrameworkLocalText("Pod Expired", comment: "Label for pod expiration row, past tense") + Spacer() + Text(self.viewModel.expiresAtString) + .foregroundColor(Color.red) } else { FrameworkLocalText("Pod Expires", comment: "Label for pod expiration row") + Spacer() + Text(self.viewModel.expiresAtString) + .foregroundColor(Color.secondary) } - Spacer() - Text(self.viewModel.expiresAtString) - .foregroundColor(Color.secondary) } + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < Pod.serviceDuration - Pod.nominalPodLife { + HStack { + FrameworkLocalText("Delivery Stoppage Timer", comment: "Label for insulin delivery stoppage timer row") + Spacer() + Text(self.viewModel.podServiceTimeRemainingString) + .foregroundColor(Color.red) + } + } + + HStack { + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < 0 { + FrameworkLocalText("Insulin Delivery Stopped", comment: "Label for insulin delivery stop time row, past tense") + Spacer() + Text(self.viewModel.deliveryStopsAtString) + .foregroundColor(Color.red) + } else { + FrameworkLocalText("Insulin Delivery Stops", comment: "Label for insulin delivery stop time row") + Spacer() + Text(self.viewModel.deliveryStopsAtString) + .foregroundColor(Color.secondary) + } + } if let podDetails = self.viewModel.podDetails { NavigationLink(destination: PodDetailsView(podDetails: podDetails, title: LocalizedString("Pod Details", comment: "title for pod details page"))) { FrameworkLocalText("Pod Details", comment: "Text for pod details disclosure row") From ea6c0ad70b9d6b49d3de6db3075eaf450527e46b Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Mon, 5 Aug 2024 14:28:13 -0600 Subject: [PATCH 3/8] Fix missing timer function --- .../ViewModels/OmniBLESettingsViewModel.swift | 12 ++++++++--- .../Views/OmniBLESettingsView.swift | 21 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift index a7a32922..656d0a13 100644 --- a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift +++ b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift @@ -78,7 +78,14 @@ class OmniBLESettingsViewModel: ObservableObject { return "—" } } - + + var serviceTimeRemainingTI: TimeInterval { + if let serviceTimeRemaining = pumpManager.podServiceTimeRemaining { + return serviceTimeRemaining + } + return 0 + } + var serviceTimeRemainingString: String? { if let serviceTimeRemaining = pumpManager.podServiceTimeRemaining { timeRemainingFormatter.allowedUnits = [.day, .hour, .minute, .second] @@ -86,9 +93,8 @@ class OmniBLESettingsViewModel: ObservableObject { if let serviceTimeRemainingString = timeRemainingFormatter.string(from: serviceTimeRemaining) { return serviceTimeRemainingString } - } else { - return nil } + return nil } // Expiration reminder date for current pod diff --git a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift index 7d32c266..47ac6880 100644 --- a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift +++ b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift @@ -355,19 +355,22 @@ struct OmniBLESettingsView: View { .foregroundColor(Color.secondary) } - HStack { - if let expiresAt = viewModel.expiresAt, expiresAt < Date() { + if let expiresAt = viewModel.expiresAt, expiresAt < Date() { + HStack { FrameworkLocalText("Pod Expired", comment: "Label for pod expiration row, past tense") Spacer() Text(self.viewModel.expiresAtString) .foregroundColor(Color.red) - } else { + } + } else { + HStack { FrameworkLocalText("Pod Expires", comment: "Label for pod expiration row") Spacer() Text(self.viewModel.expiresAtString) .foregroundColor(Color.secondary) } } + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < Pod.serviceDuration - Pod.nominalPodLife { HStack { FrameworkLocalText("Delivery Stoppage Timer", comment: "Label for insulin delivery stoppage timer row") @@ -375,22 +378,24 @@ struct OmniBLESettingsView: View { Text(self.viewModel.podServiceTimeRemainingString) .foregroundColor(Color.red) } - } - + } - HStack { - if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < 0 { + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < 0 { + HStack { FrameworkLocalText("Insulin Delivery Stopped", comment: "Label for insulin delivery stop time row, past tense") Spacer() Text(self.viewModel.deliveryStopsAtString) .foregroundColor(Color.red) - } else { + } + } else { + HStack { FrameworkLocalText("Insulin Delivery Stops", comment: "Label for insulin delivery stop time row") Spacer() Text(self.viewModel.deliveryStopsAtString) .foregroundColor(Color.secondary) } } + if let podDetails = self.viewModel.podDetails { NavigationLink(destination: PodDetailsView(podDetails: podDetails, title: LocalizedString("Pod Details", comment: "title for pod details page"))) { FrameworkLocalText("Pod Details", comment: "Text for pod details disclosure row") From 4572b2914e45718bd1ba9fdfcec7838e53c1114c Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Fri, 30 Aug 2024 12:20:21 -0600 Subject: [PATCH 4/8] Row Label Update Insulin Deliver Stops > Insulin Stops --- OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift index 47ac6880..e64dcafa 100644 --- a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift +++ b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift @@ -389,7 +389,7 @@ struct OmniBLESettingsView: View { } } else { HStack { - FrameworkLocalText("Insulin Delivery Stops", comment: "Label for insulin delivery stop time row") + FrameworkLocalText("Insulin Stops", comment: "Label for insulin delivery stop time row") Spacer() Text(self.viewModel.deliveryStopsAtString) .foregroundColor(Color.secondary) From cde0ae665adebc28f16a42f18ecd12f9fe199381 Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Mon, 2 Sep 2024 12:52:34 -0600 Subject: [PATCH 5/8] Revert "Half Unit on Cannula Insertion" This reverts commit 4d538cd19cd3148e977140a7627e0ed5f187dec3. --- OmniBLE/OmnipodCommon/Pod.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OmniBLE/OmnipodCommon/Pod.swift b/OmniBLE/OmnipodCommon/Pod.swift index 513a11c6..d0daef2e 100644 --- a/OmniBLE/OmnipodCommon/Pod.swift +++ b/OmniBLE/OmnipodCommon/Pod.swift @@ -79,7 +79,7 @@ public struct Pod { // Checked to verify it agrees with value returned by pod during the pairing process. public static let cannulaInsertionUnits = 0.5 - public static let cannulaInsertionUnitsExtra = 0.5 // edit to add a fixed additional amount of insulin during cannula insertion + public static let cannulaInsertionUnitsExtra = 0.0 // edit to add a fixed additional amount of insulin during cannula insertion // Default and limits for expiration reminder alerts public static let defaultExpirationReminderOffset = TimeInterval(hours: 2) From 10386d01b5632a39e19f77ce18b1d8c51a46fef6 Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Mon, 2 Sep 2024 12:56:53 -0600 Subject: [PATCH 6/8] Remove debug output Remove debug output --- OmniBLE/PumpManager/OmniBLEPumpManager.swift | 1 - OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/OmniBLE/PumpManager/OmniBLEPumpManager.swift b/OmniBLE/PumpManager/OmniBLEPumpManager.swift index 27288eba..afea8dc1 100644 --- a/OmniBLE/PumpManager/OmniBLEPumpManager.swift +++ b/OmniBLE/PumpManager/OmniBLEPumpManager.swift @@ -489,7 +489,6 @@ extension OmniBLEPumpManager { // If time remaining is negative, the pod has been expired for that amount of time. public var podTimeRemaining: TimeInterval? { guard let expiresAt = state.podState?.expiresAt else { return nil } - // return -32000 // for testing expired pods return expiresAt.timeIntervalSince(dateGenerator()) } diff --git a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift index 656d0a13..57fe38f2 100644 --- a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift +++ b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift @@ -46,7 +46,6 @@ class OmniBLESettingsViewModel: ObservableObject { var activatedAtString: String { if let activatedAt = activatedAt { - print("ptm: relDateAndTimeFormatter :" + relDateAndTimeFormatter.string(from: activatedAt)) if relDateFormatter.string(from: activatedAt) == absDateFormatter.string(from: activatedAt) { return altRelFormatter.string(from: activatedAt) } From 6dff3523cdec5775cca222e236e342bbb567229b Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Sat, 7 Sep 2024 12:15:26 -0600 Subject: [PATCH 7/8] Don't display delivery stoppage timer after 80 hours Don't display delivery stoppage timer after 80 hours --- OmniBLE/PumpManager/OmniBLEPumpManager.swift | 3 +++ OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/OmniBLE/PumpManager/OmniBLEPumpManager.swift b/OmniBLE/PumpManager/OmniBLEPumpManager.swift index afea8dc1..cc869780 100644 --- a/OmniBLE/PumpManager/OmniBLEPumpManager.swift +++ b/OmniBLE/PumpManager/OmniBLEPumpManager.swift @@ -784,6 +784,9 @@ extension OmniBLEPumpManager { #if targetEnvironment(simulator) private func jumpStartPod(lotNo: UInt32, lotSeq: UInt32, fault: DetailedStatus? = nil, startDate: Date? = nil, mockFault: Bool) { let start = startDate ?? Date() + //let start = startDate ?? Date.init(timeIntervalSinceNow: -(73 * 60 * 60) + 134) // Expired Pod within 8 hour grace period + //let start = startDate ?? Date.init(timeIntervalSinceNow: -(80 * 60 * 60) - 154) // Expired Pod beyond 8 hour grace period + //let start = startDate ?? Date.init(timeIntervalSinceNow: -(37 * 60 * 60) - 134) // Active Pod within 72 hour expiration let fakeLtk = Data(hexadecimalString: "fedcba98765432100123456789abcdef")! var podState = PodState(address: state.podId, ltk: fakeLtk, firmwareVersion: "jumpstarted", bleFirmwareVersion: "jumpstarted", diff --git a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift index e64dcafa..5299d5c9 100644 --- a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift +++ b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift @@ -371,7 +371,7 @@ struct OmniBLESettingsView: View { } } - if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < Pod.serviceDuration - Pod.nominalPodLife { + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < Pod.serviceDuration - Pod.nominalPodLife, serviceTimeRemainingTI > 0 { HStack { FrameworkLocalText("Delivery Stoppage Timer", comment: "Label for insulin delivery stoppage timer row") Spacer() From 2393320048fc957630b6d8d8dcf712ad2660735c Mon Sep 17 00:00:00 2001 From: IsThisPaul Date: Sat, 7 Sep 2024 20:31:30 -0600 Subject: [PATCH 8/8] NewTime Format & Layout Dedicated Insulin Expiration Time Format Function & cleaned up layout of insulin expiration rows in all states --- OmniBLE/PumpManager/OmniBLEPumpManager.swift | 9 ++-- .../ViewModels/OmniBLESettingsViewModel.swift | 48 ++++++++++++++++++- .../Views/OmniBLESettingsView.swift | 38 +++++++++++---- 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/OmniBLE/PumpManager/OmniBLEPumpManager.swift b/OmniBLE/PumpManager/OmniBLEPumpManager.swift index cc869780..90e02e82 100644 --- a/OmniBLE/PumpManager/OmniBLEPumpManager.swift +++ b/OmniBLE/PumpManager/OmniBLEPumpManager.swift @@ -784,9 +784,6 @@ extension OmniBLEPumpManager { #if targetEnvironment(simulator) private func jumpStartPod(lotNo: UInt32, lotSeq: UInt32, fault: DetailedStatus? = nil, startDate: Date? = nil, mockFault: Bool) { let start = startDate ?? Date() - //let start = startDate ?? Date.init(timeIntervalSinceNow: -(73 * 60 * 60) + 134) // Expired Pod within 8 hour grace period - //let start = startDate ?? Date.init(timeIntervalSinceNow: -(80 * 60 * 60) - 154) // Expired Pod beyond 8 hour grace period - //let start = startDate ?? Date.init(timeIntervalSinceNow: -(37 * 60 * 60) - 134) // Active Pod within 72 hour expiration let fakeLtk = Data(hexadecimalString: "fedcba98765432100123456789abcdef")! var podState = PodState(address: state.podId, ltk: fakeLtk, firmwareVersion: "jumpstarted", bleFirmwareVersion: "jumpstarted", @@ -833,8 +830,12 @@ extension OmniBLEPumpManager { // If we're in the simulator, create a mock PodState let mockFaultDuringPairing = false let mockCommsErrorDuringPairing = false + let mockStartDate = Date() + //let mockStartDate = Date.init(timeIntervalSinceNow: -(37 * 60 * 60) - 134) // Active Pod within 72 hour expiration : 37 hours, 2 mins, 14 secs + //let mockStartDate = Date.init(timeIntervalSinceNow: -(74 * 60 * 60) - 134) // Expired Pod within 8 hour grace period : 74 hours, 2 mins, 14 secs + //let mockStartDate = Date.init(timeIntervalSinceNow: -(80 * 60 * 60) - 134) // Expired Pod beyond 8 hour grace period : 80 hours, 2 mins, 14 secs DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + .seconds(2)) { - self.jumpStartPod(lotNo: 135601809, lotSeq: 0800525, mockFault: mockFaultDuringPairing) + self.jumpStartPod(lotNo: 135601809, lotSeq: 0800525, startDate: mockStartDate, mockFault: mockFaultDuringPairing) let fault: DetailedStatus? = self.setStateWithResult({ (state) in var podState = state.podState podState?.setupProgress = .priming diff --git a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift index 57fe38f2..66287580 100644 --- a/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift +++ b/OmniBLE/PumpManagerUI/ViewModels/OmniBLESettingsViewModel.swift @@ -87,14 +87,29 @@ class OmniBLESettingsViewModel: ObservableObject { var serviceTimeRemainingString: String? { if let serviceTimeRemaining = pumpManager.podServiceTimeRemaining { - timeRemainingFormatter.allowedUnits = [.day, .hour, .minute, .second] - timeRemainingFormatter.maximumUnitCount = 2 if let serviceTimeRemainingString = timeRemainingFormatter.string(from: serviceTimeRemaining) { return serviceTimeRemainingString } } return nil } + + var insulinTimeRemainingString: String? { + if let insulinTimeRemaining = pumpManager.podServiceTimeRemaining { + let insulinTimeRemainingString = insulinTimeRemainingFormatter.string(from: insulinTimeRemaining) + return insulinTimeRemainingString + + } + return nil + } + var insulinTimeExpiredString: String? { + if let insulinTimeExpired = pumpManager.podServiceTimeRemaining { + let insulinTimeExpiredString = insulinTimeExpiredFormatter.localizedString(fromTimeInterval: insulinTimeExpired) + return insulinTimeExpiredString + + } + return nil + } // Expiration reminder date for current pod @Published var expirationReminderDate: Date? @@ -185,6 +200,18 @@ class OmniBLESettingsViewModel: ObservableObject { } return "-" } + var insulinServiceTimeRemainingString: String { + if let insulinTimeRemainingString = insulinTimeRemainingString { + return insulinTimeRemainingString + } + return "-" + } + var insulinServiceTimeExpiredString: String { + if let insulinTimeExpiredString = insulinTimeExpiredString { + return insulinTimeExpiredString + } + return "-" + } var notice: DashSettingsNotice? { if pumpManager.isClockOffset { return DashSettingsNotice( @@ -260,6 +287,23 @@ class OmniBLESettingsViewModel: ObservableObject { return dateComponentsFormatter }() + let insulinTimeRemainingFormatter: DateComponentsFormatter = { + let dateComponentsFormatter = DateComponentsFormatter() + dateComponentsFormatter.allowedUnits = [.day, .hour, .minute, .second] + dateComponentsFormatter.maximumUnitCount = 2 + dateComponentsFormatter.unitsStyle = .short + dateComponentsFormatter.zeroFormattingBehavior = .dropAll + return dateComponentsFormatter + }() + + let insulinTimeExpiredFormatter: RelativeDateTimeFormatter = { + let dateComponentsFormatter = RelativeDateTimeFormatter() + dateComponentsFormatter.locale = Locale.current + dateComponentsFormatter.unitsStyle = .short + dateComponentsFormatter.dateTimeStyle = .numeric + return dateComponentsFormatter + }() + let basalRateFormatter: NumberFormatter = { let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .decimal diff --git a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift index 5299d5c9..33fd3c52 100644 --- a/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift +++ b/OmniBLE/PumpManagerUI/Views/OmniBLESettingsView.swift @@ -371,6 +371,7 @@ struct OmniBLESettingsView: View { } } + /* if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < Pod.serviceDuration - Pod.nominalPodLife, serviceTimeRemainingTI > 0 { HStack { FrameworkLocalText("Delivery Stoppage Timer", comment: "Label for insulin delivery stoppage timer row") @@ -379,20 +380,41 @@ struct OmniBLESettingsView: View { .foregroundColor(Color.red) } } + */ - if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < 0 { - HStack { + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI <= 0 { + HStack (alignment: .firstTextBaseline){ FrameworkLocalText("Insulin Delivery Stopped", comment: "Label for insulin delivery stop time row, past tense") Spacer() - Text(self.viewModel.deliveryStopsAtString) - .foregroundColor(Color.red) + VStack(alignment: .trailing) { + Text(self.viewModel.deliveryStopsAtString) + .foregroundColor(Color.red) + .frame(alignment: .trailing) + Text(self.viewModel.insulinServiceTimeExpiredString) + .foregroundColor(Color.red) + .frame(alignment: .trailing) + } + .layoutPriority(1) } } else { - HStack { - FrameworkLocalText("Insulin Stops", comment: "Label for insulin delivery stop time row") + HStack(alignment: .firstTextBaseline) { + FrameworkLocalText("Insulin Delivery Stops", comment: "Label for insulin delivery stop time row") Spacer() - Text(self.viewModel.deliveryStopsAtString) - .foregroundColor(Color.secondary) + VStack(alignment: .trailing) { + if let serviceTimeRemainingTI = Optional(viewModel.serviceTimeRemainingTI), serviceTimeRemainingTI < Pod.serviceDuration - Pod.nominalPodLife { + Text(self.viewModel.deliveryStopsAtString) + .foregroundColor(Color.red) + .frame(alignment: .trailing) + Text(self.viewModel.insulinServiceTimeRemainingString) + .foregroundColor(Color.red) + .frame(alignment: .trailing) + } else { + Text(self.viewModel.deliveryStopsAtString) + .foregroundColor(Color.secondary) + .frame(alignment: .trailing) + } + } + .layoutPriority(1) } }