Skip to content

Commit

Permalink
feat: add health data usage descriptions and IDEWorkspaceChecks.plist
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuschaves committed Mar 7, 2024
1 parent ea33191 commit c1e99e2
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 69 deletions.
22 changes: 20 additions & 2 deletions PulsePomodoro Watch App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
Text("Focus time")
.font(.caption)
.fontWeight(.bold)
.frame(maxWidth: .infinity, alignment: .leading)
.scenePadding()
.padding(
EdgeInsets(top: -20, leading: 0, bottom: 0, trailing: 0)
)
Spacer()
Stepper(value: $minutes, in: 0...60, step: 1) {
Text("\(minutes) minutes")
.font(.headline)
.font(.caption2)
}
.padding(.top, 18)
.padding(.bottom, 18)
Expand All @@ -25,11 +34,20 @@ struct ContentView: View {
label: {
Text("Confirm")
})
}.navigationTitle("Focus time")
}
.padding()

}.onAppear(perform: {
heartRateMonitor.requestAuthorization()
})
}
}

struct ContentView_Preview: PreviewProvider {
static var previews: some View {
NavigationStack {
ContentView()
}
}
}

28 changes: 25 additions & 3 deletions PulsePomodoro Watch App/views/PomodoroResumeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import Foundation
import SwiftUI

struct PomodoroResumeView: View {
@Environment(\.presentationMode) var presentationMode

var timeFocused: Int
var startDate: Date
var cycles: Int

@State private var averageHr = 0
@State private var averageBreath = 0
@State private var goToHome = false

let heartRateMonitor = HeartRateMonitor()

Expand All @@ -21,7 +24,7 @@ struct PomodoroResumeView: View {
.padding(EdgeInsets(
top: 2, leading: 0, bottom: 0, trailing: 0
))
Text("\(formatSecondsToMMSS(seconds: timeFocused))")
Text("\(formatSecondsToMMSS(seconds: timeFocused)) in \(cycles) cycles")
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundStyle(Color.yellow)
.fontWeight(Font.Weight.bold)
Expand Down Expand Up @@ -83,10 +86,28 @@ struct PomodoroResumeView: View {
}
.navigationBarTitle("Summary")
.navigationBarTitleDisplayMode(.inline)

.padding()
}.onAppear(perform: {
self.savePomodoro()
})
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button(action: {
self.goToHome = true
}) {
Image(systemName: "xmark")
}
}
}
.navigationDestination(
isPresented: self.$goToHome
) {
ContentView()
}
.navigationBarBackButtonHidden(true)
.toolbar(.hidden)
}

func formatSecondsToMMSS(seconds: Int) -> String {
Expand Down Expand Up @@ -121,7 +142,7 @@ struct PomodoroResumeView: View {
if let heartRate = heartRate, let respiratoryRate = respiratoryRate {
self.averageHr = heartRate
self.averageBreath = respiratoryRate

print("Heart rate on last \(timeFocused) seconds was \(heartRate)")
let isHeartRateNormal = heartRateMonitor.isRestingHeartRateNormal(heartRate: heartRate)

Expand Down Expand Up @@ -161,7 +182,8 @@ struct PomodoroResumeView_Previews: PreviewProvider {
NavigationStack {
PomodoroResumeView(
timeFocused: 300,
startDate: Date()
startDate: Date(),
cycles: 2
)
}
}
Expand Down
108 changes: 69 additions & 39 deletions PulsePomodoro Watch App/views/RemainingMinutesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,79 @@ struct RemainingMinutesView: View {
@State private var cycles = 0
@State private var totalTimeFocused = 0

@State private var timeInactiveInSecods = 0
@State private var startInactiveDate = Date()
@State private var endInactiveDate = Date()

@Environment(\.scenePhase) var scenePhase
@Environment(\.presentationMode) var presentationMode


var body: some View {
Text("\(self.formatSecondsToMMSS(seconds: remainingSeconds))")
.font(.largeTitle)
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
.onAppear {
startCountdown()
WKExtension.shared().isFrontmostTimeoutExtended = true
}
HStack {
NavigationLink(
destination: PomodoroResumeView(
timeFocused: self.totalTimeFocused,
startDate: self.startDate
),
label: {
Image(systemName: "checkmark")
.foregroundStyle(Color.green)
.font(.title2)
.padding(
EdgeInsets(
top: 0,
leading: 0,
bottom: 0,
trailing: 26
NavigationStack {
Text("\(self.formatSecondsToMMSS(seconds: remainingSeconds))")
.font(.largeTitle)
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
.onAppear {
startCountdown()
}
HStack {
NavigationLink(
destination: PomodoroResumeView(
timeFocused: self.totalTimeFocused,
startDate: self.startDate,
cycles: self.cycles
),
label: {
Image(systemName: "checkmark")
.foregroundStyle(Color.green)
.font(.title2)
.padding(
EdgeInsets(
top: 0,
leading: 0,
bottom: 0,
trailing: 26
)
)
)
}
)
.buttonStyle(PlainButtonStyle())
.disabled(!isTimeOver)
.onTapGesture {
if (isTimeOver) {
handleEndCountdown()
}
}
).buttonStyle(PlainButtonStyle())

Image(systemName: $isPaused.wrappedValue || $isTimeOver.wrappedValue ? "play" : "pause")
.foregroundStyle(Color.yellow)
.font(.title2)
.padding(EdgeInsets(top: 0, leading: 26, bottom: 0, trailing: 0))
.onTapGesture(perform: {
if (self.isTimeOver) {
self.startCountdown()
self.isTimeOver.toggle()
} else {
self.isPaused.toggle()
}
})
}
.padding(EdgeInsets(top: 16, leading: 0, bottom: 0, trailing: 0))
Spacer()
Text("\(self.cycles) cycles")
.padding()
.fontWeight(Font.Weight.thin)

Image(systemName: $isPaused.wrappedValue || $isTimeOver.wrappedValue ? "play" : "pause")
.foregroundStyle(Color.yellow)
.font(.title2)
.padding(EdgeInsets(top: 0, leading: 26, bottom: 0, trailing: 0))
.onTapGesture(perform: {
if (self.isTimeOver) {
self.startCountdown()
self.isTimeOver.toggle()
} else {
self.isPaused.toggle()
}
})
}.onChange(of: scenePhase) { newPhase in
if newPhase == .active {
self.endInactiveDate = Date()
self.timeInactiveInSecods = Int(self.endInactiveDate.timeIntervalSince(self.startInactiveDate))
self.remainingSeconds = max(0, self.remainingSeconds - self.timeInactiveInSecods)
} else if newPhase == .inactive {
self.startInactiveDate = Date()
}
}
.padding(EdgeInsets(top: 16, leading: 0, bottom: 0, trailing: 0))
}

func handleEndCountdown() {
Expand All @@ -66,7 +96,7 @@ struct RemainingMinutesView: View {
self.cycles += 1
self.totalTimeFocused += timerSeconds
}


func startCountdown() {
remainingSeconds = timerSeconds
Expand Down
7 changes: 6 additions & 1 deletion PulsePomodoro-Watch-App-Info.plist
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>NSHealthShareUsageDescription</key>
<string>We need this data to monitor your heart rate while you are using pomodoro</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We need this data to monitor your heart rate while you are using pomodoro</string>
</dict>
</plist>
Loading

0 comments on commit c1e99e2

Please sign in to comment.