private async Task LoadActivityDetails(string activityId) { Kudos.Clear(); Comments.Clear(); RelatedAthletes.Clear(); var activity = await _stravaService.GetActivityAsync(activityId, true); var 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; //TODO: Glenn - Why oh why are we not yet able to show/hide PivotItems through Visibility bindable ServiceLocator.Current.GetInstance <IMessenger>().Send <PivotMessage>(new PivotMessage(Pivots.Segments, HasSegments)); ServiceLocator.Current.GetInstance <IMessenger>().Send <PivotMessage>(new PivotMessage(Pivots.Photos, HasPhotos)); ServiceLocator.Current.GetInstance <IMessenger>() .Send <ActivityPolylineMessage>(!string.IsNullOrEmpty(activity?.Map.SummaryPolyline) ? new ActivityPolylineMessage(activity.Map.GeoPositions) : new ActivityPolylineMessage(new List <BasicGeoposition>())); } }
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); } }