Ejemplo n.º 1
0
        private async void Button_ClickedNext(object sender, EventArgs e)
        {
            loadingPopup = new LoadingPopup();
            await Navigation.PushPopupAsync(loadingPopup);

            loadispushed = true;

            pageNo += 1;
            if (pageNo > totalPages)
            {
                pageNo = 1;
            }
            var parsedObject = await APIPOST(searchInput, pageNo);

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

            foodList = JsonConvert.DeserializeObject <IEnumerable <APIPostFoodModel> >(json2);
            foreach (var x in foodList)
            {
                if (x.dataType == "Branded" && x.brandOwner != null)
                {
                    x.description = x.description + "\nBrand: " + x.brandOwner;
                }
            }
            var listView = new ListView();

            listViewFood.ItemsSource = foodList;
            await Navigation.RemovePopupPageAsync(loadingPopup);

            thisPage = pageNo + "/" + totalPages;
        }
Ejemplo n.º 2
0
        private async void RadButton_ClickedCalculate(object sender, EventArgs e)
        {
            var loadingPage = new LoadingPopup();
            await Navigation.PushPopupAsync(loadingPage);

            string myinput = await AddCustomButton(this.Navigation, loadingPage);
        }
Ejemplo n.º 3
0
        private async void OnLogin(object sender, EventArgs e)
        {
            var loadingPage = new LoadingPopup();
            await Navigation.PushPopupAsync(loadingPage);

            await Task.Delay(2000);

            await Navigation.RemovePopupPageAsync(loadingPage);

            //   await Navigation.PushPopupAsync(new LoginSuccessPopupPage());
        }
Ejemplo n.º 4
0
        public async void AddButtonWindow(object sender, EventArgs e)
        {
            var loadingPage = new LoadingPopup();
            await Navigation.PushPopupAsync(loadingPage);

            CheckTutorial4();
            string myinput = await AddCustomButton(this.Navigation, loadingPage);

            if (myinput == "ok")
            {
            }
        }
Ejemplo n.º 5
0
        private async void Button_ClickedCreate(object sender, EventArgs e)
        {
            var loadingPage = new LoadingPopup();
            var data        = Application.Current.Properties;

            if (Name.Text == "" || Calories2.Text == "")
            {
                var alert = new PopupAlert("You must at least fill the Name and Calories fields.");
                await Navigation.PushPopupAsync(alert);

                return;
            }
            else
            {
                //var loadingPage = new LoadingPopup();

                await Navigation.PushPopupAsync(loadingPage);

                var       no          = data["noOfFoods"] = (Convert.ToInt32(data["noOfFoods"]) + 1).ToString(); //classid
                string[]  modArr      = fullPortionString.Split('(');
                string    modArrNumb  = modArr[modArr.Count() - 1].Replace(')', ' ');
                double    modArrFloat = Convert.ToDouble(modArrNumb.Replace('g', ' '));
                FoodModel foodtosave  = new FoodModel(timeOfDay,
                                                      (Calories2.Text != "") ? Convert.ToDouble(Calories2.Text) : 0,
                                                      (CarbsPg.Text != "") ? Convert.ToDouble(CarbsPg.Text) : 0,
                                                      (FatPg.Text != "") ? Convert.ToDouble(FatPg.Text) : 0,
                                                      (ProteinPg.Text != "") ? Convert.ToDouble(ProteinPg.Text) : 0,
                                                      (MoreInfo.Text != "") ? MoreInfo.Text : "",
                                                      modArrFloat,
                                                      (Name.Text != "") ? Name.Text : "0",
                                                      Convert.ToInt32(no.ToString()),
                                                      0
                                                      );
                var foodJson = JsonConvert.SerializeObject(foodtosave);
                data.Add(foodtosave.ClassId.ToString() + "food", foodJson);
                await Application.Current.SavePropertiesAsync();



                await Navigation.RemovePopupPageAsync(loadingPage);

                ClearButtons();
                MealView.Invoker.CustomButtonCreatorInvoker(foodtosave);
                await Task.Delay(100);

                PopupPage btncreated = new PopupAlert("Button Created!");

                await Navigation.PushPopupAsync(btncreated);
            }
        }
