Skip to content
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

Feature/bal 64 heart rate i watch #180

Merged
merged 47 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d09076e
BAL-64-GP-HeartRate
gperissetcelteeka Aug 10, 2023
3130c64
BAL-64-GP-HeartRate
gperissetcelteeka Aug 11, 2023
71dd775
BAL-64-GP-HeartRate
gperissetcelteeka Aug 11, 2023
e7cea55
BAL-64-GP-HeartRate
gperissetcelteeka Aug 11, 2023
5de16ae
BAL-64-GP-HeartRate
gperissetcelteeka Aug 15, 2023
4034687
BAL-109-Coloring-Improvements
gperissetcelteeka Aug 17, 2023
c8b4491
BAL-109-Coloring-Improvements
gperissetcelteeka Aug 17, 2023
cd4db47
BAL-109-Coloring-Improvements
gperissetcelteeka Aug 18, 2023
5a7c32a
BAL-109-Coloring-Improvements
gperissetcelteeka Aug 19, 2023
49c7aba
BAL-169-Coloring-Improvements
gperissetcelteeka Aug 19, 2023
c478b3b
BAL-169-Coloring-Improvements
gperissetcelteeka Aug 19, 2023
4914e63
Update Balance/Distraction/DistractionView.swift
gperissetcelteeka Aug 22, 2023
e21eb3a
Update Balance/Distraction/Drawing/BackgroundDrawView.swift
gperissetcelteeka Aug 22, 2023
aa424af
Update Balance/Home/Home.swift
gperissetcelteeka Aug 22, 2023
fdd20b6
Update Balance/Login/AuthViewModel.swift
gperissetcelteeka Aug 22, 2023
c488430
Update Balance/Login/AuthViewModel.swift
gperissetcelteeka Aug 22, 2023
2212002
Update Balance/Login/LoginViewLocal.swift
gperissetcelteeka Aug 22, 2023
8d8b8de
Update Balance/Profile/UserProfileRepositoryLocal.swift
gperissetcelteeka Aug 22, 2023
adeab3e
Update Balance/Distraction/Drawing/MandalaCollectionView.swift
gperissetcelteeka Aug 22, 2023
27eee8c
BAL-172-BodySensations-LabelUpdate
gperissetcelteeka Aug 23, 2023
1c69eeb
BAL-172-BodySensations-LabelUpdate-GO-Button
gperissetcelteeka Aug 29, 2023
42e7e86
Merge branch 'main' into Improvements/BAL-172-Body-Sensations-LabelUp…
gperissetcelteeka Aug 29, 2023
4865a8e
Merge branch 'Improvements/BAL-172-Body-Sensations-LabelUpdate' into …
gperissetcelteeka Aug 29, 2023
fec3089
BAL-64-GP-HeartRate
gperissetcelteeka Aug 31, 2023
b7d4a8d
BAL-174-GP-CorrectText
gperissetcelteeka Aug 31, 2023
383d467
BAL-174-GP-CorrectText
gperissetcelteeka Aug 31, 2023
1a6903d
BAL-174-GP-CorrectText
gperissetcelteeka Aug 31, 2023
e1ea492
BAL-174-GP-CorrectText
gperissetcelteeka Aug 31, 2023
18c1ca5
BAL-174-GP-CorrectText
gperissetcelteeka Aug 31, 2023
5db36e5
BAL-174-GP-CorrectText
gperissetcelteeka Aug 31, 2023
2f39135
BAL-175-GP-BodySensations-Coins-Rewards
gperissetcelteeka Sep 1, 2023
4586216
BAL-175-GP-BodySensations-Coins-Rewards
gperissetcelteeka Sep 1, 2023
cb8e72d
Merge branch 'Improvements/BAL-175-BodySensation-Rewards' into featur…
gperissetcelteeka Sep 14, 2023
5f8024f
Add watchOS App
PSchmiedmayer Sep 28, 2023
6f94818
Update build-and-test.yml
PSchmiedmayer Sep 28, 2023
ab53ec6
Update beta-deployment.yml
PSchmiedmayer Sep 28, 2023
7c1ddd5
Update build-and-test.yml
PSchmiedmayer Sep 28, 2023
8a1205a
Update
PSchmiedmayer Sep 28, 2023
5b940ac
Merge branch 'feature/BAL-64-GP-HeartRate3' into feature/BAL-64-Heart…
gperissetcelteeka Sep 28, 2023
f91821b
Merge branch 'main' into feature/BAL-64-HeartRate-iWatch
gperissetcelteeka Sep 29, 2023
41ebc32
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
bebe48e
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
df3d053
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
9879c9f
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
3941bea
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
4ab7807
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
f7cb788
BAL-64-GP-HeartRate_iWatch
gperissetcelteeka Sep 29, 2023
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
84 changes: 70 additions & 14 deletions Balance.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions Balance/Balance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#endif
@StateObject var activityLogEntry = ActivityLogEntry()
@StateObject var bannerManager = PresentBannerManager()

