示例#1
0
        /// <summary>
        /// Adds feedItems to the list of feedItems.
        /// All feedItems are inserted at the correct date (since the list is sorted by date)
        /// </summary>
        /// <param name="feedItems">List of feedItems to be added</param>
        private void AddFeedItems(List <EasyNewsFeedItem> feedItems)
        {
            var counter = 0;

            foreach (var article in feedItems)
            {
                // New Article is older than the oldest article in the list, append article to end
                if (counter >= FeedItems.Count)
                {
                    FeedItems.Add(article);
                }
                // Insert new Article somewhere in the middle of the array, we don't know where it is
                else
                {
                    // Iterate through Articles until we found the right date to insert our new article
                    while (counter < FeedItems.Count &&
                           FeedItems[counter].PublishingDate > article.PublishingDate)
                    {
                        counter++;
                    }
                    // All articles we searched were newer than our article => Append the article
                    if (counter == FeedItems.Count)
                    {
                        FeedItems.Add(article);
                    }
                    else
                    {
                        // Found the right date, insert the article, redo with the next one
                        FeedItems.Insert(counter, article);
                    }
                }
            }
            // ReSharper Disable All
            OnPropertyChanged("HasFeedItems");
            // ReSharper Restore All
        }