OutRun icon indicating copy to clipboard operation
OutRun copied to clipboard

Add heart rate support

Open Amwam opened this issue 3 years ago • 5 comments

This adds a heart rate graph to the workout view, when available.

Heart rate data isn't actually captured as part of a workout, instead its recorded separately. This means that for full heart rate tracking, we would need a companion watch app/extension.

~In the future, it may be better to rely on a query each time to fetch the heart rate information for displaying, rather than trying to store it.~ Updated the pull request to do this

A few other things to mention. I think I've found a better solution for the PR #30. The issue was that steps was not always completing, resulting in the count never being updated. Adding the completion handler in the right place for the steps import, seems to solve the issue.

Extracted out the querying for heart rate data, so that it doesn't actually rely on the workout. The query only really needs the start/end times. This should be useful as we can then use that data for displaying the heart rate graph, without relying on the stored samples.

I've added the German strings for Heart Rate, and Heart Rate over time, however, I did use Google Translate for this (as I don't speak German).

The Heart rate graph now relies on querying healthkit to get the data, so there is no need to store it within the app. I'm not sure how to modify the core data models, so i've left that bit as it is.

The WorkoutViewController was getting a bit difficult to work with, as each view seemed to rely on the exact order of previous for layout. I've switched this to use a UIStackView, Which then means each subview is managed automatically, and in order. This also allows each individual view to control when it is shown/hidden via the isHidden property (UIStackView will auto arrange the views to manage)

Screenshots:

Below is a workout started in the Apple Workouts app on Apple Watch IMG_A25DE801D803-1

Below is a workout started with outrun. IMG_6C72DDA925B2-1

Amwam avatar Oct 03 '20 13:10 Amwam

In case anyone read this PR previously, I've now updated it, so that heart rate data is loaded when viewing a workout only. The original implementation of saving it on completion, made the UI too slow to respond. As the data is stored separately from a workout anyway, there isn't much need to store it within the app, when it can be easily queried.

There are some other general improvements to the WorkoutViewController, to make it easier to work with, by switching to a UIStackView.

Amwam avatar Oct 03 '20 18:10 Amwam

Hi! Nice feature! Could you please check the conflicts in the string files, so @timfraedrich gets it easier to merge?

Once this PR gets merged, as new strings were added, the English strings file should be uploaded to Weblate so other languages could get translations for them.

Thank you!

lpla avatar Dec 15 '20 08:12 lpla

@lpla Thanks, I'll try and tackle this soon. Do I now only need to modify the English strings file, and the rest will be updated automatically? Or should I keep the modifications I've made to the German strings file?

Amwam avatar Dec 15 '20 10:12 Amwam

Hey @Amwam, sorry I didn't get back to you earlier in person, I just had a lot on my plate lately.

I would actually hold on making the changes for now, I have been working on a new data model version for quite some time, including support for heart rates, and I hope I can get back to them and finally upgrade soon.

Once I've done that parts of the data interface will be quite different, probably making much of the changes incompatible, so I would propose once I'm ready I would get back to you and we could either figure this out together or I would use the code base you provided here and credit you, where credit is due.

Please let me know what you think about that.

timfraedrich avatar Dec 15 '20 16:12 timfraedrich

@timfraedrich No problem at all, this was a fun thing for me to try and do.

We might get lucky here, as the majority of this change doesn't need the data model, as it queries the heart rate as needed, but more than happy to wait and see what happens.

I'd recommend taking a look at the changes in https://github.com/timfraedrich/OutRun/pull/31/files#diff-eee3bdab3f1738acce9fe55fca140b8bc063d29b8d509e8892016379c2575a4bR138 as that makes working with the WorkoutViewController a lot easier to deal with. I could try and pull that into another PR if you think it's worth it.

Amwam avatar Dec 24 '20 09:12 Amwam