This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Support for saving goal weight #713
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,35 @@ | |
part of fitness; | ||
|
||
typedef void SettingsUpdater({ | ||
BackupMode backup | ||
BackupMode backup, | ||
double goalWeight | ||
}); | ||
|
||
class SettingsFragment extends Component { | ||
class SettingsFragment extends StatefulComponent { | ||
|
||
SettingsFragment({ this.navigator, this.userData, this.updater }); | ||
|
||
final Navigator navigator; | ||
final UserData userData; | ||
final SettingsUpdater updater; | ||
Navigator navigator; | ||
UserData userData; | ||
SettingsUpdater updater; | ||
|
||
void syncFields(SettingsFragment source) { | ||
navigator = source.navigator; | ||
userData = source.userData; | ||
updater = source.updater; | ||
} | ||
|
||
void _handleBackupChanged(bool value) { | ||
if (updater != null) | ||
updater(backup: value ? BackupMode.enabled : BackupMode.disabled); | ||
assert(updater != null); | ||
updater(backup: value ? BackupMode.enabled : BackupMode.disabled); | ||
} | ||
|
||
void _goalWeightChanged(double value) { | ||
assert(updater != null); | ||
setState(() { | ||
optimism = value ? StockMode.optimistic : StockMode.pessimistic; | ||
}); | ||
sendUpdates(); | ||
} | ||
|
||
Widget buildToolBar() { | ||
|
@@ -30,6 +45,64 @@ class SettingsFragment extends Component { | |
); | ||
} | ||
|
||
String get goalWeightText { | ||
if (userData.goalWeight == null || userData.goalWeight == 0.0) | ||
return "None"; | ||
else | ||
return "${userData.goalWeight}"; | ||
} | ||
|
||
static final GlobalKey weightGoalKey = new GlobalKey(); | ||
|
||
double _goalWeight; | ||
|
||
void _handleGoalWeightChanged(String goalWeight) { | ||
// TODO(jackson): Looking for null characters to detect enter key is a hack | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might reference https://github.com/domokit/sky_engine/issues/574 in the comment. |
||
if (goalWeight.endsWith("\u{0}")) { | ||
navigator.pop(double.parse(goalWeight.replaceAll("\u{0}", ""))); | ||
} else { | ||
setState(() { | ||
try { | ||
_goalWeight = double.parse(goalWeight); | ||
} on FormatException { | ||
_goalWeight = 0.0; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
EventDisposition _handleGoalWeightPressed() { | ||
showDialog(navigator, (navigator) { | ||
return new Dialog( | ||
title: new Text("Goal Weight"), | ||
content: new Input( | ||
key: weightGoalKey, | ||
placeholder: 'Goal weight in lbs', | ||
keyboardType: KeyboardType_NUMBER, | ||
onChanged: _handleGoalWeightChanged | ||
), | ||
onDismiss: () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. () => navigator.pop(), |
||
navigator.pop(); | ||
}, | ||
actions: [ | ||
new FlatButton( | ||
child: new Text('CANCEL'), | ||
onPressed: () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onPressed: () => navigator.pop() |
||
navigator.pop(); | ||
} | ||
), | ||
new FlatButton( | ||
child: new Text('SAVE'), | ||
onPressed: () { | ||
navigator.pop(_goalWeight); | ||
} | ||
), | ||
] | ||
); | ||
}).then((double goalWeight) => updater(goalWeight: goalWeight)); | ||
return EventDisposition.processed; | ||
} | ||
|
||
Widget buildSettingsPane() { | ||
return new Material( | ||
type: MaterialType.canvas, | ||
|
@@ -43,7 +116,16 @@ class SettingsFragment extends Component { | |
new Flexible(child: new Text('Back up data to the cloud')), | ||
new Switch(value: userData.backupMode == BackupMode.enabled, onChanged: _handleBackupChanged) | ||
] | ||
) | ||
), | ||
new DrawerItem( | ||
onPressed: () => _handleGoalWeightPressed(), | ||
children: [ | ||
new Flex([ | ||
new Text('Goal Weight'), | ||
new Text(goalWeightText, style: Theme.of(this).text.caption), | ||
], direction: FlexDirection.vertical, alignItems: FlexAlignItems.start) | ||
] | ||
), | ||
]) | ||
) | ||
) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else is not needed here.