rework timer and how we manage actions

This commit is contained in:
Joshua Burman
2024-12-06 17:33:33 -05:00
parent 56b25a6963
commit 19f835d8f2
4 changed files with 385 additions and 150 deletions

View File

@ -21,74 +21,107 @@ class ActivityActionViewState extends State<ActivityActionView> {
int actionCount = 0;
ActivityTimerModel atm =
Provider.of<ActivityTimerModel>(context, listen: true);
List<List<Map<String, dynamic>>> sets = atm.activity!.actions[0].items();
return Expanded(
child: ListView.builder(
padding: const EdgeInsets.fromLTRB(10, 0, 20, 0),
padding: const EdgeInsets.fromLTRB(10, 0, 10, 20),
itemCount: widget.action.activityActionSet.total,
itemBuilder: (BuildContext context, int index) {
itemBuilder: (BuildContext context, int setNum) {
String title = widget.action.title;
Set actionSet = widget.action.activityActionSet;
Reps setReps = actionSet.reps;
int setRest = actionSet.rest ~/ 1000;
int currentAction = actionCount;
int currentAction = 0;
List<GestureDetector> content = [];
actionCount = actionCount + 2;
content.addAll([
GestureDetector(
List<Map<String, dynamic>> set = sets[setNum];
// log('${sets.length}');
// log('${set.length}');
for (int actionNum = 0; actionNum < set.length; actionNum++) {
Map<String, dynamic> setItem = set[actionNum];
content.add(GestureDetector(
onTap: () {
setState(() {
atm.setAction(currentAction, 'manual');
});
atm.setAction(setNum, actionNum, 'manual');
atm.setActionCount();
},
child: Row(children: [
Consumer<ActivityTimerModel>(builder: (context, atm, child) {
return Ink(
width: 100,
padding: const EdgeInsets.all(15),
color: currentAction == atm.currentAction
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.onPrimary,
child: Text('Set ${index + 1} '));
}),
Ink(
// width: 90,
padding: const EdgeInsets.all(15),
color: atm.isCurrentItem(setNum, actionNum)
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.onPrimary,
child:
Text(textAlign: TextAlign.right, 'Set ${setNum + 1} ')),
Expanded(
child: Ink(
padding: const EdgeInsets.all(15),
color: currentAction == atm.currentAction
color: atm.isCurrentItem(setNum, actionNum)
? Theme.of(context).colorScheme.surfaceBright
: Theme.of(context).colorScheme.surfaceContainerLow,
child: Text(
textAlign: TextAlign.center,
'$title: ${setReps.amounts[index]} ${atm.setType}')))
])),
GestureDetector(
onTap: () {
setState(() {
atm.setAction(currentAction + 1, 'manual');
});
},
child: Row(children: [
Consumer<ActivityTimerModel>(builder: (context, atm, child) {
return Ink(
width: 100,
padding: const EdgeInsets.all(15),
color: currentAction + 1 == atm.currentAction
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.onPrimary,
child: Text('Rest ${index + 1}'));
}),
Expanded(
child: Ink(
padding: const EdgeInsets.all(15),
color: currentAction + 1 == atm.currentAction
? Theme.of(context).colorScheme.surfaceBright
: Theme.of(context).colorScheme.surfaceContainerLow,
child: Text(
textAlign: TextAlign.center,
'Rest: $setRest seconds')))
])),
]);
'${setItem['name']}: ${setItem['amount']} ${setItem['type']}')))
])));
}
// actionCount = actionCount + 2;
// content.addAll([
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// width: 90,
// padding: const EdgeInsets.all(15),
// color: currentAction == atm.currentAction
// ? Theme.of(context).colorScheme.primaryContainer
// : Theme.of(context).colorScheme.onPrimary,
// child: Text(textAlign: TextAlign.right,'Set ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction == atm.currentAction
// ? Theme.of(context).colorScheme.surfaceBright
// : Theme.of(context).colorScheme.surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// '$title: ${setReps.amounts[index]} ${atm.setType}')))
// ])),
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 1, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// width: 90,
// padding: const EdgeInsets.all(15),
// color: currentAction + 1 == atm.currentAction
// ? Theme.of(context).colorScheme.primaryContainer
// : Theme.of(context).colorScheme.onPrimary,
// child: Text(textAlign: TextAlign.right,'Rest ${index + 1}'));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 1 == atm.currentAction
// ? Theme.of(context).colorScheme.surfaceBright
// : Theme.of(context).colorScheme.surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// 'Rest: $setRest seconds')))
// ])),
// ]);
// if (actionSet.type == 'alternating') {
// actionCount = actionCount + 2;
@ -150,9 +183,29 @@ class ActivityActionViewState extends State<ActivityActionView> {
// ]);
// }
return Card(
clipBehavior: Clip.antiAlias, child: Column(children: content));
if (setNum == 0) {
return Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(0),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
),
clipBehavior: Clip.antiAlias,
child: Column(children: content));
} else {
return Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
),
clipBehavior: Clip.antiAlias,
child: Column(children: content));
}
// return Column(children: contents);
},
));

View File

@ -53,10 +53,13 @@ class _ActivityViewState extends State<ActivityView> {
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
'Actions:')),
ActivityActionView(action: activity.actions[0]),
Container(
height: MediaQuery.sizeOf(context).height * .07,
color: Theme.of(context).colorScheme.primaryContainer,
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Card(
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,
@ -69,19 +72,19 @@ class _ActivityViewState extends State<ActivityView> {
child: Flex(direction: Axis.horizontal, children: [
Consumer<ActivityTimerModel>(builder: (context, atm, child) {
return IconButton(
iconSize: 30,
// iconSize: 30,
icon: atm.isActive()
? const Icon(Icons.pause_rounded)
: const Icon(Icons.play_arrow_rounded),
onPressed: () =>
{atm.isActive() ? atm.pause() : atm.start()});
{atm.isActive() ? atm.pause : atm.start()});
}),
IconButton(
iconSize: 36,
icon: const Icon(Icons.skip_next_rounded),
onPressed: () {
atm.nextAction('manual');
})
// IconButton(
// // iconSize: 36,
// icon: const Icon(Icons.skip_next_rounded),
// onPressed: () {
// atm.nextAction('manual');
// })
])),
Expanded(
flex: 1,
@ -90,7 +93,7 @@ class _ActivityViewState extends State<ActivityView> {
return Text(
style: const TextStyle(fontSize: 20),
textAlign: TextAlign.center,
'${atm.tickCount} ${atm.actionState()}');
'${atm.actionCount} ${atm.currentActionType}');
},
)),
Expanded(
@ -102,10 +105,63 @@ class _ActivityViewState extends State<ActivityView> {
return Text(
style: const TextStyle(fontSize: 20),
textAlign: TextAlign.right,
'${atm.currentAction + 1}: ${atm.actionType}');
'${atm.currentActionNum + 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<ActivityTimerModel>(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<ActivityTimerModel>(
// 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<ActivityTimerModel>(
// 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}');
// }))),
// ]))
]);
}
}