upgraded dart and packages, analyze fixes, action type timer management
This commit is contained in:
@ -1,35 +1,36 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sendtrain/models/activity_model.dart';
|
||||
|
||||
class ActivityTimerModel with ChangeNotifier {
|
||||
int _actionCount = 0;
|
||||
int _actionCounter = 0;
|
||||
ActivityModel? _activity;
|
||||
List _actions = [];
|
||||
List _sets = [];
|
||||
int _currentActionNum = 0;
|
||||
int _currentSetNum = 0;
|
||||
Timer? _periodicTimer;
|
||||
|
||||
int get actionCount => _actionCount;
|
||||
int get actionCount => _actionCounter;
|
||||
int get currentActionNum => _currentActionNum;
|
||||
dynamic get currentAction => currentSet[_currentActionNum];
|
||||
int get currentSetNum => _currentSetNum;
|
||||
dynamic get currentSet => _sets[_currentSetNum];
|
||||
ActivityModel? get activity => _activity;
|
||||
List get actions => _actions;
|
||||
List get sets => _sets;
|
||||
Timer? get periodicTimer => _periodicTimer;
|
||||
String get currentActionType => _actions[_currentSetNum][_currentActionNum]['type'];
|
||||
bool get isActive => _isActive();
|
||||
void get pause => _periodicTimer!.cancel();
|
||||
|
||||
void setup(ActivityModel activity) {
|
||||
_activity = activity;
|
||||
_actions = activity.actions[0].items();
|
||||
_sets = activity.actions[0].items();
|
||||
_currentActionNum = 0;
|
||||
_currentSetNum = 0;
|
||||
setActionCount();
|
||||
}
|
||||
|
||||
bool isActive() {
|
||||
bool _isActive() {
|
||||
return (_periodicTimer != null && _periodicTimer!.isActive) ? true : false;
|
||||
}
|
||||
|
||||
@ -43,20 +44,30 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
|
||||
int totalActions() {
|
||||
int count = 0;
|
||||
for(int i = 0; i < _actions.length; i++) {
|
||||
count = count + _actions[i].length as int;
|
||||
for(int i = 0; i < _sets.length; i++) {
|
||||
count = count + _sets[i].length as int;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void setActionCount() {
|
||||
_actionCount = _actions[_currentSetNum][_currentActionNum]['amount'];
|
||||
_actionCounter = _sets[_currentSetNum][_currentActionNum]['amount'];
|
||||
}
|
||||
|
||||
void start() {
|
||||
_periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
|
||||
_actionCount--;
|
||||
switch(currentAction['type']) {
|
||||
case 'repititions':
|
||||
break;
|
||||
case 'seconds':
|
||||
if (_actionCounter > 0) {
|
||||
_actionCounter--;
|
||||
} else {
|
||||
nextAction(_currentActionNum + 1);
|
||||
}
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
@ -67,17 +78,25 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void nextAction(int nextActionID) {
|
||||
|
||||
}
|
||||
|
||||
(int, int) _findAction(int actionID) {
|
||||
return (1, 2);
|
||||
}
|
||||
|
||||
// void nextAction(String type) {
|
||||
// setAction(_currentActionNum + 1, _getSet(), type);
|
||||
// }
|
||||
|
||||
// int _actionCount = 0;
|
||||
// int _actionCounter = 0;
|
||||
// int _currentAction = 0;
|
||||
// ActivityModel? _activity;
|
||||
// Timer? _periodicTimer;
|
||||
// List<String> _actionMap = [];
|
||||
|
||||
// int get actionCount => _actionCount;
|
||||
// int get actionCount => _actionCounter;
|
||||
// int get currentAction => _currentAction;
|
||||
// ActivityModel? get activity => _activity;
|
||||
// Timer? get periodicTimer => _periodicTimer;
|
||||
@ -123,9 +142,9 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
|
||||
// void getValue() {
|
||||
// if (_actionMap[_currentAction] == "Rest") {
|
||||
// _actionCount = _activity!.actions[0].activityActionSet.rest ~/ 1000;
|
||||
// _actionCounter = _activity!.actions[0].activityActionSet.rest ~/ 1000;
|
||||
// } else {
|
||||
// _actionCount = _activity!.actions[0].activityActionSet.reps.amounts[0];
|
||||
// _actionCounter = _activity!.actions[0].activityActionSet.reps.amounts[0];
|
||||
// }
|
||||
// }
|
||||
|
||||
@ -159,10 +178,10 @@ class ActivityTimerModel with ChangeNotifier {
|
||||
// _periodicTimer?.cancel();
|
||||
// _periodicTimer =
|
||||
// Timer.periodic(const Duration(seconds: 1), (Timer timer) {
|
||||
// if (_actionCount <= 0) {
|
||||
// if (_actionCounter <= 0) {
|
||||
// nextAction('automatic');
|
||||
// } else if (actionState() != 'Repititions') {
|
||||
// _actionCount--;
|
||||
// _actionCounter--;
|
||||
// }
|
||||
// notifyListeners();
|
||||
// });
|
||||
|
Reference in New Issue
Block a user