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

Tasks 300 - 303 #88

Merged
merged 26 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
afe49bf
[Cozie] Push notifications 1 and Watch survey 1
Oct 3, 2024
fb7bde4
[Cozie] pre-cached health data
Oct 4, 2024
6a97e6e
[Cozie] fix scroll and new notification categories
Oct 4, 2024
23628fe
[Cozie] update app version
Oct 5, 2024
15e78bd
Merge branch 'update_phase_102024' into update_phase_2
Oct 5, 2024
0c56c5d
[Cozie] fixed scroll to question (updated UI id), add cache binding.
Oct 5, 2024
bb13374
[Cozie] Add health cutoff data, fix scroll in watchApp, added OneSign…
Oct 7, 2024
ce32832
[Cozie] Migration OneSignal to version 5.0
Oct 8, 2024
7158480
[Cozie] Changed Backend to Advanced und split into new sections
Oct 8, 2024
41c6c25
[Cozie] Update OneSignal notification extension
Oct 8, 2024
feff031
Merge branch 'master' into update_phase_102024
Oct 8, 2024
f9568aa
Merge branch 'update_phase_102024' into update_phase_2
Oct 8, 2024
a96e827
Merge branch 'update_phase_2' into update_phase_3
Oct 8, 2024
e9e4bc5
[Cozie] Improve syncing of the Cozie settings
Oct 9, 2024
664ebb9
[Cozie] Added "Summary" label/data behaviour.
Oct 11, 2024
5e539ea
[Cozie] Remove scroll animation to question in watch app
Oct 11, 2024
01d6b86
[Cozie] Phase 4 + Phase 5
Oct 22, 2024
07c8a3f
[Cozie] Fix crash and error handling
Oct 28, 2024
5e6b744
[Cozie] PushNotification logging structure
Oct 29, 2024
72119fc
[Cozie] Add push notification logging, test coverage 33
Oct 31, 2024
751437f
[Cozie] Clean up code, fix typos
Nov 8, 2024
14eec50
[Cozie] Haptic and visual feedback for response options. Bug fix 1 (P…
Nov 29, 2024
d7836c1
[Cozie] Improve watch survey location data
Nov 29, 2024
4d81d62
[Cozie] DeepLink, fix for ws link update
Dec 18, 2024
8b3cf48
[Cozie] added apnea event (303)
Dec 18, 2024
76d64bb
[Cozie] fixed ws link update, task 303
Dec 20, 2024
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
10 changes: 9 additions & 1 deletion Cozie Watch App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import SwiftUI
import WatchConnectivity

struct UICommon {
static let buttonHeight: CGFloat = 45
static let cornerRadius: CGFloat = 8

static let buttonColor = Color(.displayP3, red: 1.0, green: 1.0, blue: 1.0, opacity: 0.20)
static let selectedButtonColor = Color(.displayP3, red: 1.0, green: 1.0, blue: 1.0, opacity: 0.12)
}

struct ContentView: View {
@StateObject var viewModel = WatchSurveyViewModel()
var body: some View {
Expand All @@ -18,7 +26,7 @@ struct ContentView: View {
.multilineTextAlignment(.center)
.padding([.leading, .trailing], 8)
.onAppear {
viewModel.prepare()
viewModel.prepareLocationAndConnectivityManager()
}
Image(systemName: "arrow.triangle.2.circlepath")
.font(.system(size: 35))
Expand Down
25 changes: 16 additions & 9 deletions Cozie Watch App/Interactors/WatchSurveyInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,28 @@ class SurveyHistory: Codable {
}
}

class WatchSurveyInteractor {
final class WatchSurveyInteractor {
let healthInteractor: HealthKitInteractor = HealthKitInteractor(storage: StorageManager.shared, userData: StorageManager.shared, backendData: StorageManager.shared, loger: StorageManager.shared, dataPrefix: "ws")
let offlineMode = OfflineModeManager()

func sendSurveyData(watchSurvey: WatchSurvey?,
func healthDataPreload(trigger: String = CommunicationKeys.syncBackgroundTaskTrigger.rawValue, completion:((_ models: [HealthModel]?)->())?) {
healthInteractor.requestHealthData(trigger: trigger, completion: completion)
}

func sendSurveyData(watchSurvey: WatchSurveyModelController?,
selectedOptions:[SelectedSurveyInfo],
location: CLLocation?,
time: SelectedSurveyTime,
storage: StorageManager = StorageManager.shared,
healthCache: [HealthModel]? = nil,
logsComplition:(()->())? = nil, completion:((_ success: Bool, _ error: Error?)->())?) {
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
dateFormatter.dateFormat = DateFormat.defaultFormat
// dateFormatter.locale = Locale(identifier: "en_US_POSIX")
let dateString = dateFormatter.string(from: date)


let tags = [WatchSurveyKeys.idOnesignal.rawValue: storage.userOneSignalID(),
WatchSurveyKeys.idParticipant.rawValue: storage.userID(),
WatchSurveyKeys.idPassword.rawValue: storage.paswordID()]
Expand Down Expand Up @@ -80,8 +87,8 @@ class WatchSurveyInteractor {
storage.seveLogs(logs: String(data: jsonToLog, encoding: .utf8) ?? "")
logsComplition?()

if offlineMode.isEnabled {
healthInteractor.sendData(trigger: CommunicationKeys.syncWatchSurveyTrigger.rawValue, timeout: 0) { succces in
if offlineMode.isEnabled {
healthInteractor.sendData(trigger: CommunicationKeys.syncWatchSurveyTrigger.rawValue, timeout: 0, healthCache: healthCache) { succces in
completion?(true, nil)
}
} else {
Expand All @@ -90,7 +97,7 @@ class WatchSurveyInteractor {
case .success(let data):
debugPrint(String(data: data, encoding: .utf8) ?? "somthing whent wrong!!!")
//completion?(true, nil)
self?.healthInteractor.sendData(trigger: CommunicationKeys.syncWatchSurveyTrigger.rawValue, timeout: 0) { succces in
self?.healthInteractor.sendData(trigger: CommunicationKeys.syncWatchSurveyTrigger.rawValue, timeout: 0, healthCache: healthCache) { succces in
completion?(true, nil)
}
case .failure(let error):
Expand Down Expand Up @@ -156,13 +163,13 @@ class WatchSurveyInteractor {
WatchSurveyKeys.idParticipant.rawValue: storage.userID(),
WatchSurveyKeys.idPassword.rawValue: storage.paswordID()]

let filds = [WatchSurveyKeys.actionButtonKey.rawValue: action,
let fields = [WatchSurveyKeys.actionButtonKey.rawValue: action,
WatchSurveyKeys.transmitTrigger.rawValue: WatchSurveyKeys.transmitTriggerPushValue.rawValue]

let response: [String : Any] = [WatchSurveyKeys.postTime.rawValue: formattedDate(),
WatchSurveyKeys.measurement.rawValue: storage.expirimentID(),
WatchSurveyKeys.tags.rawValue: tags,
WatchSurveyKeys.fields.rawValue: filds]
WatchSurveyKeys.fields.rawValue: fields]

let api = storage.watchSurveyAPI()
offlineMode.updateWith(apiInfo: (wUrl: api.url, wKey: api.key))
Expand Down Expand Up @@ -206,7 +213,7 @@ class WatchSurveyInteractor {
private func formattedDate() -> String {
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
dateFormatter.dateFormat = DateFormat.defaultFormat
return dateFormatter.string(from: date)
}

Expand Down
21 changes: 20 additions & 1 deletion Cozie Watch App/Managers/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import Foundation
import CoreLocation

class LocationManager: NSObject {
protocol UpdateLocationProtocol {
func updateLocation(completion: (()->())?)
var currentLocation: CLLocation? { get }
}

final class LocationManager: NSObject {
var locationManager: CLLocationManager? = nil
var currentLocation: CLLocation? = nil
var lastUpdateDate: Date?
Expand All @@ -22,6 +27,20 @@ class LocationManager: NSObject {
}
}

extension LocationManager: UpdateLocationProtocol {
func updateLocation(completion: (()->())?) {
self.completion = completion

if locationManager == nil {
self.requestAuth()
} else {
if locationManager!.authorizationStatus == .authorizedWhenInUse || locationManager!.authorizationStatus == .authorizedAlways {
locationManager?.requestLocation()
}
}
}
}

extension LocationManager: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
Expand Down
14 changes: 14 additions & 0 deletions Cozie Watch App/Managers/StorageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class StorageManager: CozieStorageProtocol {
case lastSurveyTimeInterval = "CozieLastSurveyTimeIntervalKey"
case sevedSurveyCount = "CozieSevedSurveyCount"
case notSyncedSurvey = "CozieNotSyncedSurvey"
case healthMaxCutoffTimeintervalKey = "CozieHealthMaxCutoffTimeintervalKey"

// Storage postfix
case storagePostfixTime = "_wstorage_time"
Expand Down Expand Up @@ -118,6 +119,15 @@ class StorageManager: CozieStorageProtocol {
return (UserDefaults.standard.value(forKey: Keys.lastSurveyTimeInterval.rawValue) as? Int) ?? 0
}

// MARK: Last survey send
func saveHealthMaxCutoffTimeinterval(_ interval: Double) {
UserDefaults.standard.set(interval, forKey: Keys.healthMaxCutoffTimeintervalKey.rawValue)
}

func healthMaxCutoffTimeinterval() -> Double {
return (UserDefaults.standard.value(forKey: Keys.healthMaxCutoffTimeintervalKey.rawValue) as? Double) ?? 0
}

// MARK: Save survey logs

private func getDocumentsDirectory() -> URL {
Expand Down Expand Up @@ -242,6 +252,10 @@ class StorageManager: CozieStorageProtocol {

// MARK: HealthKit data storage

func maxHealthCutoffInteval() -> Double {
return healthMaxCutoffTimeinterval()
}

func healthLastSyncedTimeInterval(offline: Bool) -> Double {
return UserDefaults.standard.value(forKey: offline ? Keys.healthLastSyncOfflineKey.rawValue : Keys.healthLastSyncKey.rawValue) as? Double ?? 0.0
}
Expand Down
Loading