diff --git a/lib/classes/activity_action.dart b/lib/classes/activity_action.dart index 6fd7a5a..78d6f20 100644 --- a/lib/classes/activity_action.dart +++ b/lib/classes/activity_action.dart @@ -18,7 +18,7 @@ class ActivityAction { List>> items() { List>> sets = []; Reps reps = activityActionSet.reps; - int totalActions = 1; + int totalActions = 0; for (int i = 0; i < activityActionSet.total; i++) { List> actions = []; @@ -38,7 +38,7 @@ class ActivityAction { 'actionID': totalActions++, 'name': 'Rest', 'type': 'seconds', - 'amount': reps.amounts[i], + 'amount': reps.rest! ~/ 1000, }); } @@ -60,6 +60,13 @@ class ActivityAction { sets.add(actions); + // sets.add([{ + // 'actionID': totalActions++, + // 'name': 'Rest', + // 'type': 'seconds', + // 'amount': activityActionSet.rest ~/ 1000, + // }]); + // for (int j = 0; i < activityActionSet.reps.amounts; j++) {} } diff --git a/lib/models/activity_timer_model.dart b/lib/models/activity_timer_model.dart index e4e3cb0..2126a4d 100644 --- a/lib/models/activity_timer_model.dart +++ b/lib/models/activity_timer_model.dart @@ -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 _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(); - // }); - // } - // } } diff --git a/lib/widgets/activity_action_view.dart b/lib/widgets/activity_action_view.dart index 794b81a..3fef92b 100644 --- a/lib/widgets/activity_action_view.dart +++ b/lib/widgets/activity_action_view.dart @@ -44,7 +44,7 @@ class ActivityActionViewState extends State { ? Theme.of(context).colorScheme.primaryContainer : Theme.of(context).colorScheme.onPrimary, child: - Text(textAlign: TextAlign.center, 'Set ${setNum + 1} ')), + Text(textAlign: TextAlign.center, '${setNum + 1}.${actionNum + 1} ')), Expanded( child: Ink( padding: const EdgeInsets.all(15), diff --git a/lib/widgets/activity_view.dart b/lib/widgets/activity_view.dart index 2ed711c..8ad6664 100644 --- a/lib/widgets/activity_view.dart +++ b/lib/widgets/activity_view.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:provider/provider.dart'; import 'package:sendtrain/classes/activity_action.dart'; import 'package:sendtrain/classes/media.dart'; @@ -54,132 +55,65 @@ class _ActivityViewState extends State { style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), 'Actions:')), Padding( - padding: const EdgeInsets.only(left: 10, right: 10), - child: Card( - clipBehavior: Clip.antiAlias, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)), - ), - color: Theme.of(context).colorScheme.onPrimary, - child: Padding( - padding: const EdgeInsets.only(left: 0, right: 0), - child: Row(children: [ - // LinearProgressIndicator( - // value: 0.5, - // minHeight: 100, - // color: Theme.of(context).colorScheme.error, - // semanticsLabel: 'Linear progress indicator', - // ), - // Expanded( - // flex: 1, - // child: Flex(direction: Axis.horizontal, children: [ - // Consumer(builder: (context, atm, child) { - // return IconButton( - // iconSize: 30, - // icon: atm.isActive() - // ? const Icon(Icons.pause_rounded) - // : const Icon(Icons.play_arrow_rounded), - // onPressed: () => - // {atm.isActive() ? atm.pause : atm.start()}); - // }), - // // IconButton( - // // // iconSize: 36, - // // icon: const Icon(Icons.skip_next_rounded), - // // onPressed: () { - // // atm.nextAction('manual'); - // // }) - // ])), - Ink( - width: 70, - color: Theme.of(context).colorScheme.primaryContainer, - child: Consumer( - builder: (context, atm, child) { - return IconButton( - alignment: AlignmentDirectional.center, - iconSize: 30, - icon: atm.isActive - ? const Icon(Icons.pause_rounded) - : const Icon(Icons.play_arrow_rounded), - onPressed: () => - {atm.isActive ? atm.pause : atm.start()}); - }, - )), - Expanded( - flex: 2, - child: Consumer( - builder: (context, atm, child) { - return Text( - style: const TextStyle(fontSize: 20), - textAlign: TextAlign.right, - '${atm.actionCount} ${atm.currentAction['type']}'); - }, - )), - Expanded( - flex: 1, - child: Padding( - padding: const EdgeInsets.only(right: 15), - child: Consumer( - builder: (context, atm, child) { - return Text( - style: const TextStyle(fontSize: 15), - textAlign: TextAlign.right, - '${atm.currentAction['actionID']} | ${atm.totalActions()}'); - // 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}'); - }))), - ])))), + padding: const EdgeInsets.only(left: 10, right: 10), + child: Card( + clipBehavior: Clip.antiAlias, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(10), + topRight: Radius.circular(10)), + ), + color: Theme.of(context).colorScheme.onPrimary, + child: Row(children: [ + // LinearProgressIndicator( + // value: 0.5, + // minHeight: 100, + // color: Theme.of(context).colorScheme.error, + // semanticsLabel: 'Linear progress indicator', + // ), + Ink( + width: 70, + color: Theme.of(context).colorScheme.primaryContainer, + child: Consumer( + builder: (context, atm, child) { + return IconButton( + alignment: AlignmentDirectional.center, + iconSize: 30, + icon: atm.isActive + ? const Icon(Icons.pause_rounded) + : const Icon(Icons.play_arrow_rounded), + onPressed: () => + {atm.isActive ? atm.pause : atm.start()}); + }, + )), + Expanded( + flex: 1, + child: Stack(alignment: Alignment.center, children: [ + Container( + alignment: Alignment.center, + child: Consumer( + builder: (context, atm, child) { + return Text( + style: const TextStyle(fontSize: 20), + textAlign: TextAlign.center, + '${atm.actionCount} ${atm.currentAction['type']}'); + }, + ), + ), + Container( + alignment: Alignment.centerRight, + padding: EdgeInsets.only(right: 10), + child: Consumer( + builder: (context, atm, child) { + return Text( + style: const TextStyle(fontSize: 15), + textAlign: TextAlign.right, + '${atm.currentAction['actionID'] + 1} | ${atm.totalActions()}'); + // 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}'); + })), + ])), + ]))), ActivityActionView(action: activity.actions[0]), - // Container( - // height: MediaQuery.sizeOf(context).height * .07, - // color: Theme.of(context).colorScheme.primaryContainer, - // child: Row(children: [ - // // LinearProgressIndicator( - // // value: 0.5, - // // minHeight: 100, - // // color: Theme.of(context).colorScheme.error, - // // semanticsLabel: 'Linear progress indicator', - // // ), - // Expanded( - // flex: 1, - // child: Flex(direction: Axis.horizontal, children: [ - // Consumer(builder: (context, atm, child) { - // return IconButton( - // iconSize: 30, - // icon: atm.isActive() - // ? const Icon(Icons.pause_rounded) - // : const Icon(Icons.play_arrow_rounded), - // onPressed: () => - // {atm.isActive() ? atm.pause() : atm.start()}); - // }), - // IconButton( - // iconSize: 36, - // icon: const Icon(Icons.skip_next_rounded), - // onPressed: () { - // atm.nextAction('manual'); - // }) - // ])), - // Expanded( - // flex: 1, - // child: Consumer( - // builder: (context, atm, child) { - // return Text( - // style: const TextStyle(fontSize: 20), - // textAlign: TextAlign.center, - // '${atm.actionCount} ${atm.actionState()}'); - // }, - // )), - // Expanded( - // flex: 1, - // child: Padding( - // padding: const EdgeInsets.only(right: 15), - // child: Consumer( - // builder: (context, atm, child) { - // return Text( - // style: const TextStyle(fontSize: 20), - // textAlign: TextAlign.right, - // '${atm.currentAction + 1}: ${atm.actionType}'); - // // 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}'); - // }))), - // ])) ]); } } diff --git a/lib/widgets/session_card.dart b/lib/widgets/session_card.dart index b11b3de..162b20d 100644 --- a/lib/widgets/session_card.dart +++ b/lib/widgets/session_card.dart @@ -131,13 +131,13 @@ class SessionCard extends StatelessWidget { activityActionSet: Set( type: 'alternating', total: 5, - rest: 300000, + rest: 5000, reps: Reps( type: 'seconds', tempo: [0], - amounts: [60, 60, 60, 60, 60], + amounts: [5, 5, 5, 5, 5], weights: [80, 80, 80, 80, 80], - rest: 0))), + rest: 5000))), ], resources: ['https://www.youtube.com/watch?v=dyAvbUvY_PU']), ],