alternating timer types
This commit is contained in:
parent
29479e8aba
commit
5bae1aa416
@ -1,148 +1,84 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sendtrain/models/activity_model.dart';
|
import 'package:sendtrain/models/activity_model.dart';
|
||||||
import 'package:sendtrain/widgets/activity_action_view.dart';
|
|
||||||
|
|
||||||
class ActivityTimerModel with ChangeNotifier {
|
class ActivityTimerModel with ChangeNotifier {
|
||||||
late int _activityId;
|
int _tickCount = 0;
|
||||||
late int _tickCount;
|
|
||||||
late int _currentSet;
|
|
||||||
late int _totalSets;
|
|
||||||
late int _currentRep;
|
|
||||||
late int _totalReps;
|
|
||||||
late String _currentState;
|
|
||||||
late Timer? _periodicTimer;
|
|
||||||
late ActivityModel _activity;
|
|
||||||
|
|
||||||
// int _viewCount = 0;
|
|
||||||
bool _active = false;
|
|
||||||
int _currentAction = 0;
|
int _currentAction = 0;
|
||||||
|
ActivityModel? _activity;
|
||||||
|
Timer? _periodicTimer;
|
||||||
|
List<String> _actionMap = [];
|
||||||
|
|
||||||
int get tickCount => _tickCount;
|
int get tickCount => _tickCount;
|
||||||
int get currentSet => _currentSet;
|
|
||||||
int get currentRep => _currentRep;
|
|
||||||
int get currentAction => _currentAction;
|
int get currentAction => _currentAction;
|
||||||
int get totalSets => _totalSets;
|
ActivityModel? get activity => _activity;
|
||||||
int get totalReps => _totalReps;
|
Timer? get periodicTimer => _periodicTimer;
|
||||||
bool get active => _active;
|
String get actionType => _actionMap[_currentAction];
|
||||||
|
|
||||||
void setAction(int actionNum, int setNum, String state) {
|
void setup(ActivityModel activity) {
|
||||||
_currentAction = actionNum;
|
// if there isn't an activity yet
|
||||||
_currentSet = setNum;
|
// or we're coming from another activity
|
||||||
_currentState = state;
|
// setup new timer
|
||||||
stopTimer();
|
if (_activity == null || activity.id != _activity?.id) {
|
||||||
|
_periodicTimer?.cancel();
|
||||||
if (_currentState == "rest") {
|
|
||||||
startTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void incrementAction() {
|
|
||||||
_currentAction++;
|
|
||||||
|
|
||||||
if (_currentState == "rest") {
|
|
||||||
_currentState = "rep";
|
|
||||||
_currentSet++;
|
|
||||||
stopTimer();
|
|
||||||
} else {
|
|
||||||
_currentState = "rest";
|
|
||||||
startTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupTimer(ActivityModel activity) {
|
|
||||||
_activity = activity;
|
_activity = activity;
|
||||||
_activityId = activity.id;
|
_currentAction = 0;
|
||||||
_currentSet = 0;
|
_actionMap = [];
|
||||||
_currentRep = 0;
|
// for now we just do alternating rest/sets
|
||||||
_totalSets = activity.actions[0].activityActionSet.total;
|
// in the future, we'll make this more modifiable
|
||||||
_totalReps = activity.actions[0].activityActionSet.reps.amounts[0];
|
for (int i = 0; i < activity.actions[0].activityActionSet.total; i++) {
|
||||||
_tickCount = activity.actions[0].activityActionSet.rest ~/ 10000;
|
_actionMap.addAll(['Set', 'Rest']);
|
||||||
_currentState = "rep";
|
|
||||||
// ActivityActionView av = actionViews[_viewCount];
|
}
|
||||||
// av.
|
getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pauseTimer() {
|
void getValue() {
|
||||||
_active = false;
|
if (_actionMap[_currentAction] == "Rest") {
|
||||||
notifyListeners();
|
_tickCount = _activity!.actions[0].activityActionSet.rest ~/ 1000;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_tickCount = _activity!.actions[0].activityActionSet.reps.rest ~/ 1000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopTimer() {
|
void pause() {
|
||||||
_active = false;
|
|
||||||
_periodicTimer?.cancel();
|
_periodicTimer?.cancel();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startTimer() {
|
void setAction(int actionNum, String type) {
|
||||||
if (_currentState == 'rep') {
|
// always pause if we're manually taversing
|
||||||
// do nothing for now
|
if (type == 'manual') { 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 (_tickCount <= 0) {
|
||||||
|
nextAction('automatic');
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
_active = true;
|
|
||||||
_tickCount = _activity.actions[0].activityActionSet.rest ~/ 10000;
|
|
||||||
|
|
||||||
_periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
|
|
||||||
if (_tickCount == 0) {
|
|
||||||
incrementAction();
|
|
||||||
|
|
||||||
|
|
||||||
// if (_currentRep + 1 ==
|
|
||||||
// _activity.actions[0].activityActionSet.reps.amounts[_currentSet]) {
|
|
||||||
// _currentSet++;
|
|
||||||
// if (_currentSet == _activity.actions[0].activityActionSet.total) {
|
|
||||||
// timer.cancel();
|
|
||||||
// _active = false;
|
|
||||||
// setupTimer(_activity);
|
|
||||||
// }
|
|
||||||
// _currentRep = 0;
|
|
||||||
// _totalReps =
|
|
||||||
// _activity.actions[0].activityActionSet.reps.amounts[_currentSet];
|
|
||||||
// _tickCount = _activity.actions[0].activityActionSet.rest ~/ 10000;
|
|
||||||
// } else {
|
|
||||||
// _currentRep++;
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
if (_active) {
|
|
||||||
_tickCount--;
|
_tickCount--;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void startTimer(ActivityModel activity) {
|
|
||||||
// _active = true;
|
|
||||||
// _periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
|
|
||||||
// if (_tickCount == 0) {
|
|
||||||
// if (_currentRep + 1 ==
|
|
||||||
// activity.actions[0].activityActionSet.reps.amounts[_currentSet]) {
|
|
||||||
// _currentSet++;
|
|
||||||
// if (_currentSet == activity.actions[0].activityActionSet.total) {
|
|
||||||
// timer.cancel();
|
|
||||||
// _active = false;
|
|
||||||
// setupTimer(activity);
|
|
||||||
// }
|
|
||||||
// _currentRep = 0;
|
|
||||||
// _totalReps =
|
|
||||||
// activity.actions[0].activityActionSet.reps.amounts[_currentSet];
|
|
||||||
// _tickCount = activity.actions[0].activityActionSet.rest ~/ 10000;
|
|
||||||
// } else {
|
|
||||||
// _currentRep++;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// _tickCount--;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// notifyListeners();
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -9,38 +9,18 @@ import 'package:sendtrain/widgets/action_card.dart';
|
|||||||
|
|
||||||
class ActivityActionView extends StatefulWidget {
|
class ActivityActionView extends StatefulWidget {
|
||||||
ActivityActionView({super.key, required this.action});
|
ActivityActionView({super.key, required this.action});
|
||||||
|
|
||||||
ActivityAction action;
|
ActivityAction action;
|
||||||
// ActivityTimerModel activityTimerModel;
|
|
||||||
// get incrementActivity => ActivityActionViewState().incrementActivity();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ActivityActionView> createState() => ActivityActionViewState();
|
State<ActivityActionView> createState() => ActivityActionViewState();
|
||||||
// void incrementActivity() => _ActivityActionViewState().incrementActivity();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ActivityActionViewState extends State<ActivityActionView> {
|
class ActivityActionViewState extends State<ActivityActionView> {
|
||||||
int _index = 0;
|
|
||||||
int _currentAction = 0;
|
|
||||||
// int _actionCount = 0;
|
|
||||||
// int _currentState = "Active"
|
|
||||||
|
|
||||||
// void incrementActivity(int actionNum) {
|
|
||||||
// setState(() {
|
|
||||||
// atm.setAction(actionNum);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void setActivity(int currentAction) {
|
|
||||||
// setState(() {
|
|
||||||
// widget.atm.setAction(currentAction);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
int actionCount = 0;
|
int actionCount = 0;
|
||||||
ActivityTimerModel atm = Provider.of<ActivityTimerModel>(context, listen: true);
|
ActivityTimerModel atm =
|
||||||
|
Provider.of<ActivityTimerModel>(context, listen: true);
|
||||||
|
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
@ -56,13 +36,15 @@ class ActivityActionViewState extends State<ActivityActionView> {
|
|||||||
|
|
||||||
contents.add(Card(
|
contents.add(Card(
|
||||||
elevation: 0.5,
|
elevation: 0.5,
|
||||||
// surfaceTintColor: actionCount == _index ? Colors.white : ,
|
shadowColor: Theme.of(context).colorScheme.shadow,
|
||||||
|
color: currentAction == atm.currentAction
|
||||||
|
? Theme.of(context).colorScheme.secondaryContainer
|
||||||
|
: Theme.of(context).colorScheme.onSecondary,
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
log('we tappn');
|
|
||||||
setState(() {
|
setState(() {
|
||||||
atm.setAction(currentAction, index, "rep");
|
atm.setAction(currentAction, 'manual');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
@ -70,8 +52,8 @@ class ActivityActionViewState extends State<ActivityActionView> {
|
|||||||
return Ink(
|
return Ink(
|
||||||
padding: const EdgeInsets.all(15),
|
padding: const EdgeInsets.all(15),
|
||||||
color: currentAction == atm.currentAction
|
color: currentAction == atm.currentAction
|
||||||
? const Color.fromARGB(255, 49, 154, 52)
|
? Theme.of(context).colorScheme.onPrimary
|
||||||
: const Color(0xff3A5FB6),
|
: Theme.of(context).colorScheme.primaryContainer,
|
||||||
child: Text('Set: ${index + 1} '));
|
child: Text('Set: ${index + 1} '));
|
||||||
}),
|
}),
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -82,11 +64,14 @@ class ActivityActionViewState extends State<ActivityActionView> {
|
|||||||
actionCount++;
|
actionCount++;
|
||||||
|
|
||||||
contents.add(Card(
|
contents.add(Card(
|
||||||
|
color: currentAction + 1 == atm.currentAction
|
||||||
|
? Theme.of(context).colorScheme.secondaryContainer
|
||||||
|
: Theme.of(context).colorScheme.onSecondary,
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
atm.setAction(currentAction + 1, index, "rest");
|
atm.setAction(currentAction + 1, 'manual');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
@ -94,8 +79,8 @@ class ActivityActionViewState extends State<ActivityActionView> {
|
|||||||
return Ink(
|
return Ink(
|
||||||
padding: const EdgeInsets.all(15),
|
padding: const EdgeInsets.all(15),
|
||||||
color: currentAction + 1 == atm.currentAction
|
color: currentAction + 1 == atm.currentAction
|
||||||
? const Color.fromARGB(255, 49, 154, 52)
|
? Theme.of(context).colorScheme.onPrimary
|
||||||
: const Color(0xff3A5FB6),
|
: Theme.of(context).colorScheme.primaryContainer,
|
||||||
child: Text('Set: ${index + 1} '));
|
child: Text('Set: ${index + 1} '));
|
||||||
}),
|
}),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
@ -21,12 +21,8 @@ class _ActivityViewState extends State<ActivityView> {
|
|||||||
ActivityModel activity = widget.activity;
|
ActivityModel activity = widget.activity;
|
||||||
ActivityTimerModel atm =
|
ActivityTimerModel atm =
|
||||||
Provider.of<ActivityTimerModel>(context, listen: false);
|
Provider.of<ActivityTimerModel>(context, listen: false);
|
||||||
// ActivityActionView activityActionView =
|
|
||||||
// ActivityActionView(action: activity.actions[0]);
|
|
||||||
|
|
||||||
if (atm.active == false) {
|
atm.setup(activity);
|
||||||
atm.setupTimer(activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
AppBar(
|
AppBar(
|
||||||
@ -60,23 +56,31 @@ class _ActivityViewState extends State<ActivityView> {
|
|||||||
ActivityActionView(action: activity.actions[0]),
|
ActivityActionView(action: activity.actions[0]),
|
||||||
Container(
|
Container(
|
||||||
height: MediaQuery.sizeOf(context).height * .07,
|
height: MediaQuery.sizeOf(context).height * .07,
|
||||||
color:
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
ThemeData.dark(useMaterial3: true).colorScheme.primaryContainer,
|
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
|
// LinearProgressIndicator(
|
||||||
|
// value: 0.5,
|
||||||
|
// minHeight: 100,
|
||||||
|
// color: Theme.of(context).colorScheme.error,
|
||||||
|
// semanticsLabel: 'Linear progress indicator',
|
||||||
|
// ),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
child: Flex(direction: Axis.horizontal, children: [
|
child: Flex(direction: Axis.horizontal, children: [
|
||||||
IconButton(
|
Consumer<ActivityTimerModel>(builder: (context, atm, child) {
|
||||||
|
return IconButton(
|
||||||
iconSize: 30,
|
iconSize: 30,
|
||||||
icon: const Icon(Icons.play_arrow_rounded),
|
icon: atm.isActive()
|
||||||
onPressed: () => {
|
? const Icon(Icons.pause_rounded)
|
||||||
atm.startTimer()
|
: const Icon(Icons.play_arrow_rounded),
|
||||||
|
onPressed: () =>
|
||||||
|
{atm.isActive() ? atm.pause() : atm.start()});
|
||||||
}),
|
}),
|
||||||
IconButton(
|
IconButton(
|
||||||
iconSize: 36,
|
iconSize: 36,
|
||||||
icon: const Icon(Icons.skip_next_rounded),
|
icon: const Icon(Icons.skip_next_rounded),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
atm.incrementAction();
|
atm.nextAction('manual');
|
||||||
})
|
})
|
||||||
])),
|
])),
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -96,9 +100,10 @@ class _ActivityViewState extends State<ActivityView> {
|
|||||||
child: Consumer<ActivityTimerModel>(
|
child: Consumer<ActivityTimerModel>(
|
||||||
builder: (context, atm, child) {
|
builder: (context, atm, child) {
|
||||||
return Text(
|
return Text(
|
||||||
style: const TextStyle(fontSize: 15),
|
style: const TextStyle(fontSize: 20),
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}');
|
"${atm.actionType}");
|
||||||
|
// 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}');
|
||||||
}))),
|
}))),
|
||||||
]))
|
]))
|
||||||
]);
|
]);
|
||||||
|
@ -67,7 +67,7 @@ class SessionCard extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
resources: ['https://www.youtube.com/watch?v=bLz0xp1PEm4']),
|
resources: ['https://www.youtube.com/watch?v=bLz0xp1PEm4']),
|
||||||
ActivityModel(
|
ActivityModel(
|
||||||
id: 1,
|
id: 2,
|
||||||
title: 'Projecting',
|
title: 'Projecting',
|
||||||
type: 'fundamental',
|
type: 'fundamental',
|
||||||
categories: ['technique', 'conditioning'],
|
categories: ['technique', 'conditioning'],
|
||||||
@ -104,7 +104,7 @@ class SessionCard extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
resources: ['https://www.youtube.com/watch?v=dyAvbUvY_PU']),
|
resources: ['https://www.youtube.com/watch?v=dyAvbUvY_PU']),
|
||||||
ActivityModel(
|
ActivityModel(
|
||||||
id: 1,
|
id: 3,
|
||||||
title: 'Weighted Pull Ups',
|
title: 'Weighted Pull Ups',
|
||||||
type: 'fundamental',
|
type: 'fundamental',
|
||||||
categories: ['Strength', 'Power'],
|
categories: ['Strength', 'Power'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user