Beispiel #1
0
        private void TryAddLoadMoreButton(IEnumerable <ITweetable> received)
        {
            if (!ActivateLoadMoreButton)
            {
                return;
            }

            if (Source == null || !Source.Any())
            {
                return;
            }

            ITweetable olderTweetReceived;
            ITweetable nextTweet;

            olderTweetReceived = received.OrderBy(item => item.Id).FirstOrDefault();

            if (olderTweetReceived == null)
            {
                return;
            }

            nextTweet = Source.FirstOrDefault(item => item.Id < olderTweetReceived.Id);

            if (nextTweet == null)
            {
                return;
            }

            int      avgTime = DecisionMaker.GetAvgTimeBetweenTweets(Source);
            TimeSpan diff    = olderTweetReceived.CreatedDate - nextTweet.CreatedDate;

            if (diff.TotalSeconds > 4 * avgTime && !(nextTweet is LoadMoreTweetable))
            {
                Source.Add(new LoadMoreTweetable {
                    Id = olderTweetReceived.Id - 1
                });
            }
        }
Beispiel #2
0
        IEnumerable <ITweetable> AddLoadMoreButtons(IEnumerable <ITweetable> cache)
        {
            var    list    = cache.ToList();
            int    avgTime = DecisionMaker.GetAvgTimeBetweenTweets(Source);
            double sumTime = 0;

            for (int i = 1; i < list.Count; i++)
            {
                double diff = Math.Abs((list[i].CreatedDate - list[i - 1].CreatedDate).TotalSeconds);
                sumTime += diff;

                if (sumTime != 0 && i > 1 &&
                    diff > 10 * (sumTime / (i - 1)) && diff > 5 * avgTime &&
                    diff > 200)
                {
                    yield return new LoadMoreTweetable {
                               Id = list[i].Id + 1
                    }
                }
                ;

                yield return(list[i]);
            }
        }