Skip to content

Commit

Permalink
Bring back override end date on home view
Browse files Browse the repository at this point in the history
  • Loading branch information
gestrich committed Jan 31, 2024
1 parent 695bf25 commit d26192b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 7 additions & 1 deletion LoopCaregiver/LoopCaregiver/Views/Home/HUDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ struct HUDView: View {
}.onChange(of: hudViewModel.selectedLooper) { newValue in
looperPopoverShowing = false
}
if let activeOverride = nightscoutDataSource.activeOverride() {
if let (activeOverride, status) = nightscoutDataSource.activeOverrideAndStatus() {
HStack {
Text(activeOverride.presentableDescription())
.bold()
.font(.subheadline)
Spacer()
if let endTimeDescription = status.endTimeDescription() {
Text(endTimeDescription)
.foregroundColor(.gray)
.bold()
.font(.subheadline)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ public class RemoteDataServiceManager: ObservableObject, RemoteDataServiceProvid
return try await remoteDataProvider.fetchCurrentProfile()
}

public func activeOverride() -> NightscoutKit.TemporaryScheduleOverride? {

public func activeOverrideAndStatus() -> (override: NightscoutKit.TemporaryScheduleOverride, status: NightscoutKit.OverrideStatus)? {
/*
There are 3 sources of the current override from Nightscout
1. Devicestatus.overrideStatus: Used by NS Plugin (bubble view)
Expand Down Expand Up @@ -320,7 +319,11 @@ public class RemoteDataServiceManager: ObservableObject, RemoteDataServiceProvid
// }
// }

return override
return (override, overrideStatus)
}

public func activeOverride() -> NightscoutKit.TemporaryScheduleOverride? {
return activeOverrideAndStatus()?.override
}

public func fetchRecentCommands() async throws -> [RemoteCommand] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ public extension TemporaryScheduleOverride {
func presentableDescription() -> String {
return "\(symbol ?? "") \(name ?? "")"
}

func targetRangePresentableDescription() -> String? {
guard let targetRange else { return nil }
return "\(Int(targetRange.lowerBound)) - \(Int(targetRange.upperBound))"
}
}

public extension OverrideStatus {
func endTimeDescription() -> String? {
guard let duration, duration < 60 * 60 * 24 else { return nil }
let endDate = timestamp.addingTimeInterval(duration)
let endTimeText = DateFormatter.localizedString(from: endDate, dateStyle: .none, timeStyle: .short)
return String(format: NSLocalizedString("until %@", comment: "The format for the description of a custom preset end date"), endTimeText)
}
}

extension TemporaryScheduleOverride: Hashable {

public func hash(into hasher: inout Hasher) {
Expand Down

0 comments on commit d26192b

Please sign in to comment.