@Environment(\.scenePhase)
var scenePhase

Expand All @@ -52,23 +52,37 @@
#endif
.environmentObject(activityLogEntry)
.environmentObject(bannerManager)
.onAppear(perform: {
if !userModel.existLocalUser(uid: demoID) {
userModel.createDemoUser()
}
})
.onChange(of: scenePhase) { phase in
switch phase {
case .active:
print("ScenePhase: active")
UserDefaults.standard.set(false, forKey: StorageKeys.spotifyConnect)
activeApp()
case .background:
print("ScenePhase: background")
let value = UserDefaults.standard.bool(forKey: StorageKeys.spotifyConnect)
if value == false {
activityLogEntry.reset()
}
backgroundApp()

Check warning on line 65 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L65

Added line #L65 was not covered by tests
case .inactive:
print("ScenePhase: inactive")
inactiveApp()

Check warning on line 67 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L67

Added line #L67 was not covered by tests
@unknown default:
print("ScenePhase: unexpected state")
}
}
}
}

func inactiveApp() { }

Check warning on line 75 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L75

Added line #L75 was not covered by tests

func backgroundApp() {
let value = UserDefaults.standard.bool(forKey: StorageKeys.spotifyConnect)
if value == false {
activityLogEntry.reset()
}
}

Check warning on line 82 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L77-L82

Added lines #L77 - L82 were not covered by tests

func activeApp() {
UIApplication.shared.applicationIconBadgeNumber = 0
UserDefaults.standard.set(false, forKey: StorageKeys.spotifyConnect)
}
}
3 changes: 2 additions & 1 deletion Balance/BalanceAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BalanceAppDelegate: CardinalKitAppDelegate {
}
}

