Skip to content

Maximize use of real estate in Home view of Watch app #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
67 changes: 48 additions & 19 deletions LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?")
Expand Down Expand Up @@ -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
Expand Down