public override async Task DidLoad() { // Only fetch new comments as needed if (PrimaryCardViewModel.CommentCount != 0 || PrimaryCardViewModel.CommentViewModels.Count == 0) { await PrimaryCardViewModel.GetComments(); } // populate all cards var viewModels = PrimaryCardViewModel.CommentViewModels.OrderBy(vm => vm.OrderByDateTime).ToList(); // Group by the relative string of the 15 minute increment var groups = viewModels.GroupBy(x => { var stamp = x.OrderByDateTime; stamp = stamp.AddMinutes(-(stamp.Minute % 15)); stamp = stamp.AddMilliseconds(-stamp.Millisecond - 1000 * stamp.Second); return(stamp.ToRelativeString()); }) .Select(g => new CommentGroup(new HeaderCardViewModel(g.Key), g.Distinct())); var contentViewModels = new List <BaseCardViewModel> (); // Format the new grouping by including the headers in the main list PrimaryCardViewModel.ShowCommentButton = false; contentViewModels.Add(PrimaryCardViewModel); for (int i = 0; i < groups.Count(); i++) { var commentGroup = groups.ElementAtOrDefault(i); if (i == 0) { commentGroup.Header.Position = Position.Top; } contentViewModels.Add(commentGroup.Header); foreach (BaseContentCardViewModel viewModel in commentGroup.Content) { contentViewModels.Add(viewModel); } } // Add the footer header for "now" contentViewModels.Add(new HeaderCardViewModel(ApplicationResources.Now, Position.Bottom)); CardViewModels.Clear(); CardViewModels.AddRange(contentViewModels); }
private async void ReplyCommandExecute() { // TODO: Determine if we need to track the response var response = ServiceResponseType.ERROR; try { _hudService.Show(); await PrimaryCardViewModel.Reply(Comments); await DidLoad(); Comments = string.Empty; if (RequestDismissKeyboard != null) { RequestDismissKeyboard(); } } finally { _hudService.Dismiss(); } }