Skip to content

Commit

Permalink
Reorganize views
Browse files Browse the repository at this point in the history
  • Loading branch information
gestrich committed Aug 9, 2024
1 parent 14302ad commit b074d02
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 53 deletions.
23 changes: 14 additions & 9 deletions LoopCaregiver/LoopCaregiverWatchApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ struct ContentView: View {
@State private var path = NavigationPath()

var body: some View {
let _ = Self._printChanges()
NavigationStack(path: $path) {
VStack {
if let looperService = accountService.selectedLooperService {
HomeView(connectivityManager: watchService, accountService: accountService, looperService: looperService)
} else {
Text("Open Caregiver Settings on your iPhone and tap 'Setup Watch'")
NavigationLink {
WatchSettingsView(
connectivityManager: watchService,
accountService: accountService,
settings: settings
)
} label: {
Label("Settings", systemImage: "gear")
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
NavigationLink {
WatchSettingsView(
connectivityManager: watchService,
accountService: accountService,
settings: settings
)
} label: {
Label("Settings", systemImage: "gear")
}
}
}
}
}
.alert(deepLinkErrorText, isPresented: $deepLinkErrorShowing) {
Expand Down
101 changes: 58 additions & 43 deletions LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,25 @@ struct HomeView: View {
}

var body: some View {
Group {
switch glucoseTimelineEntry {
case .success(let glucoseTimelineValue):
GeometryReader { geometryProxy in
List {
NightscoutChartScrollView(settings: settings, remoteDataSource: remoteDataSource, compactMode: true)
.frame(height: geometryProxy.size.height * 0.75)
.listRowBackground(Color.clear)
.listRowInsets(.none)
if let (override, status) = glucoseTimelineValue.treatmentData.overrideAndStatus {
NavigationLink {
Text("Override Control Coming Soon...")
} label: {
Label {
if status.active {
Text(override.presentableDescription())
} else {
Text("Overrides")
}
} icon: {
workoutImage(isActive: status.active)
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.blue)
.accessibilityLabel(Text("Workout"))
}
}
}
NavigationLink {
WatchSettingsView(
connectivityManager: connectivityManager,
accountService: accountService,
settings: settings
)
} label: {
Label("Settings", systemImage: "gear")
}
}
.listRowInsets(.none)
let _ = Self._printChanges()
GeometryReader { geometryProxy in
List {
graphRowView()
.frame(height: geometryProxy.size.height * 0.75)
.listRowBackground(Color.clear)
NavigationLink {
Text("Override Control Coming Soon...")
} label: {
overrideRowView()
}
case .failure(let glucoseTimeLineEntryError):
if !remoteDataSource.updating {
Text(glucoseTimeLineEntryError.localizedDescription)
NavigationLink {
WatchSettingsView(
connectivityManager: connectivityManager,
accountService: accountService,
settings: settings
)
} label: {
Label("Settings", systemImage: "gear")
}
}
}
Expand All @@ -86,6 +61,46 @@ struct HomeView: View {
})
}

@ViewBuilder
func graphRowView() -> some View {
Group {
switch glucoseTimelineEntry {
case .success:
NightscoutChartScrollView(settings: settings, remoteDataSource: remoteDataSource, compactMode: true)
case .failure(let glucoseTimeLineEntryError):
if !remoteDataSource.updating {
Text(glucoseTimeLineEntryError.localizedDescription)
} else {
Text("")
}
}
}
}

@ViewBuilder func overrideRowView() -> some View {
switch glucoseTimelineEntry {
case .success(let glucoseTimelineValue):
if let (override, status) = glucoseTimelineValue.treatmentData.overrideAndStatus {
Label {
if status.active {
Text(override.presentableDescription())
} else {
Text("Overrides")
}
} icon: {
workoutImage(isActive: status.active)
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.blue)
.accessibilityLabel(Text("Workout"))
}
}
case .failure:
Text("")
}
}

struct ToolbarButtonView: View {
var remoteDataSource: RemoteDataServiceManager
var glucoseTimelineEntry: GlucoseTimeLineEntry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public struct TimelineProviderShared {
var errorDescription: String? {
switch self {
case let .looperNotFound(looperID, looperName, availableCount):
return "The looper for this widget was not found: \(looperName), (\(looperID)) \(availableCount)." + configurationText()
return "The looper for this widget was not found: \(looperName), (\(looperID.dropLast(30))), (\(availableCount))." + configurationText()
case .looperNotConfigured:
return "No looper is configured for this widget. " + configurationText()
case .notReady:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public struct NightscoutChartScrollView: View {
}

public var body: some View {
let _ = Self._printChanges()
GeometryReader { containerGeometry in
ZoomableScrollView { zoomScrollViewProxy in
NightscoutChartView(viewModel: graphViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ struct NightscoutChartView: View {
let viewModel: NightscoutChartViewModel

var body: some View {
let _ = Self._printChanges()
Chart {
ForEach(viewModel.getTargetDateRangesAndValues(), id: \.range) { dateRangeAndValue in
RectangleMark(
Expand Down

0 comments on commit b074d02

Please sign in to comment.