allow for reps and times

This commit is contained in:
Joshua Burman
2024-12-06 01:28:43 -05:00
parent 5bae1aa416
commit 56b25a6963
4 changed files with 166 additions and 84 deletions

View File

@ -15,6 +15,10 @@ class ActivityTimerModel with ChangeNotifier {
ActivityModel? get activity => _activity;
Timer? get periodicTimer => _periodicTimer;
String get actionType => _actionMap[_currentAction];
String get setType => _activity != null
? _activity!.actions[0].activityActionSet.reps.type
: 'n/a';
String? get repType => actionState();
void setup(ActivityModel activity) {
// if there isn't an activity yet
@ -27,20 +31,33 @@ class ActivityTimerModel with ChangeNotifier {
_actionMap = [];
// for now we just do alternating rest/sets
// in the future, we'll make this more modifiable
for (int i = 0; i < activity.actions[0].activityActionSet.total; i++) {
_actionMap.addAll(['Set', 'Rest']);
int totalActions = activity.actions[0].activityActionSet.total;
// log(activity.actions[0].activityActionSet.type);
// if (activity.actions[0].activityActionSet.type == 'alternating') {
// totalActions = totalActions * 4;
// log('were in $totalActions');
// }
for (int i = 0; i < totalActions; i++) {
_actionMap.addAll(['Set', 'Rest']);
}
getValue();
}
}
String actionState() {
if (actionType == 'Set') {
return setType == 'seconds' ? 'Seconds' : 'Repititions';
}
return 'Seconds';
}
void getValue() {
if (_actionMap[_currentAction] == "Rest") {
_tickCount = _activity!.actions[0].activityActionSet.rest ~/ 1000;
} else {
_tickCount = _activity!.actions[0].activityActionSet.reps.rest ~/ 1000;
_tickCount = _activity!.actions[0].activityActionSet.reps.amounts[0];
}
}
@ -51,7 +68,9 @@ class ActivityTimerModel with ChangeNotifier {
void setAction(int actionNum, String type) {
// always pause if we're manually taversing
if (type == 'manual') { pause(); }
if (type == 'manual' && setType == 'seconds') {
pause();
}
_currentAction = actionNum;
getValue();
notifyListeners();
@ -74,7 +93,7 @@ class ActivityTimerModel with ChangeNotifier {
Timer.periodic(const Duration(seconds: 1), (Timer timer) {
if (_tickCount <= 0) {
nextAction('automatic');
} else {
} else if (actionState() != 'Repititions') {
_tickCount--;
}
notifyListeners();