Ejemplo n.º 6
0
        private async void SearchboxUnFocused(object sender, FocusEventArgs e)
        {
            checkdelay = true;
            if (activeSearch)
            {
                if (Name.Text.Length >= 3 && !justsearched)
                {
                    await Task.Run(() => { Delayer(); });

                    justsearched = true;
                    //viewModel.ClearNamePlc("");
                    loadingPopup = new LoadingPopup();
                    await Navigation.PushPopupAsync(loadingPopup);

                    loadispushed = true;
                    //await Navigation.RemovePopupPageAsync(loadingPage);
                    string URL2 = "https://api.nal.usda.gov/fdc/v1/search?api_key=aurg5ejFKMIpBq79PlHAkkCRCfEKt6s1hYnNKwg8";

                    var searchinput = Name.Text;
                    var values      = new Dictionary <string, string>
                    {
                        { "generalSearchInput", searchinput },
                        { "pageNumber", "1" },
                        { "requireAllWords", "true" },
                        { "sortField", "score" }
                    };
                    HttpClient HttpClient = new HttpClient();
                    // client2.BaseAddress = new Uri(URL);

                    // HttpContent content = new FormUrlEncodedContent(values);
                    //      HttpContent content = new En(values);
                    var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(values));

                    var content = new StringContent(stringPayload, Encoding.UTF8, "application/json");


                    //var yo =  content.GetType();
                    HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    if (CheckForInternetConnection())
                    {
                        var response2 = await HttpClient.PostAsync(URL2, content);

                        if (response2.IsSuccessStatusCode)
                        {
                            var responseString = await response2.Content.ReadAsStringAsync();

                            //  var httpContent = new StringContent(jsonData, Encoding.UTF8, "application/json");
                            // var json = Newtonsoft.Json.JsonConvert.SerializeObject(responseString, Newtonsoft.Json.Formatting.Indented);
                            var parsedObject = JObject.Parse(responseString);
                            // var properties = JsonConvert.DeserializeObject<IEnumerable<APIHitsAndPages>>(parsedObject.ToString());

                            var json2       = parsedObject["foods"].ToString();
                            var totalPages  = Convert.ToInt32(parsedObject["totalPages"].ToString());
                            var currentPage = Convert.ToInt32(parsedObject["currentPage"].ToString());

                            //Debug.WriteLine(json);
                            HttpClient.Dispose();
                            checkdelay = false;
                            try
                            {
                                await Navigation.RemovePopupPageAsync(globalAlert);

                                loadispushed = false;
                            }
                            catch
                            {
                                loadispushed = false;
                            }


                            // var yo = json2.Count();
                            if (json2.Count() == 2) //[] -> 2 chars
                            {
                                justsearched = false;
                                //                                viewModel.ClearNamePlc("search...");
                                var alert = new PopupAlert("No Entries found.");
                                try
                                {
                                    await Navigation.RemovePopupPageAsync(loadingPopup);

                                    loadispushed = false;
                                }
                                catch
                                {
                                    loadispushed = false;
                                }
                                await Navigation.PushPopupAsync(alert);

                                return;
                            }

                            var loadingPage2 = new APIListView(json2, this, loadingPopup, searchinput, totalPages, currentPage);
                            // await Navigation.PopAllPopupAsync();
                            await Navigation.PushPopupAsync(loadingPage2);
                        }
                    }
                    else
                    {
                        justsearched = false;
                        //  viewModel.ClearNamePlc("search...");
                        await DisplayAlert("Error", "Could not reach database.\nCheck your internet conenction.", "OK");

                        await Navigation.PopAllPopupAsync();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public Task <string> AddCustomButton(INavigation navigation, LoadingPopup loadingPage)
        {
            //apo edw kai katw gia na ginei to return
            var tcs  = new TaskCompletionSource <string>();
            var page = new PopupPage();



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

            btnOk.Clicked += async(s, e) =>
            {
                // close page

                await navigation.RemovePopupPageAsync(page);

                // pass result
                tcs.SetResult("ok");
            };
            var slButtons = new StackLayout
            {
                Children = { btnOk },
                //Children = { btnOk, btnCancel },
            };
            //apo edw kai panw gia na ginei to return



            //var layout = new StackLayout
            //{

            //    VerticalOptions = LayoutOptions.CenterAndExpand,
            //    HorizontalOptions = LayoutOptions.CenterAndExpand,
            //    Orientation = StackOrientation.Vertical,
            //    //Children = { lblTitle, lblMessage, carview, slButtons },
            //    Children = {  carview },

            //};

            // create and show page
            //var page = new ContentPage();
            //page.Content = layout;

            var carview = new CreateCustomButton(timofday);

            var layout = new StackLayout
            {
                //  Children = { carview.Content, slButtons }
                Children = { carview.Content }
            };

            page.Content = layout;
            navigation.RemovePopupPageAsync(loadingPage);
            navigation.PushPopupAsync(page);

            // open keyboard
            //txtInput.Focus();

            // code is waiting her, until result is passed with tcs.SetResult() in btn-Clicked
            // then proc returns the result
            return(tcs.Task);
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        public Task <string> AddCustomButton(INavigation navigation, LoadingPopup loadingPage)
        {
            //apo edw kai katw gia na ginei to return
            var tcs  = new TaskCompletionSource <string>();
            var page = new PopupPage();



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

            var slButtons = new StackLayout
            {
                Children = { btnOk },
                //Children = { btnOk, btnCancel },
            };
            //apo edw kai panw gia na ginei to return



            //var layout = new StackLayout
            //{

            //    VerticalOptions = LayoutOptions.CenterAndExpand,
            //    HorizontalOptions = LayoutOptions.CenterAndExpand,
            //    Orientation = StackOrientation.Vertical,
            //    //Children = { lblTitle, lblMessage, carview, slButtons },
            //    Children = {  carview },

            //};

            // create and show page
            //var page = new ContentPage();
            //page.Content = layout;

            var carview = new CalcCal();

            //carview.BackgroundColor = Color.FromHex("#c0cca7") ;
            page.BackgroundColor = Color.NavajoWhite;
            carview.MealFrame.BackgroundColor = Color.NavajoWhite;
            var layout = new StackLayout
            {
                Children = { carview.Content, slButtons }
            };

            page.Content = layout;
            // page.BackgroundColor = Color.FromHex("#c0cca7");
            page.BackgroundColor = Color.NavajoWhite;

            btnOk.BackgroundColor = Color.DarkTurquoise;
            navigation.RemovePopupPageAsync(loadingPage);
            navigation.PushPopupAsync(page);
            btnOk.Clicked += async(s, e) =>
            {
                // close page
                if (carview.SliderGoalCalories.Text == "" || carview.SliderGoalCalories.Text == null)
                {
                    string myinput = await MainPage.CustomAlert(this.Navigation, "Goal Calories not calculated.\nCancel?");

                    if (myinput == "yes")
                    {
                    }
                    if (myinput == "no")
                    {
                        return;
                    }
                }
                if (carview.SliderGoalCalories.Text != "" && carview.SliderGoalCalories.Text != null)
                {
                    var cal = Convert.ToDouble(carview.SliderGoalCalories.Text.Replace(" Calories.", ""));
                    Calories.Text = cal.ToString();
                    Calories_TextChanged(null, null);//ginetai apo dw update twn timwn
                }
                await navigation.RemovePopupPageAsync(page);

                ApplyShadowsLocal();
                // pass result
                tcs.SetResult("ok");
            };
            // open keyboard
            //txtInput.Focus();

            // code is waiting her, until result is passed with tcs.SetResult() in btn-Clicked
            // then proc returns the result
            return(tcs.Task);
        }
Ejemplo n.º 10
0
        private async void Calendar_CellTapped(object sender, CalendarCell e)
        {
            var x = e as CalendarDateCell;

            if (x != null)
            {
                if (lastdateselected.Date != x.Date)
                {
                    lastdateselected = x.Date;
                    return;
                }

                var loading = new LoadingPopup();
                await Navigation.PushPopupAsync(loading);

                var      data  = Application.Current.Properties;
                DateTime start = (calendar as RadCalendar).MinDate;
                var      num   = (x.Date - start.Date).TotalDays + 1;
                var      food  = "";

                if (x.Date == DateTime.Now.Date)
                {
                    food = data["todayspressedlist"].ToString();

                    if (food.Length == 0)
                    {
                        var alert1 = new PopupAlert("No data for selected date.");
                        await Navigation.RemovePopupPageAsync(loading);

                        await Navigation.PushPopupAsync(alert1);

                        return;
                    }
                }
                else
                {
                    //   var num = (DateTime.Now.Date - x.Date).TotalDays;


                    bool exists = data.Any(p => p.Key == num + "day");
                    if (!exists)
                    {
                        var alert1 = new PopupAlert("No data for selected date.");
                        await Navigation.RemovePopupPageAsync(loading);

                        await Navigation.PushPopupAsync(alert1);

                        return;
                    }
                    else
                    {
                        food = data[num + "day"].ToString();
                    }
                }
                var list = new List <int>();
                int inde = 0;

                if (x.Date == DateTime.Now.Date)
                {
                    if (food == "")
                    {
                        var alert1 = new PopupAlert("No data for selected date.");
                        await Navigation.RemovePopupPageAsync(loading);

                        await Navigation.PushPopupAsync(alert1);

                        return;
                    }
                    do
                    {
                        //if(food[inde] == ',')
                        //{
                        //    inde += 1;
                        //    continue;
                        //}

                        var q = "";// + ",";
                        do
                        {
                            q    += food[inde].ToString();// + ",";
                            inde += 1;
                        } while (food[inde].ToString() != ",");
                        inde = 0;
                        if (!list.Contains(Convert.ToInt32(q.ToString())))
                        {
                            list.Add(Convert.ToInt32(q.ToString()));
                        }

                        q += ",";
                        // food = food.Replace(q, "");
                        int    qLength   = q.Length;
                        int    chRemoved = 0;
                        int    tempInt   = 0;
                        string temp      = "";
                        for (int ii = 0; ii < food.Length; ii++)
                        {
                            if (tempInt != qLength)
                            {
                                temp    += food[ii - chRemoved];
                                tempInt += 1;
                            }
                            if (temp == q)
                            {
                                food       = food.Remove(ii - tempInt + 1 - chRemoved, tempInt);
                                chRemoved += tempInt;
                                tempInt    = 0;
                                temp       = "";
                            }
                            else if (temp.Contains(","))
                            {
                                temp    = "";
                                tempInt = 0;
                            }
                        }

                        if (food.Length == 0)
                        {
                            break;
                        }
                        // inde += 1;
                    } while (true);
                }
                string show = "";
                inde = 0;
                if (x.Date == DateTime.Now.Date)
                {
                    foreach (var y in list)
                    {
                        if (data["removedClassIds"].ToString().Contains(list[inde].ToString() + ","))
                        {
                            inde += 1;
                            continue;
                        }
                        var q = JsonConvert.DeserializeObject <FoodModel>(data[list[inde] + "food"].ToString());
                        if (x.Date == DateTime.Now.Date)
                        {
                            show += q.Name + " : " + q.TimesPressed + ". \n";
                        }

                        //kyr edw prepei na mpei check an einai simera h oxi.
                        //an einai pairnei to q.TimesPressed. alliws prepei na apothikeyw st telos tis meras ta TimesPressed kapou.
                        inde += 1;
                    }
                }
                else
                {
                    try
                    {
                        show = data[num + "day"].ToString();
                    }
                    catch
                    {
                        var alert1 = new PopupAlert("No data for selected date.");
                        await Navigation.RemovePopupPageAsync(loading);

                        await Navigation.PushPopupAsync(alert1);

                        return;
                    }
                }
                var alert = new PopupAlert(show);
                await Navigation.RemovePopupPageAsync(loading);

                await Navigation.PushPopupAsync(alert);
            }
        }