reset timer and activity when complete
This commit is contained in:
@@ -30,10 +30,6 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
setActionCount();
|
||||
}
|
||||
|
||||
bool _isActive() {
|
||||
return (_periodicTimer != null && _periodicTimer!.isActive) ? true : false;
|
||||
}
|
||||
|
||||
bool isCurrentItem(int setNum, int actionNum) {
|
||||
if (setNum == _currentSetNum && actionNum == _currentActionNum) {
|
||||
return true;
|
||||
@@ -44,7 +40,7 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
|
||||
int totalActions() {
|
||||
int count = 0;
|
||||
for(int i = 0; i < _sets.length; i++) {
|
||||
for (int i = 0; i < _sets.length; i++) {
|
||||
count = count + _sets[i].length as int;
|
||||
}
|
||||
|
||||
@@ -52,12 +48,14 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
void setActionCount() {
|
||||
_actionCounter = _sets[_currentSetNum][_currentActionNum]['amount'];
|
||||
_actionCounter = currentAction['amount'];
|
||||
}
|
||||
|
||||
void start() {
|
||||
_periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
|
||||
switch(currentAction['type']) {
|
||||
switch (currentAction['type']) {
|
||||
// we don't want to count down
|
||||
// if its repititions
|
||||
case 'repititions':
|
||||
break;
|
||||
case 'seconds':
|
||||
@@ -65,6 +63,7 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
_actionCounter--;
|
||||
} else {
|
||||
nextAction(_currentActionNum + 1);
|
||||
setActionCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,113 +77,22 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void nextAction(int nextActionID) {
|
||||
|
||||
void nextAction(int nextActionIndex) {
|
||||
if (currentSet.length > nextActionIndex) {
|
||||
setAction(_currentSetNum, nextActionIndex, 'automatic');
|
||||
} else if (_sets.length > _currentSetNum + 1) {
|
||||
// if the item isn't in the set
|
||||
// increment the set and reset action index
|
||||
setAction(_currentSetNum + 1, 0, 'automatic');
|
||||
} else {
|
||||
// if we're done all the sets
|
||||
// cancel timer and reset activity
|
||||
_periodicTimer!.cancel();
|
||||
setup(_activity!);
|
||||
}
|
||||
}
|
||||
|
||||
(int, int) _findAction(int actionID) {
|
||||
return (1, 2);
|
||||
bool _isActive() {
|
||||
return (_periodicTimer != null && _periodicTimer!.isActive) ? true : false;
|
||||
}
|
||||
|
||||
// void nextAction(String type) {
|
||||
// setAction(_currentActionNum + 1, _getSet(), type);
|
||||
// }
|
||||
|
||||
// int _actionCounter = 0;
|
||||
// int _currentAction = 0;
|
||||
// ActivityModel? _activity;
|
||||
// Timer? _periodicTimer;
|
||||
// List<String> _actionMap = [];
|
||||
|
||||
// int get actionCount => _actionCounter;
|
||||
// int get currentAction => _currentAction;
|
||||
// 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();
|
||||
// List get sets => _activity!.actions[0].items();
|
||||
|
||||
// void setup(ActivityModel activity) {
|
||||
// // if there isn't an activity yet
|
||||
// // or we're coming from another activity
|
||||
// // setup new timer
|
||||
// if (_activity == null || activity.id != _activity?.id) {
|
||||
// _periodicTimer?.cancel();
|
||||
// _activity = activity;
|
||||
// _currentAction = 0;
|
||||
// _actionMap = [];
|
||||
// // for now we just do alternating rest/sets
|
||||
// // in the future, we'll make this more modifiable
|
||||
// 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") {
|
||||
// _actionCounter = _activity!.actions[0].activityActionSet.rest ~/ 1000;
|
||||
// } else {
|
||||
// _actionCounter = _activity!.actions[0].activityActionSet.reps.amounts[0];
|
||||
// }
|
||||
// }
|
||||
|
||||
// void pause() {
|
||||
// _periodicTimer?.cancel();
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
// void setAction(int actionNum, String type) {
|
||||
// // always pause if we're manually taversing
|
||||
// if (type == 'manual' && setType == 'seconds') {
|
||||
// pause();
|
||||
// }
|
||||
// _currentAction = actionNum;
|
||||
// getValue();
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
// void nextAction(String type) {
|
||||
// _currentAction + 1 >= _actionMap.length
|
||||
// ? pause()
|
||||
// : setAction(_currentAction + 1, type);
|
||||
// }
|
||||
|
||||
// bool isActive() {
|
||||
// return (_periodicTimer != null && _periodicTimer!.isActive) ? true : false;
|
||||
// }
|
||||
|
||||
// void start() {
|
||||
// if (_activity != null) {
|
||||
// _periodicTimer?.cancel();
|
||||
// _periodicTimer =
|
||||
// Timer.periodic(const Duration(seconds: 1), (Timer timer) {
|
||||
// if (_actionCounter <= 0) {
|
||||
// nextAction('automatic');
|
||||
// } else if (actionState() != 'Repititions') {
|
||||
// _actionCounter--;
|
||||
// }
|
||||
// notifyListeners();
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user