Beispiel #1
0
        public FoodInfo(FoodInfoModel foodobject, Button button, int timesPressed, bool hideDelBtn = false)
        {
            var data = Application.Current.Properties;
            var qqq  = foodobject.IsMeal;

            InitializeComponent();
            foodObj = foodobject;
            foodobject.TimesPressed = timesPressed.ToString();
            btn = button;
            if (!foodObj.IsMeal)
            {
                UndoButton.IsVisible = false;
            }
            if (btn == null)
            {
                RemoveEntryButton.IsVisible = false;
                EditNameButton.IsVisible    = false;
                ChangeMealTime.IsVisible    = false;
                UndoButton.IsVisible        = false;
                //FoodCal.Text = foodObj.FoodCal;
                //FoodFat.Text = foodObj.FoodFat;
                //FoodCarb.Text = foodObj.FoodCarb;
                //FoodProt.Text = foodObj.FoodProt;
                //IsCustom.Text = foodObj.FoodPortion;

                FoodCal.Text  = "Calories: " + foodobject.FoodCal + "kcal";
                FoodCarb.Text = "Carbs: " + foodobject.FoodCarb + "g";
                FoodFat.Text  = "Fat: " + foodobject.FoodFat + "g";
                FoodProt.Text = "Protein: " + foodobject.FoodProt + "g";

                IsCustom.Text = "Food Portion: " + foodobject.IsCustomButton;
            }
            else if (timesPressed == 0)
            {
                RemoveEntryButton.IsVisible = false;
                //RemoveEntryBoxView.IsVisible = false;
            }
            if (hideDelBtn)
            {
                DeleteButon.IsVisible       = false;
                RemoveEntryButton.IsVisible = false;
                //RemoveEntryBoxView.IsVisible = false;
            }
            BindingContext = viewModel = new FoodInfoViewModel(foodobject);
            //var swp = new SwipeGestureRecognizer();
            //swp.Swiped += SwipeGestureRecognizer_Swiped;
            //(this as PopupPage).Content.GestureRecognizers.Add(swp);
            //var leftSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Left };
            //leftSwipeGesture.Swiped += SwipeGestureRecognizer_Swiped;
            //sl.GestureRecognizers.Add(leftSwipeGesture);
        }
Beispiel #2
0
        public async void OnButtonLongPressed(object sender, EventArgs args)
        {
            if (combineActive)
            {
                return;
            }
            longpress = true;
            var data = Xamarin.Forms.Application.Current.Properties;

            var x = sender as Xamarin.Forms.Button;
            var y = x.ClassId;

            int.TryParse(y, out int classid);
            FoodInfoModel foodobject = new FoodInfoModel();
            var           q          = data[classid + "food"].ToString();
            FoodModel     foodtoget  = JsonConvert.DeserializeObject <FoodModel>(q);

            foodobject.FoodCal        = foodtoget.Calories.ToString();
            foodobject.TimeOfDay      = foodtoget.TimeOfDay.ToString();
            foodobject.FoodCarb       = foodtoget.Carbs.ToString();
            foodobject.FoodFat        = foodtoget.Fat.ToString();
            foodobject.FoodProt       = foodtoget.Protein.ToString();
            foodobject.MoreInfo       = foodtoget.MoreInfo.ToString();
            foodobject.IsCustomButton = foodtoget.Portion.ToString();
            foodobject.FoodName       = foodtoget.Name.ToString();
            foodobject.ClassId        = foodtoget.ClassId.ToString();
            foodobject.IsMeal         = false;



            //var z = y.ToCharArray();
            //var isNumeric = int.TryParse(z[0].ToString(), out int n);
            //if (isNumeric) //einai custom button
            //{

            //        string q = y.Replace("Brunch", "");

            //        int k = Convert.ToInt32(q);


            //        string calories = Application.Current.Properties[k.ToString() + "custombuttonBrunchCal"].ToString();
            //        string carbs = Application.Current.Properties[k.ToString() + "custombuttonBrunchCarb"].ToString();
            //        string prots = Application.Current.Properties[k.ToString() + "custombuttonBrunchProtein"].ToString();
            //        string fats = Application.Current.Properties[k.ToString() + "custombuttonBrunchFat"].ToString();
            //        string name = Application.Current.Properties[k.ToString() + "custombuttonBrunchName"].ToString();
            //        string moreinfo = Application.Current.Properties[k.ToString() + "custombuttonBrunchMoreInfo"].ToString();

            //        foodobject.FoodCal = calories;
            //        foodobject.FoodCarb = carbs;
            //        foodobject.FoodFat = prots;
            //        foodobject.FoodProt = fats;
            //        foodobject.FoodName = name;
            //        foodobject.MoreInfo = moreinfo;

            //        foodobject.ClassId = x.ClassId;
            //        foodobject.IsCustomButton = true.ToString();
            //        foodobject.TimeOfDay = "Brunch";
            //        foodobject.TimesPressed = "0";
            //        for (int qq = 0; qq < timesButtonPressed.Count; qq++)
            //        {
            //            if (x.ClassId == timesButtonPressed[qq].classid)
            //            {
            //                foodobject.TimesPressed = timesButtonPressed[qq].timespressed.ToString();
            //                break;
            //            }
            //        }


            //        //await DisplayAlert("Info", message, "OK");


            //}
            //else
            //{
            //    //Rg.Plugins.Popup.
            //    //  PopupNavigation.Instance.PushAsync(new FoodInfo());

            //    foodobject = viewModel.Getmacros(x.ClassId);
            //    foodobject.TimesPressed = "0";
            //    for (int qq = 0; qq < timesButtonPressed.Count; qq++)
            //    {
            //        if (x.ClassId == timesButtonPressed[qq].classid)
            //        {
            //            foodobject.TimesPressed = timesButtonPressed[qq].timespressed.ToString();
            //            break;
            //        }
            //    }
            //    foodobject.ClassId = x.ClassId;
            //    foodobject.IsCustomButton = false.ToString();

            //    //await DisplayAlert("Info", message, "OK");
            //}
            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
            var modalPage  = new FoodInfo(foodobject, x, foodtoget.TimesPressed);

            modalPage.Disappearing += (sender2, e2) =>
            {
                waitHandle.Set();
            };
            await PopupNavigation.Instance.PushAsync(modalPage);

            if (data["mealviewedtutorial2"].ToString() != "ok" && data["mealviewedtutorial1"].ToString() == "ok")
            {
                //var qq =  rdbutton.Parent.GetPropertyIfSet(Grid.RowProperty,false);


                var page = new MealTutorialView2();
                await Navigation.PushPopupAsync(page);

                //string myinput = await TutorialPage(this.Navigation);

                // StartTutorial();
            }
            //edw stamataei k perimenei
            await Task.Run(() => waitHandle.WaitOne());

            //edw stamataei k perimenei
            longpress = false;


            //    var x = sender as Button;
        }
