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

BAL-194-GP-NEW EVENT TRACKING #196

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions Balance/Balance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@Environment(\.scenePhase)
var scenePhase
@State var heartAlert = false

var body: some Scene {
WindowGroup {
Expand Down Expand Up @@ -74,6 +75,10 @@
print("ScenePhase: unexpected state")
}
}
.onReceive( NotificationCenter.default.publisher( for: Notification.Name.heartAlert)) { _ in
self.heartAlert = true
appEvent(description: "App Opened via Heart Rate notification")
}

Check warning on line 81 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L79-L81

Added lines #L79 - L81 were not covered by tests
}
}

Expand All @@ -84,10 +89,28 @@
if value == false {
activityLogEntry.reset()
}
self.heartAlert = false

Check warning on line 92 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L92

Added line #L92 was not covered by tests
}

func activeApp() {
if heartAlert == false {
appEvent(description: "App Opened manually")
}
UIApplication.shared.applicationIconBadgeNumber = 0
UserDefaults.standard.set(false, forKey: StorageKeys.spotifyConnect)
}

func appEvent(description: String) {
activityLogEntry.addActionButton(actionDescription: description)
#if DEMO
logStore.saveLog(activityLogEntry)
ActivityLogStore.save(logs: logStore.logs) { result in
if case .failure(let error) = result {
print(error.localizedDescription)
}
}

Check warning on line 111 in Balance/Balance.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Balance.swift#L108-L111

Added lines #L108 - L111 were not covered by tests
#else
ActivityStorageManager.shared.uploadActivity(activityLogEntry: activityLogEntry)
#endif
}
}
12 changes: 12 additions & 0 deletions Balance/BalanceAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@
sceneConfig.delegateClass = SceneDelegate.self
return sceneConfig
}

// swiftlint:disable:next discouraged_optional_collection
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
return true
}
}

extension BalanceAppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
NotificationCenter.default.post(name: Notification.Name.heartAlert, object: nil)
}

Check warning on line 93 in Balance/BalanceAppDelegate.swift

View check run for this annotation

Codecov / codecov/patch

Balance/BalanceAppDelegate.swift#L91-L93

Added lines #L91 - L93 were not covered by tests
}
8 changes: 8 additions & 0 deletions Balance/Utils/BalanceExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
static let coinsUpdate = Notification.Name("coinsUpdate")
static let coinsRefresh = Notification.Name("coinsRefresh")
static let coinsAlert = Notification.Name("coinsAlert")
static let heartAlert = Notification.Name("heartAlert")
}

// swiftlint:disable operator_whitespace
Expand Down Expand Up @@ -158,3 +159,10 @@
static let screenHeight = UIScreen.main.bounds.size.height
static let screenSize = UIScreen.main.bounds.size
}

extension Array {
func first(elementCount: Int) -> Array {
let min = Swift.min(elementCount, count)
return Array(self[0..<min])
}

Check warning on line 167 in Balance/Utils/BalanceExtensions.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Utils/BalanceExtensions.swift#L164-L167

Added lines #L164 - L167 were not covered by tests
}
Loading