示例#1
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);
            }
        }
示例#2
0
        private async void Delayer()
        {
            do
            {
                await Task.Delay(3800);

                if (checkdelay && loadispushed)
                {
                    if (PopupAlert.isYesNoActive)
                    {
                        continue;
                    }
                    globalAlert = new PopupAlert("This operation is taking too long.....\nCancel?", false);

                    await Navigation.PushPopupAsync(globalAlert);
                }
            } while (loadispushed);



            // viewModel.ClearNamePlc("search...");
        }
示例#3
0
        private async void Button_ClickedSave(object sender, EventArgs e)
        {
            if (Calories.Text == "")
            {
                return;
            }
            if (!Double.TryParse(Calories.Text, out double cal))
            {
                return;
            }
            if (!Double.TryParse(FatMg.Text, out double fat))
            {
                return;
            }
            if (!Double.TryParse(CarbsMg.Text, out double carbs))
            {
                return;
            }
            if (!Double.TryParse(ProteinMg.Text, out double prot))
            {
                return;
            }
            var data = Application.Current.Properties;

            data["goalcal"]         = cal;
            data["goalcarb"]        = carbs;
            data["goalprot"]        = prot;
            data["goalfat"]         = fat;
            data["goalslidervalue"] = slidervalueforsave;

            data["goalset"] = "true";

            await Application.Current.SavePropertiesAsync();

            var alert = new PopupAlert("Goals saved.");
            await Navigation.PushPopupAsync(alert);

            return;
        }
示例#4
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();
                    }
                }
            }
        }
示例#5
0
 private async void RadButton_Clicked(object sender, EventArgs e)
 {
     var al = new PopupAlert("This will reset todays calories.\nContinue?", false, false, this);
     await Navigation.PushPopupAsync(al);
 }
示例#6
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);
            }
        }