#if !DEMO
private var firestore: Firestore<FHIR> {
let settings = FirestoreSettings()
if FeatureFlags.useFirebaseEmulator {
Expand All @@ -55,7 +56,7 @@ class BalanceAppDelegate: CardinalKitAppDelegate {
settings: settings
)
}
#endif

private var healthKit: HealthKit<FHIR> {
HealthKit {
Expand Down
5 changes: 4 additions & 1 deletion Balance/BalanceDebug.entitlements
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?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>aps-environment</key>
<string>development</string>
</dict>
</plist>
20 changes: 0 additions & 20 deletions Balance/Distraction/Drawing/DrawHighlightView.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Balance/Distraction/Gallery/LookImages/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
tapLike = false
}
}) {
Image("heartImage")
Image("heart3")

Check warning on line 187 in Balance/Distraction/Gallery/LookImages/ImageView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Gallery/LookImages/ImageView.swift#L187

Added line #L187 was not covered by tests
.resizable()
.frame(width: 30, height: 30)
.foregroundColor(.white)
Expand Down
51 changes: 51 additions & 0 deletions Balance/HeartRate/Counter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Counter.swift
// Balance
//
// Created by Gonzalo Perisset on 10/08/2023.
//

import Combine
import SwiftUI
import WatchConnectivity

// swiftlint:disable weak_delegate
final class Counter: ObservableObject {
var session: WCSession
let delegate: WCSessionDelegate
private let subject = PassthroughSubject<Double, Never>()

Check warning on line 16 in Balance/HeartRate/Counter.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/Counter.swift#L16

Added line #L16 was not covered by tests

@Published private(set) var count: Double = 0.0

Check warning on line 18 in Balance/HeartRate/Counter.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/Counter.swift#L18

Added line #L18 was not covered by tests

init(session: WCSession = .default) {
self.delegate = SessionDelegater(countSubject: subject)
self.session = session
self.session.delegate = self.delegate
self.session.activate()

subject
.receive(on: DispatchQueue.main)
.assign(to: &$count)
}

Check warning on line 29 in Balance/HeartRate/Counter.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/Counter.swift#L20-L29

Added lines #L20 - L29 were not covered by tests

func increment() {
count += 1
session.sendMessage(["count": count], replyHandler: nil) { error in
print(error.localizedDescription)
}
}

Check warning on line 36 in Balance/HeartRate/Counter.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/Counter.swift#L31-L36

Added lines #L31 - L36 were not covered by tests

func sendValue(val: Double) {
count = val
session.sendMessage(["count": count], replyHandler: nil) { error in
print(error.localizedDescription)
}
}

Check warning on line 43 in Balance/HeartRate/Counter.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/Counter.swift#L38-L43

Added lines #L38 - L43 were not covered by tests

func decrement() {
count -= 1
session.sendMessage(["count": count], replyHandler: nil) { error in
print(error.localizedDescription)
}
}

Check warning on line 50 in Balance/HeartRate/Counter.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/Counter.swift#L45-L50

Added lines #L45 - L50 were not covered by tests
}
50 changes: 50 additions & 0 deletions Balance/HeartRate/SessionDelegater.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// SessionDelegater.swift
// Balance
//
// Created by Gonzalo Perisset on 10/08/2023.
//

import Combine
import WatchConnectivity

class SessionDelegater: NSObject, WCSessionDelegate {
private let countSubject: PassthroughSubject<Double, Never>

init(countSubject: PassthroughSubject<Double, Never>) {
self.countSubject = countSubject
super.init()
}

Check warning on line 17 in Balance/HeartRate/SessionDelegater.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/SessionDelegater.swift#L14-L17

Added lines #L14 - L17 were not covered by tests

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
// Protocol comformance only
// Not needed for this demo
}

Check warning on line 22 in Balance/HeartRate/SessionDelegater.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/SessionDelegater.swift#L19-L22

Added lines #L19 - L22 were not covered by tests

func session(_ session: WCSession, didReceiveMessage message: [String: Any]) {
DispatchQueue.main.async {
if let count = message["count"] as? Double {
self.countSubject.send(count)
} else {
print("There was an error")
}
}
}

Check warning on line 32 in Balance/HeartRate/SessionDelegater.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/SessionDelegater.swift#L24-L32

Added lines #L24 - L32 were not covered by tests

// iOS Protocol comformance
// Not needed for this demo otherwise
#if os(iOS)
func sessionDidBecomeInactive(_ session: WCSession) {
print("\(#function): activationState = \(session.activationState.rawValue)")
}

Check warning on line 39 in Balance/HeartRate/SessionDelegater.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/SessionDelegater.swift#L37-L39

Added lines #L37 - L39 were not covered by tests

func sessionDidDeactivate(_ session: WCSession) {
// Activate the new session after having switched to a new watch.
session.activate()
}

Check warning on line 44 in Balance/HeartRate/SessionDelegater.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/SessionDelegater.swift#L41-L44

Added lines #L41 - L44 were not covered by tests

func sessionWatchStateDidChange(_ session: WCSession) {
print("\(#function): activationState = \(session.activationState.rawValue)")
}

Check warning on line 48 in Balance/HeartRate/SessionDelegater.swift

View check run for this annotation

Codecov / codecov/patch

Balance/HeartRate/SessionDelegater.swift#L46-L48

Added lines #L46 - L48 were not covered by tests
#endif
}
42 changes: 40 additions & 2 deletions Balance/Home/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@
import SwiftUI
import class FHIR.FHIR
import FirebaseAccount
import WatchConnectivity

// swiftlint:disable closure_body_length
struct HomeView: View {
@EnvironmentObject var authModel: AuthViewModel
@State var showMe = false
@State var profile = ProfileUser()

@StateObject var counter = Counter()

Check warning on line 20 in Balance/Home/Home.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/Home.swift#L20

Added line #L20 was not covered by tests

var body: some View {
ActivityLogContainer {
ZStack {
backgroundColor.edgesIgnoringSafeArea(.all)
NavigationStack {
VStack(spacing: 0) {
HeaderHome()
HeaderHome().environmentObject(counter)

Check warning on line 28 in Balance/Home/Home.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/Home.swift#L28

Added line #L28 was not covered by tests
menuOptions
Spacer()
}
Expand All @@ -42,6 +45,24 @@
loadUser()
}
}
.onChange(of: counter.count, perform: { _ in
if counter.count > 90 {
print(counter.count)
alertHeartRate()
}
})
.onAppear {
UNUserNotificationCenter.current().requestAuthorization(
options: [[.alert, .sound, .badge]],
completionHandler: { granted, error in
if error != nil {
print("LocalNotification error: \(String(describing: error))")
} else {
print("LocalNotification access granted...\( granted.description)")
}
}
)
}

Check warning on line 65 in Balance/Home/Home.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/Home.swift#L48-L65

Added lines #L48 - L65 were not covered by tests
}
}

Expand Down Expand Up @@ -200,6 +221,23 @@
}
}

