Skip to content

Commit

Permalink
more import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Desync-o-tron committed Oct 10, 2024
1 parent da42954 commit dfcebdc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 64 deletions.
128 changes: 73 additions & 55 deletions lib/importing/ex_match_listview.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:open_fitness_tracker/DOM/exercise_metadata.dart';
import 'package:open_fitness_tracker/common/common_widgets.dart';
import 'package:open_fitness_tracker/exercises/ex_search_page.dart';
import 'package:open_fitness_tracker/exercises/ex_tile.dart';
import 'package:open_fitness_tracker/importing/history_importing_cubits.dart';

//TODO give them a #/total cards on each card.
import 'package:open_fitness_tracker/navigation/routes.dart';

class MatchExercisesScrollView extends StatefulWidget {
final VoidCallback confirmSelections;
Expand Down Expand Up @@ -62,73 +62,89 @@ class _MatchExercisesScrollViewState extends State<MatchExercisesScrollView> {
),
const SizedBox(height: 10),
MyGenericButton(
onPressed: widget.confirmSelections,
onPressed: () {
widget.confirmSelections();
context.push(routeNames.History.text);
},
label: "Confirm Selections",
),
],
),
);
}

Widget _buildExerciseMatchTile(
int index,
) {
Widget _buildExerciseMatchTile(int index) {
ExerciseMatchCard exerciseMatch = exerciseMatches[index];

Color matchedExerciseBackgroundColor;
if (exerciseMatch.matchedExercise == null && !exerciseMatch.isConfirmed) {
matchedExerciseBackgroundColor = Colors.red.shade300;
} else if (exerciseMatch.isConfirmed) {
matchedExerciseBackgroundColor = Colors.greenAccent.shade400;
} else {
matchedExerciseBackgroundColor = Colors.yellow.shade300;
}

return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
child: Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8.0),
boxShadow: [
BoxShadow(
color: Colors.grey.shade200, offset: const Offset(0, 2), blurRadius: 4.0)
],
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Text(
'${index + 1} of ${exerciseMatches.length}',
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
),
child: Row(
children: [
Expanded(
child: Opacity(
opacity: exerciseMatch.bDiscard ? .33 : 1,
child: Column(
children: [
ExerciseTile(exercise: exerciseMatch.foreignExercise),
const SizedBox(height: 8.0),
_selectableExTile(
index, exerciseMatch, matchedExerciseBackgroundColor),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
child: Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8.0),
boxShadow: [
BoxShadow(
color: Colors.grey.shade200,
offset: const Offset(0, 2),
blurRadius: 4.0,
)
],
),
SizedBox(
width: 80,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_acceptSwitch(exerciseMatch),
_useMyNameSwitch(exerciseMatch),
_discardThisExSwitch(exerciseMatch),
],
),
child: Row(
children: [
Expanded(
child: Opacity(
opacity: exerciseMatch.bDiscard ? .33 : 1,
child: Column(
children: [
ExerciseTile(exercise: exerciseMatch.foreignExercise),
const SizedBox(height: 8.0),
_selectableExTile(index, exerciseMatch,
_getExerciseBackgroundColor(exerciseMatch)),
],
),
),
),
SizedBox(
width: 80,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_acceptSwitch(exerciseMatch),
_useMyNameSwitch(exerciseMatch),
_discardThisExSwitch(exerciseMatch),
],
),
),
],
),
],
),
),
),
],
);
}

Color _getExerciseBackgroundColor(ExerciseMatchCard exerciseMatch) {
if (exerciseMatch.matchedExercise == null && !exerciseMatch.isConfirmed) {
return Colors.red.shade300;
} else if (exerciseMatch.isConfirmed) {
return Colors.greenAccent.shade400;
} else {
return Colors.yellow.shade300;
}
}

Column _discardThisExSwitch(ExerciseMatchCard exerciseMatch) {
return Column(
children: [
Expand All @@ -154,8 +170,10 @@ class _MatchExercisesScrollViewState extends State<MatchExercisesScrollView> {
child: Text('Use my name?', textAlign: TextAlign.center),
),
Switch(
value:
(exerciseMatch.bDiscard) ? false : exerciseMatch.preferForeignExerciseName,
value: (exerciseMatch.bDiscard)
? false
: exerciseMatch.preferForeignExerciseName ||
(exerciseMatch.isConfirmed && exerciseMatch.matchedExercise == null),
onChanged: (bool value) {
if (exerciseMatch.bDiscard) return;
setState(() {
Expand Down
11 changes: 4 additions & 7 deletions lib/importing/import_inspection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class _ImportInspectionPageState extends State<ImportInspectionPage> {

if (matchPairs.isEmpty) {
matchPairs = _exerciseMatcher(newExs, exercisesState, 92);
context.read<ImportedExerciseMatchesCubit>().deleteAll();
context.read<ImportedExerciseMatchesCubit>().addMatches(matchPairs);
}
return Scaffold(
Expand Down Expand Up @@ -167,13 +168,9 @@ class _ImportInspectionPageState extends State<ImportInspectionPage> {
}
histCubit.loadUserTrainingHistory(useCache: true);

if (mounted) {
//i think this should be fine, what's a dialog going to do?
context.push(routeNames.History.text);
} else {
//todo error handling?
throw Exception("todo help me..import still worked, just go back");
}
//the user made it!
context.read<ImportedExerciseMatchesCubit>().deleteAll();
context.read<ImportedTrainingSessionsCubit>().deleteSessions();
}

Future<bool?> _confirmCreatingNewExercisesDialog(
Expand Down
4 changes: 2 additions & 2 deletions lib/navigation/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ enum routeNames {
final GoRouter appRouter = GoRouter(
errorBuilder: (context, state) => const ScaffoldWithNavBar(child: PageNotFoundPage()),
navigatorKey: _rootNavigatorKey,
initialLocation: routeNames.Temp.text,
// initialLocation: routeNames.Temp.text,
// initialLocation: routeNames.Training.text, //////////<--- This is the initial route
// initialLocation: routeNames.Exercises.text, //////////<--- This is the initial route
// initialLocation: routeNames.History.text, //////////<--- This is the initial route
initialLocation: routeNames.History.text, //////////<--- This is the initial route
// initialLocation: routeNames.Community.text, //////////<--- This is the initial route
routes: [
ShellRoute(
Expand Down

0 comments on commit dfcebdc

Please sign in to comment.