Beispiel #3
0
        private async void SelectedItem(object sender, EventArgs e)
        {
            loadingPopup = new LoadingPopup();
            await Navigation.PushPopupAsync(loadingPopup);

            loadispushed = true;


            var tapped_label = sender as StackLayout;

            tapped_label.BackgroundColor = Color.Orange;
            var fcdId        = tapped_label.ClassId;
            var parsedObject = await APIGET(fcdId);

            if (parsedObject == null)
            {
                return;
            }

            var json2 = parsedObject["foodNutrients"].ToString();

            var foodNutrients = JsonConvert.DeserializeObject <IEnumerable <APIGetFoodModel> >(json2);
            var foodportion   = parsedObject["foodPortions"].ToString();
            var portionUnits  = JsonConvert.DeserializeObject <IEnumerable <APIgramWeightModel> >(foodportion);


            LocalFoodModel foodtosave = new LocalFoodModel();
            int            i          = 0;

            foreach (var nu in foodNutrients)
            {
                if (nu.nutrient.name == "Protein" && nu.nutrient.unitName == "g")
                {
                    foodtosave.Prot = nu.amount;
                    i += 1;
                }
                if (nu.nutrient.name == "Total lipid (fat)" && nu.nutrient.unitName == "g")
                {
                    foodtosave.Fat = nu.amount;

                    i += 1;
                }
                if (nu.nutrient.name == "Carbohydrate, by difference" && nu.nutrient.unitName == "g")
                {
                    foodtosave.Carb = nu.amount;

                    i += 1;
                }
                if (nu.nutrient.name == "Energy" && nu.nutrient.unitName == "kcal")
                {
                    foodtosave.Cal = nu.amount;

                    i += 1;
                }
                if (nu.nutrient.name == "Sugars, total including NLEA" && nu.nutrient.unitName == "g")
                {
                    foodtosave.MoreInfo = nu.amount;

                    i += 1;
                }
                if (i == 5)
                {
                    break;
                }
            }
            // foodtosave.Name = foodNutrients.First().gramWeight; // to add grams to name of food
            foodtosave.gramsEnum = portionUnits;
            var x = new FoodInfoModel();

            x.FoodCal        = String.Format("{0:C2}", foodtosave.Cal);
            x.FoodCarb       = String.Format("{0:C2}", foodtosave.Carb);
            x.FoodProt       = String.Format("{0:C2}", foodtosave.Prot);
            x.FoodFat        = String.Format("{0:C2}", foodtosave.Fat);
            x.MoreInfo       = foodtosave.MoreInfo;
            x.IsCustomButton = "100g\n\nnote: you can change\nthe portion later.";
            var view = new FoodInfo(x, null, 0, true);
            //var x = new PopupAlert("is this ok?");
            //await Navigation.PushPopupAsync(x, true);
            string myinput = await IsOk(this.Navigation, view, loadingPopup);

            //pageref.ClearButtons(false);
            //pageref.SetButtons(foodtosave);
            if (myinput == "Ok")
            {
                CreateSearch.Invoker.SetButtons(foodtosave);
                // await Navigation.RemovePopupPageAsync(loadingPage);

                await Navigation.RemovePopupPageAsync(this);
            }
            else
            {
                tapped_label.BackgroundColor = Color.Default;
                //await Navigation.RemovePopupPageAsync(loadingPage);
            }

            //var your_viewcell = tapped_label.Parent as ViewCell;
            //var your_binded_object = your_viewcell.BindingContext;
        }