func alertHeartRate() {
let content = UNMutableNotificationContent()
content.title = "BALANCE"
content.subtitle = "Please chill!"
content.body = "Your heart rate are to up! Please relax with Balance!"
content.badge = 1

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)

let requestIdentifier = "BALANCENotification"
let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
print("LocalNotification error: \(String(describing: error))")
})
}

Check warning on line 239 in Balance/Home/Home.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/Home.swift#L224-L239

Added lines #L224 - L239 were not covered by tests

func loadUser() {
#if !DEMO
UserProfileRepository.shared.fetchCurrentProfile { profileUser, error in
Expand Down
47 changes: 40 additions & 7 deletions Balance/Login/AuthViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import FirebaseFirestore
import SwiftUI

// swiftlint:disable function_parameter_count
// swiftlint:disable type_body_length
struct User {
var uid: String
var email: String?
Expand Down Expand Up @@ -208,10 +210,36 @@
}
}

func createDemoUser() {
let profileUser = ProfileUser(
id: demoID,
displayName: "Demo",
email: "demo@balance.com",
parentEmail: "",
birthday: "",
country: "",
phone: "",
avatar: "avatar_" + String(Int.random(in: 1..<7)),
accesory: "",
password: "demo"
)

UserProfileRepositoryToLocal.shared.createProfile(profile: profileUser) { profile, error in
if let error = error {
print("Error while fetching the user profile: \(error)")
return

Check warning on line 230 in Balance/Login/AuthViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Login/AuthViewModel.swift#L229-L230

Added lines #L229 - L230 were not covered by tests
} else {
print("User: " + (profile?.description() ?? "-"))
return
}
}
}

func createLocalUser(
uid: String,
name: String,
email: String,
password: String,
onSuccess: @escaping() -> Void,
onError: @escaping(_ errorMessage: String) -> Void
) {
Expand All @@ -225,7 +253,7 @@
phone: "",
avatar: "avatar_" + String(Int.random(in: 1..<7)),
accesory: "",
password: ""
password: password

Check warning on line 256 in Balance/Login/AuthViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Login/AuthViewModel.swift#L256

Added line #L256 was not covered by tests
)

UserProfileRepositoryToLocal.shared.createProfile(profile: profileUser) { profile, error in
Expand All @@ -243,21 +271,26 @@
}
}

func loginLocalUser(uid: String, onSuccess: @escaping() -> Void, onError: @escaping(_ errorMessage: String) -> Void) {
func loginLocalUser(uid: String, password: String, onSuccess: @escaping() -> Void, onError: @escaping(_ errorMessage: String) -> Void) {

Check warning on line 274 in Balance/Login/AuthViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Login/AuthViewModel.swift#L274

Added line #L274 was not covered by tests
UserProfileRepositoryToLocal.shared.fetchProfile(userId: uid) { profile, error in
if let error = error {
print("Error while fetching the user profile: \(error)")
onError(error.localizedDescription)
onError("The patientID or password are incorrect.")

Check warning on line 278 in Balance/Login/AuthViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Login/AuthViewModel.swift#L278

Added line #L278 was not covered by tests
return
} else if profile == nil && error == nil {
print("Error while fetching the user profile: profile==error==nulo")
onError("noUser")
onError("The patientID or password are incorrect.")

Check warning on line 282 in Balance/Login/AuthViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Login/AuthViewModel.swift#L282

Added line #L282 was not covered by tests
return
} else {
print("User: " + (profile?.description() ?? "-"))
self.isLoggedIn = true
self.profile = profile
onSuccess()
if profile?.password == password {
self.isLoggedIn = true
self.profile = profile
onSuccess()
} else {
print("Password Incorrect")
onError("The patientID or password are incorrect.")
}

Check warning on line 293 in Balance/Login/AuthViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Login/AuthViewModel.swift#L286-L293

Added lines #L286 - L293 were not covered by tests
return
}
}
Expand Down
Loading