Exemple #1
0
        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);
        }
Exemple #2
0
        public async Task GetPosts()
        {
            var facebookViewModels = await GetFacebookFeed();

            var twitterViewModels = await GetTwitterFeed();

            var allViewModels = new ObservableRangeCollection <BaseContentCardViewModel> ();

            // TODO: Need to further develop this system of ordering
            // Need to be able to toggle between popularity and time
            //			allViewModels.AddRange (facebookViewModels);
            //			allViewModels.AddRange (twitterViewModels);

            Random rnd = new Random();

            int    total  = facebookViewModels.Count + twitterViewModels.Count;
            double fbLuck = 0;
            double tLuck  = 0;

            fbLuck = facebookViewModels.Count / (double)total;
            tLuck  = twitterViewModels.Count / (double)total;

            for (int i = 0; i < total; i++)
            {
                int newTotal = 0;
                var dicey    = rnd.NextDouble();
                if (dicey < fbLuck)
                {
                    allViewModels.Add(facebookViewModels.First());
                    facebookViewModels.RemoveAt(0);
                }
                else
                {
                    allViewModels.Add(twitterViewModels.First());
                    twitterViewModels.RemoveAt(0);
                }
                newTotal = facebookViewModels.Count + twitterViewModels.Count;
                if (newTotal != 0)
                {
                    fbLuck = facebookViewModels.Count / (double)newTotal;
                    tLuck  = twitterViewModels.Count / (double)newTotal;
                }
            }



            //
            //			if(OrderBy == OrderBy.Time)
            //			{
            //				allViewModels = new ObservableRangeCollection<BaseContentCardViewModel> (allViewModels.OrderByDescending (vm => vm.OrderByDateTime));
            //			}
            //
            CardViewModels.Clear();
            CardViewModels.AddRange(allViewModels);

            foreach (BaseContentCardViewModel viewModel in CardViewModels)
            {
                viewModel.RequestMovieViewer = RequestMovieViewer;
                viewModel.RequestPhotoViewer = RequestPhotoViewer;
                viewModel.RequestCommentPage = OnRequestCommentPage;
            }

            IsRefreshing = false;

            if (RequestCompleted != null)
            {
                RequestCompleted();
            }
        }