private Frame GetExerciseFrame(Exercise exercise)
		{
			StackLayout exerciseStackLayout = new StackLayout
			{
				Orientation = StackOrientation.Horizontal,
				VerticalOptions = LayoutOptions.FillAndExpand,
				Spacing = 0,
			};

			StackLayout exerciseLabelContainerStack = new StackLayout
			{
				Padding = new Thickness(0, 0, 5, 0),
				Spacing = 10
			};

			var exerciseFrame = new Frame
			{
				Content = exerciseStackLayout,
				HasShadow = false,
				BackgroundColor = (Color)Application.Current.Resources["ymcaLightBlue"]
			};

			var tapGestureRecognizer2 = new TapGestureRecognizer();
			tapGestureRecognizer2.Tapped += async (s2, e2) =>
			{
				if (_viewModel.IsBusy)
				{
					return;
				}
				_viewModel.IsBusy = true;
				await exerciseFrame.FadeTo(0);
				//MemberExerciseViewModel simpleMemberExercise = new MemberExerciseViewModel (exercise, _memberExerciseCollection);
				MemberExerciseViewModel simpleMemberExercise = new MemberExerciseViewModel(exercise);

				//Uses session tracking
				Insights.Track("Viewed exercise in simple member exercise container", new Dictionary<string, string>() {
					{ "exercise", simpleMemberExercise.Exercise.Exercisename },
					{ "exercise id", simpleMemberExercise.Exercise.ExerciseID.ToString () }
				});



				await this.Navigation.PushAsync(new MemberExercisePage(simpleMemberExercise, false));
				await exerciseFrame.FadeTo(1, 500);
				_viewModel.IsBusy = false;
			};

			//exerciseFrame.GestureRecognizers.Add (tapGestureRecognizer2);
			exerciseStackLayout.GestureRecognizers.Add(tapGestureRecognizer2);

			Label exerciseCategoryLabel = new Label
			{
				Text = exercise.ExerciseType,
				FontAttributes = FontAttributes.Bold,
				VerticalOptions = LayoutOptions.Start,
				Style = (Style)Application.Current.Resources["exerciseNameLabelStyle"]
			};


			Label exerciseNameLabel = new Label
			{
				Text = exercise.Exercisename,
				Style = (Style)Application.Current.Resources["exerciseNameLabelStyle"]
			};

			Image exerciseImage = new Image
			{
				Source = exercise.ImageSource,
				Style = (Style)Application.Current.Resources["exerciseImageStyle"]
			};

			exerciseLabelContainerStack.Children.Add(exerciseCategoryLabel);
			exerciseLabelContainerStack.Children.Add(exerciseNameLabel);

			//exerciseStackLayout.Children.Add (exerciseNameLabel);
			exerciseStackLayout.Children.Add(exerciseLabelContainerStack);
			exerciseStackLayout.Children.Add(exerciseImage);
			return exerciseFrame;
		}
