Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion G7SensorKitUI/G7CGMManager/G7UICoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class G7UICoordinator: UINavigationController, CGMManagerOnboarding, CompletionN
// advertised; `.g7` when it did not announce one, matching what
// the pairing screen showed a moment ago.
let model = deviceName.flatMap(G7SensorModel.init(advertisedName:)) ?? .g7
let view = G7PairingSuccessView(model: model, deviceName: deviceName, hasNextStep: offersShare) { [weak self] in
let view = G7PairingSuccessView(model: model, deviceName: deviceName, hasNextStep: offersShare, warmup: G7PairingWarmupModel(cgmManager: cgmManager)) { [weak self] in
guard let self = self else { return }
if offersShare {
self.navigate(to: .shareSignIn)
Expand Down
7 changes: 5 additions & 2 deletions G7SensorKitUI/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,11 @@
"%1$@ connects to your G7, ONE+ or Stelo sensor directly. Pair it with the 4-digit code printed on the sensor applicator, and the Dexcom app is not needed." : {
"comment" : "Descriptive text on G7StartupView (1: appName)"
},
"%1$@ is now connected to the sensor directly. Readings arrive every 5 minutes; a new sensor needs about 30 minutes to warm up first." : {
"comment" : "Body of the pairing success screen (1: appName)"
"%1$@ is now connected to the sensor directly. Readings arrive every 5 minutes after a %2$@ warm-up." : {
"comment" : "Body of the pairing success screen (1: appName, 2: warm-up duration, e.g. 27 minutes)"
},
"%1$@ is now connected to the sensor directly. Readings arrive every 5 minutes once the sensor has warmed up." : {
"comment" : "Body of the pairing success screen before the sensor reports its warm-up time (1: appName)"
},
"%1$@ will read glucose from the Dexcom app's session until you pair a sensor. The Dexcom app must stay installed for this to work." : {
"comment" : "Explanation of eavesdropping mode on G7StartupView (1: appName)"
Expand Down
35 changes: 34 additions & 1 deletion G7SensorKitUI/Views/Onboarding/G7PairingSuccessView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,25 @@ struct G7PairingSuccessView: View {
var deviceName: String?
/// Whether setup continues after this page (Dexcom Share sign-in).
var hasNextStep = false
@ObservedObject var warmup: G7PairingWarmupModel
var didFinish: () -> Void

@Environment(\.appName) private var appName

private var bodyText: String {
guard let duration = warmup.duration, let formatted = Self.durationFormatter.string(from: duration) else {
return String(format: LocalizedString("%1$@ is now connected to the sensor directly. Readings arrive every 5 minutes once the sensor has warmed up.", comment: "Body of the pairing success screen before the sensor reports its warm-up time (1: appName)"), appName)
}
return String(format: LocalizedString("%1$@ is now connected to the sensor directly. Readings arrive every 5 minutes after a %2$@ warm-up.", comment: "Body of the pairing success screen (1: appName, 2: warm-up duration, e.g. 27 minutes)"), appName, formatted)
}

private static let durationFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute]
formatter.unitsStyle = .full
return formatter
}()

var body: some View {
// Laid out like the pairing screen this arrives from: the sensor
// centred at the top, the text from one left edge under it, and the
Expand All @@ -42,7 +57,7 @@ struct G7PairingSuccessView: View {
}
}

Text(String(format: LocalizedString("%1$@ is now connected to the sensor directly. Readings arrive every 5 minutes; a new sensor needs about 30 minutes to warm up first.", comment: "Body of the pairing success screen (1: appName)"), appName))
Text(bodyText)
.foregroundColor(.secondary)
.fixedSize(horizontal: false, vertical: true)

Expand All @@ -65,3 +80,21 @@ struct G7PairingSuccessView: View {
.navigationBarBackButtonHidden(true)
}
}

/// The warm-up the sensor reports, which arrives shortly after pairing.
final class G7PairingWarmupModel: ObservableObject, G7StateObserver {
@Published private(set) var duration: TimeInterval?

init(cgmManager: G7CGMManager?) {
duration = cgmManager?.state.extendedVersion?.warmupDuration
cgmManager?.addStateObserver(self, queue: .main)
}

func g7StateDidUpdate(_ state: G7CGMManagerState?) {
if let warmupDuration = state?.extendedVersion?.warmupDuration {
duration = warmupDuration
}
}

func g7ConnectionStatusDidChange() {}
}