private async Task ViewLoaded()
        {
            if (!_viewModelLoaded)
            {
                IsBusy = true;
                var athlete = await _stravaService.GetAthleteAsync();

                var statistics = await _stravaService.GetStatsAsync(athlete.Id.ToString());

                RunStatistics    = StatisticsHelper.GetRunStatistics(statistics);
                RideStatistics   = StatisticsHelper.GetRideStatistics(statistics);
                _viewModelLoaded = true;
                IsBusy           = false;
            }
        }
Beispiel #2
0
        private async Task LoadAsync()
        {
            // clear old value // TODO configure ioc to give a new VM per call
            ClearProperties();

            string currentParameter  = (string)NavigationService.CurrentParameter;
            bool   authenticatedUser = string.IsNullOrEmpty(currentParameter);

            if (authenticatedUser)
            {
                Athlete = await _stravaService.GetAthleteAsync();
                await GetStarredSegmentsAsync();
            }
            else
            {
                Athlete = await _stravaService.GetAthleteAsync(currentParameter);
                await GetStarredSegmentsAsync(Athlete.Id.ToString());
            }

            if (Athlete != null)
            {
                List <Task> tasks = new List <Task>();

                _currentAthleteId = Athlete.Id.ToString();

                tasks.Add(GetFollowersAsync(_currentAthleteId, authenticatedUser));
                tasks.Add(GetFriendsAsync(_currentAthleteId, authenticatedUser));
                if (!string.IsNullOrEmpty(currentParameter))
                {
                    tasks.Add(GetMutualFriendsAsync(_currentAthleteId));
                }
                tasks.Add(GetKomsAsync(_currentAthleteId));

                await Task.WhenAll(tasks);
            }
        }
Beispiel #3
0
        //TODO: Glenn - Can't remember, was this set up as async void for fire and forget reasons?
        private async void ViewLoaded()
        {
            if (!_viewModelLoaded)
            {
                //TODO: Glenn - Check loaded version with saved version in Settings, if different show what's new dialog and overwrite settings field
                //AppInfoDialog appInfo = new AppInfoDialog();
                //await appInfo.ShowAsync();

                ActivityFeedFilter filter = await _settingsService.GetStoredActivityFeedFilterAsync();

                var athlete = await _stravaService.GetAthleteAsync();

                ApplyActivityFeedFilter(filter);

                _viewModelLoaded = true;
            }
        }
        private async Task LoadActivityDetails(string activityId)
        {
            //We need to unload (remove the PropertyChanged event handler) from the
            //UserMeasurementUnitStatisticsDetail items to avoid memory leaks
            //Not prety, but I don't see a better solution atm
            //ToDo: maybe use CleanUp in order to unwire eventhandlers?
            SelectedActivity?.Statistics?.Where(a => a is UserMeasurementUnitStatisticsDetail)
            .Select(a => a as UserMeasurementUnitStatisticsDetail).ToList().ForEach(a => a.Unload());

            Kudos.Clear();
            Comments.Clear();
            RelatedAthletes.Clear();

            //TODO: Glenn - Why aren't we receiving private activities?
            Activity activity = null;

            try
            {
                activity = await _stravaService.GetActivityAsync(activityId, true);
            }
            catch (Exception ex)
            {
                var t = ex.Message;
            }
            _athlete = await _stravaService.GetAthleteAsync();

            if (activity != null)
            {
                SelectedActivity = activity;

                if (activity.KudosCount > 0 && activity.Kudos != null && activity.Kudos.Any())
                {
                    foreach (AthleteSummary kudo in activity.Kudos)
                    {
                        Kudos.Add(kudo);
                    }
                }

                if (activity.CommentCount > 0 && activity.Comments != null && activity.Comments.Any())
                {
                    foreach (Comment comment in activity.Comments)
                    {
                        Comments.Add(comment);
                    }
                }

                if (activity.OtherAthleteCount > 0 && activity.RelatedActivities != null && activity.RelatedActivities.Any())
                {
                    foreach (ActivitySummary relatedActivity in activity.RelatedActivities)
                    {
                        RelatedAthletes.Add(relatedActivity.Athlete);
                    }
                }

                //Currently the Public API of Strava will not give us Segments info for 'other' athletes then the one logged in
                HasSegments = SelectedActivity.SegmentEfforts != null;

                //Currently the Public API of Strava will not give us the Photo links for 'other' athletes then the one logged in
                //But we do get the photo count, so we also need to verify the current user vs the one from the activity
                HasPhotos     = _athlete.Id == SelectedActivity.Athlete.Id && SelectedActivity.TotalPhotoCount > 0;
                HasKudoed     = _athlete.Id == SelectedActivity.Athlete.Id || SelectedActivity.HasKudoed;
                IsEditEnabled = _athlete.Id == SelectedActivity.Athlete.Id;

                //TODO: Glenn - Why oh why are we not yet able to show/hide PivotItems through Visibility binding
                ServiceLocator.Current.GetInstance <IMessenger>().Send <PivotMessage <ActivityPivots> >(new PivotMessage <ActivityPivots>(ActivityPivots.Segments, HasSegments), Tokens.ActivityPivotMessage);
                ServiceLocator.Current.GetInstance <IMessenger>().Send <PivotMessage <ActivityPivots> >(new PivotMessage <ActivityPivots>(ActivityPivots.Photos, HasPhotos), Tokens.ActivityPivotMessage);

                ServiceLocator.Current.GetInstance <IMessenger>()
                .Send <PolylineMessage>(!string.IsNullOrEmpty(activity?.Map.SummaryPolyline)
                        ? new PolylineMessage(activity.Map.GeoPositions)
                        : new PolylineMessage(new List <BasicGeoposition>()), Tokens.ActivityPolylineMessage);
            }
        }