Fix possible incorrect total basal units in profile editor #421
+8
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes possible incorrect total basal units in profile editor
Steps to reproduce
Cause
This is caused by the fact that the total is calculated before the entries are sorted.
Effects
It seems to be a visual problem only, saving on pump seems to save the profile correctly. And after reopening the profile editor, the total is calulated correctly aswell.
Priority
Even though this might not be a problem when 1.0 comes with reworked settings, this bug got me scared when editing my basal profile. So I figured this might be worth fixing.
Deduplication of items
Furthermore, upon inspecing the validate() function I noticed that entries will get deduplicated based on the start time. As this method is called .onAppear of the RootView it's possible that while editing an entry it will get depulicated if one selects an already used start time. after that happens, changing the time or rate of this entry will cause the application to crash
I included a fix for that particular situation by making it impossible to select an already used start time, which I feel like is a nice addition from a users perspective aswell.
But this is more of an edge case and this problem also exists in other similar views like the ISF profile editor. So if we think it's worth fixing, I could also fix that in a separate PR and then include the other views aswell.
This is my first PR to this project, so feedback is welcome :)