Esempio n. 1
0
        private async Task DisplayLoadoutMeals()
        {
            //stop appendage
            loadoutMealsStack.Children.Clear();

            for (int i = 0; i < loadoutMeals.Count; i++)
            {
                Grid itemGrid = new Grid();
                itemGrid.ColumnDefinitions.Add(new ColumnDefinition());
                itemGrid.ColumnDefinitions.Add(new ColumnDefinition());
                itemGrid.ColumnDefinitions.Add(new ColumnDefinition());
                itemGrid.RowDefinitions.Add(new RowDefinition());
                itemGrid.RowDefinitions.Add(new RowDefinition());
                itemGrid.RowDefinitions.Add(new RowDefinition());

                itemGrid.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
                itemGrid.RowDefinitions[2].Height = new GridLength(0.5, GridUnitType.Star);

                Frame frame = new Frame();
                frame.Content         = itemGrid;
                frame.BackgroundColor = Color.DarkRed;
                frame.Padding         = new Thickness(10, 10);
                frame.CornerRadius    = 5;

                //save index number per foodItem... To fix a bug
                loadoutMeals[i].index = i;

                Meal meal = loadoutMeals[i];

                Label lblName = new Label();
                lblName           = CardCreator.CreateLabelTemplate(lblName, LayoutOptions.Start, 0, 0, 1, meal.mealName);
                lblName.TextColor = Color.White;
                Label lblEnergy = new Label();
                lblEnergy           = CardCreator.CreateLabelTemplate(lblEnergy, LayoutOptions.Start, 0, 1, 2, string.Format("Energy: {0:0.00} kcal", meal.totalEnergy));
                lblEnergy.TextColor = Color.White;
                Label lblProtein = new Label();
                lblProtein           = CardCreator.CreateLabelTemplate(lblProtein, LayoutOptions.Start, 0, 2, 1, string.Format("P: {0:0.00} g", meal.totalProtein));
                lblProtein.TextColor = Color.White;
                Label lblCarbs = new Label();
                lblCarbs           = CardCreator.CreateLabelTemplate(lblCarbs, LayoutOptions.Center, 1, 2, 1, string.Format("C: {0:0.00} g", meal.totalCarbs));
                lblCarbs.TextColor = Color.White;
                Label lblFat = new Label();
                lblFat           = CardCreator.CreateLabelTemplate(lblFat, LayoutOptions.End, 2, 2, 1, string.Format("F: {0:0.00} g", meal.totalFat));
                lblFat.TextColor = Color.White;

                itemGrid.Children.Add(lblName);
                itemGrid.Children.Add(lblEnergy);
                itemGrid.Children.Add(lblProtein);
                itemGrid.Children.Add(lblCarbs);
                itemGrid.Children.Add(lblFat);

                StackLayout stack = new StackLayout();
                stack.Orientation = StackOrientation.Horizontal;
                Grid.SetColumnSpan(stack, 3);
                stack.HorizontalOptions = LayoutOptions.End;

                CheckBox chkbxEaten = new CheckBox();
                chkbxEaten.Color = Color.White;

                //check meal status from database and set accordingly.
                if (loadoutMeals[meal.index].isEaten == true)
                {
                    chkbxEaten.IsChecked = true;
                }
                else
                {
                    chkbxEaten.IsChecked = false;
                }

                chkbxEaten.CheckedChanged += async(sender, args) =>
                {
                    if (chkbxEaten.IsChecked == true)
                    {
                        goalProgress.energyKcal += loadoutMeals[meal.index].totalEnergy;
                        goalProgress.protein    += loadoutMeals[meal.index].totalProtein;
                        goalProgress.carbs      += loadoutMeals[meal.index].totalCarbs;
                        goalProgress.fat        += loadoutMeals[meal.index].totalFat;

                        loadoutMeals[meal.index].isEaten = true;
                    }
                    else
                    {
                        goalProgress.energyKcal -= loadoutMeals[meal.index].totalEnergy;
                        goalProgress.protein    -= loadoutMeals[meal.index].totalProtein;
                        goalProgress.carbs      -= loadoutMeals[meal.index].totalCarbs;
                        goalProgress.fat        -= loadoutMeals[meal.index].totalFat;

                        loadoutMeals[meal.index].isEaten = false;
                    }
                    await DisplayGoalAndProgress(); //update
                    await SetGoalRatios();
                    await DisplayGoalRatios();

                    //update db per tick
                    await MasterModel.DAL.SaveGoalAsync(dailyGoal);

                    await MasterModel.DAL.SaveGoalProgressAsync(goalProgress);

                    loadout.Meals = loadoutMeals;
                    await MasterModel.DAL.SaveSelectedLoadout(loadout);
                };

                stack.Children.Add(chkbxEaten);

                itemGrid.Children.Add(stack);

                loadoutMealsStack.Children.Add(frame);
            }
        }
Esempio n. 2
0
        private void LoadMeals()
        {
            //prevent appendage
            mealsFound.Children.Clear();

            for (int i = 0; i < meals.Count; i++)
            {
                Grid mealGrid = new Grid();
                mealGrid.ColumnDefinitions.Add(new ColumnDefinition());
                mealGrid.ColumnDefinitions.Add(new ColumnDefinition());
                mealGrid.ColumnDefinitions.Add(new ColumnDefinition());
                mealGrid.RowDefinitions.Add(new RowDefinition());
                mealGrid.RowDefinitions.Add(new RowDefinition());

                mealGrid.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);

                mealGrid.BackgroundColor = Color.FromHex("2196F3");
                mealGrid.Padding         = new Thickness(10, 10);

                //save index number per foodItem... To fix a bug
                meals[i].index = i;

                Meal meal = meals[i];

                Label lblName = new Label();
                lblName           = CardCreator.CreateLabelTemplate(lblName, LayoutOptions.Start, 0, 1, 3, meal.mealName);
                lblName.TextColor = Color.White;

                mealGrid.Children.Add(lblName);

                StackLayout stack = new StackLayout();
                stack.Orientation = StackOrientation.Horizontal;
                Grid.SetColumnSpan(stack, 3);
                stack.HorizontalOptions = LayoutOptions.End;

                Button btnEdit = new Button()
                {
                    Text            = "Edit",
                    FontSize        = Device.GetNamedSize(NamedSize.Micro, typeof(Button)),
                    BackgroundColor = Color.DarkGoldenrod,
                    TextColor       = Color.White,
                    HeightRequest   = 35,
                    WidthRequest    = 50,
                    CornerRadius    = 5
                };

                Button btnDelete = new Button()
                {
                    Text            = "Del",
                    FontSize        = Device.GetNamedSize(NamedSize.Micro, typeof(Button)),
                    BackgroundColor = Color.DarkRed,
                    TextColor       = Color.White,
                    HeightRequest   = 35,
                    WidthRequest    = 50,
                    CornerRadius    = 5
                };

                btnEdit.Clicked += async(sender, args) =>
                {
                    MasterModel.tempMeal = meals[meal.index];
                    await Navigation.PushAsync(new AddMealPage());
                };

                btnDelete.Clicked += async(sender, args) =>
                {
                    //meals.RemoveAt(meal.index);
                    MasterModel.currentUser.Meals.RemoveAt(meal.index);
                    await MasterModel.DAL.SaveMealV2();

                    RefreshPage();
                };

                stack.Children.Add(btnEdit);
                stack.Children.Add(btnDelete);

                mealGrid.Children.Add(stack);

                //mealsFound.Children.Add(mealGrid);
                mealsFound.Children.Insert(0, mealGrid);
            }
        }