예제 #1
0
        public Task <string> IsOk(INavigation navigation, FoodInfo foodinfoview, PopupPage loadingpage)
        {
            // wait in this proc, until user did his input
            var tcs = new TaskCompletionSource <string>();



            var btnCancel = new RadButton
            {
                Text            = "Cancel",
                WidthRequest    = 100,
                BackgroundColor = Color.FromRgb(0.8, 0.8, 0.8)
            };


            var btnOk = new RadButton
            {
                Text            = "Ok",
                WidthRequest    = 100,
                BackgroundColor = Color.FromRgb(0.8, 0.8, 0.8)
            };

            var slButtons = new StackLayout
            {
                Children = { btnOk, btnCancel },
            };

            var layout = new StackLayout
            {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Orientation       = StackOrientation.Vertical,
                Children          = { foodinfoview.Content, slButtons },
                //Children = { carview },
            };

            //create and show page
            var page = new PopupPage();

            page.Content = layout;

            btnCancel.Clicked += async(s, e) =>
            {
                // close page
                await navigation.RemovePopupPageAsync(page);

                // pass empty result
                tcs.SetResult(null);
            };
            btnOk.Clicked += async(s, e) =>
            {
                // close page
                await navigation.RemovePopupPageAsync(page);

                // pass empty result
                tcs.SetResult("Ok");
            };


            // create and show page

            navigation.PushPopupAsync(page);
            navigation.RemovePopupPageAsync(loadingpage);

            // open keyboard


            // code is waiting her, until result is passed with tcs.SetResult() in btn-Clicked
            // then proc returns the result
            return(tcs.Task);
        }
예제 #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;
        }
예제 #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;
        }