Пример #2
0
		public MemberExercisePage (MemberExerciseViewModel exercise, bool isExerciseEdit = false)
		{
			InitializeComponent ();

			Title = isExerciseEdit ? "Modify Exercise" : "Add Exercise";

			_viewModel = exercise;
			_isExerciseEdit = isExerciseEdit;
			this.BindingContext = _viewModel;

			if (_viewModel.Exercise.EquipmentType == "Machine") {

				foreach (string seatPosLabel in MemberExerciseViewModel.SeatPositionLabelOptions) {
					seatPositionLabelPicker1.Items.Add (seatPosLabel);
					seatPositionLabelPicker2.Items.Add (seatPosLabel);
					seatPositionLabelPicker3.Items.Add (seatPosLabel);
					seatPositionLabelPicker4.Items.Add (seatPosLabel);
				}

				seatPositionLabelPicker1.SetBinding (Picker.SelectedIndexProperty, "SeatPosition1Label");
				seatPositionLabelPicker2.SetBinding (Picker.SelectedIndexProperty, "SeatPosition2Label");
				seatPositionLabelPicker3.SetBinding (Picker.SelectedIndexProperty, "SeatPosition3Label");
				seatPositionLabelPicker4.SetBinding (Picker.SelectedIndexProperty, "SeatPosition4Label");

			} else {

				seatPositionStack.IsVisible = false;
			}

			if (_viewModel.Exercise.EquipmentType == "Hold") {
				RepsLabel.Text = "Hold (Secs): ";
			}

			if (_viewModel.Exercise.IsMask) {
				WeightLabel.Text = "Target Pins:";
			}

			if (_viewModel.Exercise.IsBodyWeight) {
				WeightLabel.IsVisible = false;
				weightEntry.IsVisible = false;
			
			} 




			cancelButton.Clicked += (sender, args) => {
				string addEditString = "";
				if (!_isExerciseEdit) {
					addEditString = "add";
				} else {
					addEditString = "edit";
				}

				Action cancelAction = async () => {
					if (!_isExerciseEdit) {
						//Remove the addexercisecontainerpage from the stack so that the user doesn't land on that page after clicking the cancel button
						//this.Navigation.RemovePage (this.Navigation.NavigationStack [this.Navigation.NavigationStack.Count - 2]);
						await App.Current.MainPage.Navigation.PopAsync (false);
					}

					//Uses session tracking
					Insights.Track ("Cancel exercise " + addEditString, new Dictionary<string, string> () {
						{ "Exercise", exercise.Exercise.Exercisename },
						{ "Exercise id", exercise.Exercise.ExerciseID.ToString () }
					});

					await App.Current.MainPage.Navigation.PopAsync (false);

				};
				DependencyService.Get<ICustomDialog> ().Display ("Cancel exercise " + addEditString + "?", "No", "Yes", cancelAction);
			};

			createExerciseButton.Clicked += async (sender, args) => {
				if ((_viewModel.Sets != 0 && _viewModel.Reps != 0) || _viewModel.Duration != 0)
				{
					if (!_isExerciseEdit) {
						// _viewModel.Exercise = exercise.Exercise;
						//_viewModel.SimpleExerciseCollection.Add (_viewModel);
						MessagingCenter.Send<MemberExercisePage, MemberExerciseViewModel> (this, "ExerciseAdded", _viewModel);
						//Uses session tracking
						Insights.Track ("Added exercise to member program", new Dictionary<string, string> () {
							{ "Exercise", exercise.Exercise.Exercisename },
							{ "Exercise id", exercise.Exercise.ExerciseID.ToString () }
						});
				
						//Remove the addexercisecontainerpage from the stack so that the user doesn't land on that page after clicking the create button
						//App.Current.MainPage.Navigation.RemovePage (App.Current.MainPage.Navigation.NavigationStack [App.Current.MainPage.Navigation.NavigationStack.Count - 2]);
						await App.Current.MainPage.Navigation.PopAsync (false);
	                   
					} else {
						MessagingCenter.Send<MemberExercisePage, MemberExerciseViewModel> (this, "ExerciseModified", _viewModel);
						//MessagingCenter.Send<MemberExercisePage> (this, "ExerciseModified");
						//_viewModel.SimpleExerciseCollection.
						//Uses session tracking
						Insights.Track ("Viewed or modified a member exercise in their program", new Dictionary<string, string> () {
							{ "Exercise", exercise.Exercise.Exercisename },
							{ "Exercise id", exercise.Exercise.ExerciseID.ToString () }
						});
					}

					await App.Current.MainPage.Navigation.PopAsync (true);
				} else {
					StringBuilder displayMessageSB = new StringBuilder("Exercises cannot be added with 0 ");
					if (_viewModel.IsCardio)
					{
						displayMessageSB.Append("minutes.");
					}
					else {
						displayMessageSB.Append("sets or 0 reps.");
					}
					DependencyService.Get<ICustomDialog> ().Display (displayMessageSB.ToString(), "OK");
				}
			};



			if (isExerciseEdit) {

				ToolbarItem cancelItem = new ToolbarItem {
					Text = "Cancel",
					Icon = Device.OnPlatform ("cancel.png", "ic_action_cancel", "Images/cancel.png"),
					Order = ToolbarItemOrder.Primary
				};

				cancelItem.Clicked += (sender, args) => {
					Action cancelAction = async () => {

						//Uses session tracking
						Insights.Track ("Cancel exercise edit", new Dictionary<string, string> () {
							{ "Exercise", exercise.Exercise.Exercisename },
							{ "Exercise id", exercise.Exercise.ExerciseID.ToString () }
						});
            

						await this.Navigation.PopAsync ();

					};
					DependencyService.Get<ICustomDialog> ().Display ("Cancel exercise edit?", "No", "Yes", cancelAction);
					
				};
				this.ToolbarItems.Add (cancelItem);

				ToolbarItem deleteItem = new ToolbarItem {
					Text = "Delete",
					Icon = Device.OnPlatform ("discard.png", "ic_action_discard.png", "Images/delete.png"),
					Order = ToolbarItemOrder.Primary
				};

				deleteItem.Clicked += (sender, args) => {
					Action deleteAction = async () => {
						//Uses session tracking
						Insights.Track ("Deleted exercise from exercise list", new Dictionary<string, string> () {
							{ "Exercise", exercise.Exercise.Exercisename },
							{ "Exercise id", exercise.Exercise.ExerciseID.ToString () }
						});
						MessagingCenter.Send<MemberExercisePage, MemberExerciseViewModel> (this, "ExerciseDeleted", _viewModel);
						await this.Navigation.PopAsync ();
					};
					DependencyService.Get<ICustomDialog> ().Display ("Delete this exercise?", "No", "Yes", deleteAction, true);
				};

				this.ToolbarItems.Add (deleteItem);

			}

		}
		private void GetMemberExercises()
		{


			Device.BeginInvokeOnMainThread(async () =>
			{
				List<UserWorkoutTemplateMapping> exerciseList = await UserWorkoutTemplateMappingDAL.GetMappingsByUserProfileIDAndUserExerciseGroupID(this.ProfileID, this.LocalUserExerciseGroupID);

				SimpleExerciseCollection.CollectionChanged -= SyncExercises;


				foreach (var mapping in exerciseList)
				{

					MemberExerciseViewModel simpleExercise = new MemberExerciseViewModel();
					var exercise = await ExerciseDAL.GetExercisesByExerciseID(App.WorkoutCreatorContext.StaffMember.GymID, mapping.ExerciseID);
					if (exercise != null && exercise.Id != 0)
					{
						simpleExercise.Exercise = exercise;
						simpleExercise.ImageSource = exercise.ImageSource;
						simpleExercise.Reps = mapping.TargetReps;
						simpleExercise.Sets = mapping.TargetSets;
						simpleExercise.Weight = mapping.TargetWeight;

						simpleExercise.Duration = mapping.TargetDurationMin;
						simpleExercise.TargetHRMin = mapping.TargetHRMin;
						simpleExercise.TargetHRMax = mapping.TargetHRMax;

						simpleExercise.IsCardio = exercise.CardioExID != 0 ? true : false;


						simpleExercise.SeatPosition1Value = mapping.SeatPosValue1;

						simpleExercise.SeatPosition2Value = mapping.SeatPosValue2;

						simpleExercise.SeatPosition3Value = mapping.SeatPosValue3;

						simpleExercise.SeatPosition4Value = mapping.SeatPosValue4;


						if (mapping.SeatPosLabel1 != "")
						{
							simpleExercise.SeatPosition1Label = MemberExerciseViewModel.SeatPositionLabelOptions.FindIndex(a => a.Equals(mapping.SeatPosLabel1));
						}
						else {
							simpleExercise.SeatPosition1Label = -1;
						}
						if (mapping.SeatPosLabel2 != "")
						{
							simpleExercise.SeatPosition2Label = MemberExerciseViewModel.SeatPositionLabelOptions.FindIndex(a => a.Equals(mapping.SeatPosLabel2));
						}
						else {
							simpleExercise.SeatPosition2Label = -1;
						}
						if (mapping.SeatPosLabel3 != "")
						{
							simpleExercise.SeatPosition3Label = MemberExerciseViewModel.SeatPositionLabelOptions.FindIndex(a => a.Equals(mapping.SeatPosLabel3));
						}
						else {
							simpleExercise.SeatPosition3Label = -1;
						}
						if (mapping.SeatPosLabel4 != "")
						{
							simpleExercise.SeatPosition4Label = MemberExerciseViewModel.SeatPositionLabelOptions.FindIndex(a => a.Equals(mapping.SeatPosLabel4));
						}
						else {
							simpleExercise.SeatPosition4Label = -1;
						}
						SimpleExerciseCollection.Add(simpleExercise);
					}
					else {
						//If exercise is not available manually throw error and log to insights
						try
						{
							throw new Exception("Exercise id " + mapping.ExerciseID.ToString() + "is not in the phone's database");
						}
						catch (Exception e)
						{
							Insights.Report(e);
						}
					}
				}


				//Wire up event to changed

				SimpleExerciseCollection.CollectionChanged += SyncExercises;
			});

		}
		public void Setup(){
			mockStaffMemberDataRepository = new Mock<IStaffMember> ();
			mockExercise = new Mock<IExercise> ();

			//Create 2 simple exercise objects
			MemberExerciseViewModel exercise1 = new MemberExerciseViewModel ();
			exercise1.SetsIndex= 1;
			exercise1.RepsIndex = 2;
			exercise1.WeightIndex = 2;
			exercise1.SeatPosition1Label = 1;
			exercise1.SeatPosition1Value = 1;

			MemberExerciseViewModel exercise2 = new MemberExerciseViewModel ();
			exercise1.SetsIndex = 2;
			exercise1.RepsIndex = 1;
			exercise1.WeightIndex = 2;
			exercise1.SeatPosition1Label = 2;
			exercise1.SeatPosition1Value = 1;

			//Add exercises to observable collection
            _memberExerciseViewModelCollection = new ObservableCollection<MemberExerciseViewModel>();
            _memberExerciseViewModelCollection.Add(exercise1);
            _memberExerciseViewModelCollection.Add(exercise2);

			StaffMember staffMember = new StaffMember ();
			staffMember.FirstName = "Clay";
			staffMember.LastName = "Martin";
			staffMember.GymID = 8;
			staffMember.PhoneNumber = "5024171595";
			staffMember.StaffID = 132;

            _templateFolder = new TemplateFolder();
			_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 AddExerciseWorkoutContainerViewModel(_templateFolder, mockExercise.Object);
		}