diff --git a/LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift b/LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift index 735c42e0..05f93855 100644 --- a/LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift +++ b/LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift @@ -19,6 +19,8 @@ struct HomeView: View { @ObservedObject var looperService: LooperService @Environment(\.scenePhase) var scenePhase + var homeViewTextMultiplier = 1.20 + init(connectivityManager: WatchService, looperService: LooperService){ self.connectivityManager = connectivityManager self.looperService = looperService @@ -28,28 +30,33 @@ struct HomeView: View { } var body: some View { - VStack { - HStack { - Text(remoteDataSource.currentGlucoseSample?.presentableStringValue(displayUnits: settings.glucoseDisplayUnits) ?? " ") + HStack (spacing: 10) { + VStack { + //BG number + Text(remoteDataSource.currentGlucoseSample?.presentableStringValue(displayUnits: settings.glucoseDisplayUnits) ?? "??") .strikethrough(egvIsOutdated()) - .font(.largeTitle) + .font(.system(size: 60.0 * homeViewTextMultiplier)) .foregroundColor(egvValueColor()) - if let egv = remoteDataSource.currentGlucoseSample { - Image(systemName: egv.arrowImageName()) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 15.0) - .foregroundColor(egvValueColor()) - } - VStack { - Text(lastEGVTimeFormatted()) - .font(.footnote) - .if(egvIsOutdated(), transform: { view in - view.foregroundColor(.red) - }) - Text(lastEGVDeltaFormatted()) - .font(.footnote) + } + VStack (spacing: 0) { + HStack { + //Trend arrow + if let egv = remoteDataSource.currentGlucoseSample { + Image(systemName: egv.arrowImageName()) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(maxWidth: 12 * homeViewTextMultiplier) + .offset(.init(width: 0.0, height: 1.5 * homeViewTextMultiplier)) + } + //BG delta + Text(lastEGVDeltaFormatted()) + .strikethrough(egvIsOutdated()) + .font(.system(size: 20.0 * homeViewTextMultiplier)) } + //Minutes since update + Text(durSinceEGV()) + .strikethrough(egvIsOutdated()) + .font(.system(size: 20.0 * homeViewTextMultiplier)) } } .navigationTitle(accountService.selectedLooper?.name ?? "Name?") @@ -102,6 +109,28 @@ struct HomeView: View { return currentEGV.date.formatted(.dateTime.hour().minute()) } + //Minutes since last BG reading + func minSinceEGV() -> String { + guard let currentEGV = remoteDataSource.currentGlucoseSample else { + return "0" + } + return String(Int(Date().timeIntervalSince(currentEGV.date)) / 60) + } + + //Seconds since last BG reading + func secSinceEGV() -> String { + guard let currentEGV = remoteDataSource.currentGlucoseSample else { + return "00" + } + let seconds = Int(Date().timeIntervalSince(currentEGV.date)) % 60 + return(String(format: "%02d", seconds)) + } + + //Time since last reading in mm:ss + func durSinceEGV() -> String { + return minSinceEGV() + ":" + secSinceEGV() + } + func egvIsOutdated() -> Bool { guard let currentEGV = remoteDataSource.currentGlucoseSample else { return true