protected async override void OnAppearing()
        {
            EnableLoader();

            var user = await _db.GetObjectAsync <FacebookUser> (Const.USER_AKAVACHE_KEY);

            bool   exceptionFlag = false;
            string exceptionMsg  = string.Empty;

            try
            {
                var info = await PartyAdvisorApiHelper.GetUserInfo(user.AccessToken);

                lblUserName.Text   = info.FullName;
                imgUser.Source     = info.FacebookPictureUrl;
                lblUserPoints.Text = string.Format("{0} pts", info.Points);
                lblGender.Text     = string.Format("{0}{1}", (char.ToUpper(info.Gender[0])), info.Gender.Substring(1));
            }

            catch (WebException e)
            {
                int status = (int)e.Status;

                exceptionFlag = true;

                //name resolution failure, aka no internet
                if (status == 1)
                {
                    exceptionMsg = Const.APP_REQUIRES_INTERNET;
                }
                else
                {
                    exceptionMsg = Const.GLOBAL_ERROR_MSG;
                }
            }

            catch (Exception ex)
            {
                exceptionFlag = true;
                exceptionMsg  = Const.GLOBAL_ERROR_MSG;
            }

            finally
            {
                DisableLoader();
            }

            if (exceptionFlag)
            {
                await DisplayAlert("Error", exceptionMsg, "Ok");

                await App.Navigation.PopModalAsync();
            }
        }
Exemple #2
0
        private async Task <List <Place> > GetServerPlaces()
        {
            var user = await _db.GetObjectAsync <FacebookUser> (Const.USER_AKAVACHE_KEY);

            //no token ? redirect to login page
            if (user == null || string.IsNullOrWhiteSpace(user.AccessToken))
            {
                await Navigation.PushModalAsync(new LoginPage());
            }

            var places = await PartyAdvisorApiHelper.GetPlaces(user.AccessToken);

            return(places);
        }
        protected async override void OnAppearing()
        {
            EnableLoader();

            var user = await _db.GetObjectAsync <FacebookUser> (Const.USER_AKAVACHE_KEY);

            bool   exceptionFlag = false;
            string exceptionMsg  = string.Empty;

            try
            {
                var rankingItems = await PartyAdvisorApiHelper.GetRanking(user.AccessToken);

                lvRanking.ItemsSource = rankingItems;
            }

            catch (WebException e)
            {
                int status = (int)e.Status;

                exceptionFlag = true;

                //name resolution failure, aka no internet
                if (status == 1)
                {
                    exceptionMsg = Const.APP_REQUIRES_INTERNET;
                }
                else
                {
                    exceptionMsg = Const.GLOBAL_ERROR_MSG;
                }
            }
            catch (Exception ex)
            {
                exceptionFlag = true;
                exceptionMsg  = Const.GLOBAL_ERROR_MSG;
            }

            DisableLoader();

            if (exceptionFlag)
            {
                await DisplayAlert("Error", exceptionMsg, "Ok");

                await App.Navigation.PopModalAsync();
            }
        }
Exemple #4
0
        private async Task <PlaceDetails> GetDetails(string accessToken)
        {
            PlaceDetails details = null;

            try
            {
                details = await PartyAdvisorApiHelper.GetGenderStats(accessToken, PlaceId);

                lblLastUpdate.Text = string.Format("Last Update\n [{0:hh:mm tt}]", DateTime.Now);
                return(details);
            }

            catch (Exception ex)
            {
                return(null);
            }
        }
Exemple #5
0
        protected async override void OnAppearing()
        {
            EnableLoader();

            //if we reach this point; places must be in database
            var places = await _db.GetObjectAsync <List <Place> >(Const.PLACES_AKAVACHE_KEY);

            var user = await _db.GetObjectAsync <FacebookUser> (Const.USER_AKAVACHE_KEY);

            _accessToken = user.AccessToken;

            var place = places.SingleOrDefault(x => x.Id == PlaceId);

            lblPlaceName.Text    = place.Name;
            lblPlaceAddress.Text = place.Address;

            await FillPage(user.AccessToken);

            DisableLoader();

            FacebookEvent lastFbEvent = null;

            try
            {
                lastFbEvent = await PartyAdvisorApiHelper.GetNextFacebookEvent(user.AccessToken, place.FacebookId);

                var facebookHours = await PartyAdvisorApiHelper.GetHours(user.AccessToken, place.FacebookId);

                if (facebookHours != null && !string.IsNullOrWhiteSpace(facebookHours.StartTime))
                {
                    lblHours.Text = string.Format("[{0}-{1}]", facebookHours.StartTime, string.IsNullOrWhiteSpace(facebookHours.EndTime) ? "?" : facebookHours.EndTime);
                }
            }

            catch (Exception ex)
            {
                //TODO log error
            }

            if (lastFbEvent != null && lastFbEvent.EndTime > DateTimeOffset.Now)
            {
                lblFacebookLink.IsVisible   = true;
                _facebookEvent              = lastFbEvent;
                lblFacebookLink.IsUnderline = true;
            }
        }
Exemple #6
0
        protected async override void OnAppearing()
        {
            List <Place> places;

            EnableLoader();

            bool   exceptionFlag = false;
            string exceptionMsg  = string.Empty;

            try {
                var service  = DependencyService.Get <ILocationService> ();
                var position = service.GetPosition();

                //optimisation thing: this can be done in parallel
                DateTimeOffset datePingServer = await PartyAdvisorApiHelper.GetPlacePing();

                long?datePingTicksLocal = await _db.GetObjectAsync <long?>(Const.PLACES_AKAVACHE_PING_KEY);

                //outdated places info
                //comparison of ticks bc it looks like the serialization of datetimeoffset is not as precise as comparison of ticks
                if (datePingTicksLocal == null || datePingTicksLocal.Value < datePingServer.Ticks)
                {
                    places = await GetServerPlaces();

                    //we save the new places
                    await _db.InsertObjectAsync <List <Place> > (Const.PLACES_AKAVACHE_KEY, places);

                    //we save the ping value
                    await _db.InsertObjectAsync <long?> (Const.PLACES_AKAVACHE_PING_KEY, datePingServer.Ticks);
                }

                //updated infos
                else
                {
                    //test if places already saved in database
                    places = await _db.GetObjectAsync <List <Place> >(Const.PLACES_AKAVACHE_KEY);

                    if (places == null)
                    {
                        places = await GetServerPlaces();

                        await _db.InsertObjectAsync <List <Place> > (Const.PLACES_AKAVACHE_KEY, places);
                    }
                }

                List <PlaceDistance> pdList = new List <PlaceDistance>();

                foreach (var place in places)
                {
                    var pd = new PlaceDistance(place, position);
                    pdList.Add(pd);
                }

                lvPlaces.ItemsSource = pdList.OrderBy(x => x.Distance).ToList();
            }

            catch (WebException ex)
            {
                int status = (int)ex.Status;
                exceptionFlag = true;

                //name resolution failure, aka no internet
                exceptionMsg = status == 1 ? Const.APP_REQUIRES_INTERNET : Const.GLOBAL_ERROR_MSG;
            }

            catch (PositionNotFoundException ex)
            {
                exceptionFlag = true;
                exceptionMsg  = ex.Message;
            }

            catch (Exception ex)
            {
                exceptionFlag = true;
                exceptionMsg  = Const.GLOBAL_ERROR_MSG;
            }

            finally
            {
                DisableLoader();
            }

            if (exceptionFlag)
            {
                await DisplayAlert("Error", exceptionMsg, "Ok");

                await App.Navigation.PopModalAsync();
            }
        }