Ejemplo n.º 1
0
        public async Task <string> SetUpcomingEvents()
        {
            //Call Google API
            var googleService = new GoogleService();

            publicYear  = dateTimeNow.Year;
            publicMonth = (dateTimeNow.Month);
            publicDay   = dateTimeNow.Day;

            string timeZoneOffset = DateTimeOffset.Now.ToString();

            string[] timeZoneOffsetParsed = timeZoneOffset.Split('-');
            int      timeZoneNum          = Int32.Parse(timeZoneOffsetParsed[1].Substring(0, 2));

            var currentTimeinUTC = DateTime.Now.ToUniversalTime();

            uTCHour = (currentTimeinUTC.Hour - timeZoneNum);
            currentLocalUTCMinute = currentTimeinUTC.Minute;


            var jsonResult = await googleService.GetAllTodaysEventsList(publicYear, publicMonth, publicDay, timeZoneNum);


            //Return error if result is empty
            if (jsonResult == null)
            {
                await DisplayAlert("Oops!", "There was an error listing your events", "OK");
            }

            //Parse the json using EventsList Method

            try
            {
                var parsedResult = JsonConvert.DeserializeObject <Methods.GetEventsListMethod>(jsonResult);

                //Create Item List
                var eventList     = new List <string>();
                var dateList      = new List <string>();
                var startTimeList = new List <string>();
                var endTimeList   = new List <string>();


                //Separate out just the EventName
                foreach (var events in parsedResult.Items)
                {
                    eventList.Add(events.EventName);
                    dateList.Add(events.Start.DateTime.ToString());
                    startTimeList.Add(events.Start.DateTime.ToString());
                    endTimeList.Add(events.End.DateTime.ToString());
                }

                try
                {
                    eventBtn2.Text = eventList[1];
                }
                catch (ArgumentOutOfRangeException e)
                {
                    eventBtn2.Text = "";
                }

                try
                {
                    eventBtn1.Text = eventList[0];

                    await noEventsButton.FadeTo(0, 2000);

                    noEventsButton.IsVisible = false;

                    eventBtn1.IsVisible = true;
                    eventBtn2.IsVisible = true;
                    await Task.WhenAll(eventBtn1.FadeTo(1, 2000), eventBtn2.FadeTo(1, 2000));
                }
                catch (ArgumentOutOfRangeException e)
                {
                    await Task.WhenAll(eventBtn1.FadeTo(0, 2000), eventBtn2.FadeTo(0, 2000));

                    eventBtn1.IsVisible = false;
                    eventBtn2.IsVisible = false;

                    noEventsButton.IsVisible = true;
                    await noEventsButton.FadeTo(1, 2000);
                }

                return(null);
            }
            catch (ArgumentNullException e)
            {
                //LoginPage.accessToken = LoginPage.refreshToken;
                //await Navigation.PopAsync();
                //Console.WriteLine(LoginPage.accessToken);
                return(null);
            }
        }