public void Setup(){ mockStaffMemberDataRepository = new Mock<IStaffMember> (); //mockCurrentConnecitivity = new Mock<IConnectivity> (); mockExercise = new Mock<IExercise> (); //Set up a template folder templateFolder = new TemplateFolder (); //Create a simple template TemplateViewModel simpleTemplate = new TemplateViewModel (); simpleTemplate.TemplateName = "Back Blaster"; simpleTemplate.TemplateDescription = "Back Blaster Description"; templateFolder.Template = simpleTemplate; //Create 2 simple exercise objects ExerciseViewModel exercise1 = new ExerciseViewModel (); exercise1.SetsIndex= 1; exercise1.RepsIndex = 2; exercise1.WeightIndex = 2; exercise1.SeatPosition1Label = 1; exercise1.SeatPosition1Value = 1; ExerciseViewModel exercise2 = new ExerciseViewModel (); exercise1.SetsIndex = 2; exercise1.RepsIndex = 1; exercise1.WeightIndex = 2; exercise1.SeatPosition1Label = 2; exercise1.SeatPosition1Value = 1; //Add exercises to observable collectin in the template folder templateFolder.Exercises.Add (exercise1); templateFolder.Exercises.Add (exercise2); StaffMember staffMember = new StaffMember (); staffMember.FirstName = "Clay"; staffMember.LastName = "Martin"; staffMember.GymID = 8; staffMember.PhoneNumber = "5024171595"; staffMember.StaffID = 132; templateFolder.StaffMember = staffMember; exercise = new Exercise (); exercise.ExerciseName = "Barbell Bench Press"; exercise.Bodypart = "Chest"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "Barbell Inclie Bench Press"; exercise.Bodypart = "Chest"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "Barbell Row"; exercise.Bodypart = "Back"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "DB Row"; exercise.Bodypart = "Back"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "DB Shoulder Press"; exercise.Bodypart = "Shoulders"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); workoutCreatorViewModel = new WorkoutContainerViewModel (templateFolder, mockExercise.Object, new mockCurrentConnectivity()); mockExercise.Setup (x => x.GetAllExercises (staffMember.GymID)).ReturnsAsync(exerciseList); }
public ExerciseContainerPage(bool createWorkoutOnly = false, User logFeedbackOnlyUser = null) { InitializeComponent(); if (createWorkoutOnly) { this.Title = "Create Workout"; } if (logFeedbackOnlyUser != null) { this.Title = "Log Feedback for " + logFeedbackOnlyUser.FullMemberName; } _createWorkoutOnly = createWorkoutOnly; _viewModel = new WorkoutContainerViewModel(App.WorkoutCreatorContext, CrossConnectivity.Current, createWorkoutOnly, logFeedbackOnlyUser); this.BindingContext = _viewModel; _unselectedPadding = new Thickness(36, 20, 36, 0); _selectedPadding = new Thickness(36, 20, 36, 0); _mfBlue = (Color)Application.Current.Resources["blueColor"]; var exerciseListTask = _viewModel.GetAllExercises(); Action<Task> action = (actionResult) => { Device.BeginInvokeOnMainThread(() => { _viewModel.IsBusy = true; List<String> categories = _viewModel.GetExerciseCategories(); foreach (String bodypart in categories) { CustomImageButton circleButton = new CustomImageButton { IsVisible = false, Style = (Style)Application.Current.Resources["circleButtonStyle"] }; CustomImageButton emptyCircleButton = new CustomImageButton { Style = (Style)Application.Current.Resources["emptyCircleButtonStyle"] }; Label bodyPartLabel = new Label { HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Start, FontAttributes = FontAttributes.None, FontSize = _closedFrameBodyPartLabelFontSize, TextColor = Color.Gray, }; Label bodyPartSubLabel = new Label { HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Start, FontAttributes = FontAttributes.None, TextColor = Color.Gray }; StackLayout bodyPartLabelStack = new StackLayout { Children = { bodyPartLabel, bodyPartSubLabel }, Orientation = StackOrientation.Horizontal, VerticalOptions = LayoutOptions.Center, Spacing = 15, HorizontalOptions = LayoutOptions.Start }; var boxView = new BoxView() { Color = _mfBlue, HeightRequest = 1, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.FillAndExpand, IsVisible = false }; Grid bodyPartGrid = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = new GridLength (.8, GridUnitType.Star) }, new ColumnDefinition { Width = GridLength.Auto }, }, Padding = _unselectedPadding, StyleId = "closed" }; bodyPartGrid.Children.Add(circleButton, 0, 0); bodyPartGrid.Children.Add(bodyPartLabelStack, 1, 0); bodyPartGrid.Children.Add(boxView, 0, 1); Grid.SetColumnSpan(boxView, 4); bodyPartGrid.Children.Add(emptyCircleButton, 0, 0); emptyCircleButton.Clicked += async (button, e) => { emptyCircleButton.IsEnabled = false; await ShowHideExercisesInBodypart(bodyPartLabel, bodypart, boxView, circleButton, emptyCircleButton); emptyCircleButton.IsEnabled = true; }; circleButton.Clicked += async (button, e) => { circleButton.IsEnabled = false; await ShowHideExercisesInBodypart(bodyPartLabel, bodypart, boxView, circleButton, emptyCircleButton); circleButton.IsEnabled = true; }; String bodyPartStringForProcessing = bodypart; String[] bodyPartComponents = bodyPartStringForProcessing.Split('-'); if (bodyPartComponents.Count() > 1) { bodyPartLabel.Text = bodyPartComponents[0].Trim(); bodyPartSubLabel.Text = bodyPartComponents[1].Trim(); } else { bodyPartLabel.Text = bodyPartStringForProcessing; bodyPartSubLabel.Text = "General"; } primaryStackLayout.Children.Add(bodyPartGrid); } _viewModel.IsBusy = false; }); }; exerciseListTask.ContinueWith(action); cancelButton.Clicked += (sender, args) => { //Uses session tracking Insights.Track("Canceled workout creation in progress from 'ExerciseContainerPage'", new Dictionary<string, string>() { }); Action cancelAction = async () => { _viewModel.RemoveTemplateAndExercises(); summaryLabel.Text = ExerciseViewModel.WorkoutSummary(); await Navigation.PopToRootAsync(true); }; DependencyService.Get<ICustomDialog>().Display("Cancel workout creation in progress?", "No", "Yes", cancelAction); }; createWorkoutButton.Clicked += async (sender, args) => { //Uses session tracking Insights.Track("Clicked create workout button in exercise container", new Dictionary<string, string>() { }); await Navigation.PushAsync(new ModalWorkoutCreationPage(createWorkoutOnly, logFeedbackOnlyUser), true); }; reviewButton.Clicked += reviewButton_Clicked; summaryLabel.Text = ExerciseViewModel.WorkoutSummary(); if (_viewModel.WorkoutCreatorContext.Exercises.Count() == 0) { createWorkoutButton.IsEnabled = false; } else { createWorkoutButton.IsEnabled = true; } }