Skip to content

Commit

Permalink
multiple: remove references to MusicController in exercises and begin…
Browse files Browse the repository at this point in the history
… implementation of heart range notifications
  • Loading branch information
liamcharger committed Jan 26, 2025
1 parent 8cf919c commit b540129
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 190 deletions.
Binary file modified .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion InfiniLink/BLE/BLECharacteristicHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct BLECharacteristicHandler {

@AppStorage("lastHeartRateUpdateTimestamp") var lastHeartRateUpdateTimestamp: Double = 0
@AppStorage("lastTimeCheckCompleted") var lastTimeCheckCompleted: Double = 0
@AppStorage("lastTimeStepGoalNotified") var lastTimeStepGoalNotified: Double = 86400
@AppStorage("lastTimeStepGoalNotified") var lastTimeStepGoalNotified: Double = 0

func fetchHeartPoints() -> [HeartDataPoint] {
let fetchRequest: NSFetchRequest<HeartDataPoint> = HeartDataPoint.fetchRequest()
Expand Down Expand Up @@ -234,7 +234,10 @@ struct BLECharacteristicHandler {
}
private func updateHeartRate(bpm: Int) {
lastHeartRateUpdateTimestamp = Date().timeIntervalSince1970

healthKitManager.writeHeartRate(date: Date(), dataToAdd: bleManager.heartRate)
chartManager.addHeartRateDataPoint(heartRate: Double(bpm), time: Date())

notificationManager.sendHeartRangeNotification(bpm)
}
}
2 changes: 1 addition & 1 deletion InfiniLink/Core/Components/ActionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct ActionView: View {
.padding(10)
.font(.body.weight(.semibold))
.background(action.accent)
.foregroundStyle(.white) // TODO: check this works for all accents
.foregroundStyle(.white)
.clipShape(RoundedRectangle(cornerRadius: 10))
Text(NSLocalizedString(action.title, comment: ""))
.font(.system(size: 28).weight(.bold))
Expand Down
14 changes: 0 additions & 14 deletions InfiniLink/Core/Exercise/View Model/ExerciseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ExerciseViewModel: ObservableObject {

let healthKitManager = HealthKitManager.shared

@Published var playedTracks = [PlayedTrack]()
@Published var exerciseTime: TimeInterval = 0
@Published var stepsTaken: Int = 0
@Published var currentExercise: Exercise?
Expand Down Expand Up @@ -60,18 +59,6 @@ class ExerciseViewModel: ObservableObject {
}
}

func addTrackToExercise(title: String, artist: String) {
let track = PlayedTrack(context: PersistenceController.shared.container.viewContext)
track.id = UUID()
track.timestamp = Date()
track.title = title
track.artist = artist

if !playedTracks.contains(where: { $0.title == track.title && $0.artist == track.artist }) {
playedTracks.append(track)
}
}

func reset() {
stepsTaken = 0
exerciseTime = 0
Expand All @@ -97,7 +84,6 @@ class ExerciseViewModel: ObservableObject {
newExercise.startDate = startDate
newExercise.endDate = Date()
newExercise.exerciseId = exercise
newExercise.playedTracks = NSSet(array: playedTracks)
newExercise.heartPoints = NSSet(array: heartPoints)
newExercise.steps = Int32(stepsTaken)

Expand Down
39 changes: 0 additions & 39 deletions InfiniLink/Core/Exercise/Views/ActiveExerciseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct ActiveExerciseView: View {
@Environment(\.managedObjectContext) var viewContext

@ObservedObject var exerciseViewModel = ExerciseViewModel.shared
@ObservedObject var musicController = MusicController.shared
@ObservedObject var bleManager = BLEManager.shared

@Binding var exercise: Exercise?
Expand Down Expand Up @@ -55,43 +54,6 @@ struct ActiveExerciseView: View {
}
}
Spacer()
if musicController.musicPlaying != 0 {
HStack(spacing: 12) {
if let artwork = musicController.musicPlayer.nowPlayingItem?.artwork, let image = artwork.image(at: CGSize(width: 52, height: 52)) {
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 52, height: 52)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
VStack(alignment: .leading, spacing: 2) {
Text(musicController.musicPlayer.nowPlayingItem?.title ?? "Not Playing")
.fontWeight(.bold)
if let artist = musicController.musicPlayer.nowPlayingItem?.artist {
Text(artist)
}
}
Spacer()
HStack(spacing: 16) {
Button {
musicController.musicPlaying == 1 ? musicController.pause() : musicController.play()
} label: {
Image(systemName: musicController.musicPlaying == 1 ? "pause.fill" : "play.fill")
.font(.system(size: 21))
}
Button {
musicController.skipForward()
} label: {
Image(systemName: "forward.fill")
.font(.system(size: 22))
}
}
}
.padding(14)
.foregroundStyle(Color.primary)
.background(Material.regular)
.clipShape(RoundedRectangle(cornerRadius: 20))
}
HStack(spacing: 14) {
Spacer()
Button {
Expand Down Expand Up @@ -145,7 +107,6 @@ struct ActiveExerciseView: View {
currentStepCount = bleManager.stepCount
DispatchQueue.main.async {
startTimer()
musicController.updateMusicInformation()
}
}
// Should these onChanges go in BLECharacteristicHandler?
Expand Down
22 changes: 0 additions & 22 deletions InfiniLink/Core/Exercise/Views/ExerciseDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,13 @@ struct ExerciseDetailView: View {
.foregroundStyle(.gray)
}
}
if let tracks = userExercise.playedTracks, tracks.count > 1 {
HStack {
Text("Total Tracks Played")
Text("\(tracks.count)")
.foregroundStyle(.gray)
}
}
}
if heartPoints.count > 1 {
Section("Heart Rate") {
HeartChartView(showHeader: false)
}
.listRowBackground(Color.clear)
}
if let tracksSet = userExercise.playedTracks as? Set<PlayedTrack>, tracksSet.count > 1 {
let tracks = Array(tracksSet).sorted(by: { $0.timestamp ?? Date() < $1.timestamp ?? Date() })

Section("Played Tracks") {
ForEach(tracks) { track in
if let title = track.title, let artist = track.artist {
VStack(alignment: .leading, spacing: 5) {
Text(title)
.fontWeight(.bold)
Text(artist)
}
}
}
}
}
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions InfiniLink/Core/Settings/General/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ struct GeneralSettingsView: View {
}
.disabled(bleManager.blefsTransfer == nil)
}
Section {
// TODO: implement non-dummy input form in SetUpDetailsView
/*
NavigationLink {
SetUpDetailsView(listOnly: true)
.navigationBarTitle("Health Details")
} label: {
Text("Health Details")
}
*/
}
Section {
NavigationLink {
AppearanceView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ struct NotificationsSettingsView: View {
@AppStorage("waterReminder") var waterReminder = true
@AppStorage("waterReminderAmount") var waterReminderAmount = 7
@AppStorage("standUpReminder") var standUpReminder = true
@AppStorage("heartRangeReminder") var heartRangeReminder = true
@AppStorage("minHeartRange") var minHeartRange = 40
@AppStorage("maxHeartRange") var maxHeartRange = 150
@AppStorage("watchNotifications") var watchNotifications = true
@AppStorage("enableReminders") var enableReminders = true
@AppStorage("enableCalendarNotifications") var enableCalendarNotifications = true
Expand Down Expand Up @@ -49,7 +52,7 @@ struct NotificationsSettingsView: View {
Toggle("Water Reminder", isOn: $waterReminder)
if waterReminder {
Picker("Interval", selection: $waterReminderAmount) {
ForEach(0..<9) { amount in
ForEach(0..<9, id: \.self) { amount in
Text("\(amount + 1) time\(amount == 0 ? "" : "s")")
}
}
Expand All @@ -60,6 +63,21 @@ struct NotificationsSettingsView: View {
Toggle("Stand-up Reminder", isOn: $standUpReminder)
}
*/
Section(footer: Text("Get a notification whenn your heart rate goes above or below the specified range.")) {
Toggle("Heart Range Notifications", isOn: $heartRangeReminder)
if heartRangeReminder {
HStack {
Text("Minimum")
Stepper("\(minHeartRange)", value: $minHeartRange, in: 40...(maxHeartRange - 1), step: 1)
.fontWeight(.semibold)
}
HStack {
Text("Maximum")
Stepper("\(maxHeartRange)", value: $maxHeartRange, in: (minHeartRange + 1)...220, step: 1)
.fontWeight(.semibold)
}
}
}
Section(header: Text("Daily Goals"), footer: Text("Get notified when you reach your daily fitness goals.")) {
Toggle("Steps", isOn: $remindOnStepGoalCompletion)
}
Expand Down
12 changes: 2 additions & 10 deletions InfiniLink/InfiniLink.xcdatamodeld/InfiniLink.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24C5089c" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24D5040f" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="BatteryDataPoint" representedClassName="BatteryDataPoint" syncable="YES" codeGenerationType="class">
<attribute name="deviceId" optional="YES" attributeType="String"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
Expand Down Expand Up @@ -51,13 +51,6 @@
<attribute name="weatherEnable" attributeType="Integer 16" defaultValueString="1" usesScalarValueType="YES"/>
<relationship name="device" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Device" inverseName="pineTimeStyle" inverseEntity="Device"/>
</entity>
<entity name="PlayedTrack" representedClassName="PlayedTrack" syncable="YES" codeGenerationType="class">
<attribute name="artist" optional="YES" attributeType="String"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="timestamp" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="title" attributeType="String"/>
<relationship name="exercise" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="UserExercise" inverseName="playedTracks" inverseEntity="UserExercise"/>
</entity>
<entity name="SleepDataPoint" representedClassName="SleepDataPoint" syncable="YES" codeGenerationType="class">
<attribute name="deviceId" optional="YES" attributeType="String"/>
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
Expand All @@ -77,6 +70,5 @@
<attribute name="startDate" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="steps" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<relationship name="heartPoints" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="HeartDataPoint" inverseName="exercise" inverseEntity="HeartDataPoint"/>
<relationship name="playedTracks" toMany="YES" deletionRule="Nullify" destinationEntity="PlayedTrack" inverseName="exercise" inverseEntity="PlayedTrack"/>
</entity>
</model>
</model>
24 changes: 18 additions & 6 deletions InfiniLink/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@
},
"General" : {

},
"Get a notification whenn your heart rate goes above or below the specified range." : {

},
"Get notifications on your watch when you reach goals, when it's time to drink water, and more." : {

Expand Down Expand Up @@ -441,9 +444,18 @@
},
"Health Details" : {

},
"Heart Range Notifications" : {

},
"Heart Rate" : {

},
"Heart Rate High" : {

},
"Heart Rate Low" : {

},
"Height" : {

Expand Down Expand Up @@ -525,9 +537,15 @@
},
"M" : {

},
"Maximum" : {

},
"Metric" : {

},
"Minimum" : {

},
"Music" : {

Expand Down Expand Up @@ -579,9 +597,6 @@
},
"Pair New Device" : {

},
"Played Tracks" : {

},
"Pull Request #2217 on GitHub" : {

Expand Down Expand Up @@ -711,9 +726,6 @@
},
"Total Steps" : {

},
"Total Tracks Played" : {

},
"Units" : {

Expand Down
Loading

0 comments on commit b540129

Please sign in to comment.