private void ShowFirstItem() { if (Settings.Current.UserSettings.ImagesEnabled) { BackgroundDownloadImages(); } _itemsForSelectedCategories = new List <Item>(); // Use local variables to avoid repeated calls var allItems = Repository.Default.ListItems(); var lastCategories = Settings.Current.LastCategories; foreach (Item currentitem in allItems) { if (lastCategories.Contains(currentitem.Feed.Category)) { _itemsForSelectedCategories.Add(currentitem); } } // Filter out read items, if it's enabled. if (Settings.Current.UserSettings.IgnoreReadItems) { _itemsForSelectedCategories = _itemsForSelectedCategories.Where(i => !i.IsRead).ToList(); } // Nothing to work with, show the empty message if (_itemsForSelectedCategories.Count == 0) { Settings.Current.LastItemId = ""; _webView.LoadHtmlString(HtmlTemplate.EmptyHtml(), new NSUrl("/")); return; } else { switch (Settings.Current.UserSettings.SortItemsBy) { case SortBy.Site: _itemsForSelectedCategories = _itemsForSelectedCategories.SortBySite(); break; case SortBy.Date: default: _itemsForSelectedCategories = _itemsForSelectedCategories.SortByDate(); break; } UpdateArrowButtons(); // Show the first item _currentItemIndex = 0; // Use the last item that was viewed, if it exists Item item = null; if (!string.IsNullOrEmpty(Settings.Current.LastItemId)) { try { Guid guid = new Guid(Settings.Current.LastItemId); item = _itemsForSelectedCategories.FirstOrDefault(i => i.Id == guid); } catch (FormatException) { } } if (item != null) { // Put it at the start of the list, and remove it from wherever it is _itemsForSelectedCategories.Remove(item); _itemsForSelectedCategories.Insert(0, item); } else { // No saved item, use the first item = _itemsForSelectedCategories[0]; } Settings.Current.LastItemId = item.Id.ToString(); _webView.LoadHtmlString(HtmlTemplate.HtmlForItem(item), new NSUrl("/")); } }