diff --git a/CollectionViewChallenge/CollectionViewChallenge/RssFeedItem.cs b/CollectionViewChallenge/CollectionViewChallenge/RssFeedItem.cs new file mode 100644 index 0000000..7faa823 --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/RssFeedItem.cs @@ -0,0 +1,12 @@ +namespace CollectionViewChallenge +{ + public class RssFeedItem + { + public string Title { get; set; } + public string Description { get; set; } + public string Link { get; set; } + public string AuthorEmail { get; set; } + public int Id { get; set; } + public string PublishDate { get; set; } + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml index f2da7f7..370c6ad 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml +++ b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml @@ -1,32 +1,41 @@ - - + + - - - - - - This is a CollectionView! - Your feedback on the experience of converting a ListView to a CollectionView is incredibly appreciated. - Here are three general questions: - 1. How was the experience of converting your existing ListView to a CollectionView? - 2. How is the performance compared to the ListView? - 3. Is there a specific piece of functionality that you'd like to see? - - + + + - - + - \ No newline at end of file + diff --git a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs index 701124f..0f8c32c 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs +++ b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; +using System.Net.Http; using System.Threading.Tasks; - +using System.Xml.Linq; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -16,5 +15,49 @@ public CollectionViewChallengePage() { InitializeComponent(); } + + protected override void OnAppearing() + { + base.OnAppearing(); + LoadItems(); + } + + private async void LoadItems() + { + // cargando la lista de elementos de rss + using (HttpClient client = new HttpClient()) + { + HttpResponseMessage response = await client.GetAsync("https://www.excelsior.com.mx/rss.xml"); + if (response.IsSuccessStatusCode) + { + string rssFeedList = await response.Content.ReadAsStringAsync(); + clvRssItems.ItemsSource = await ParseFeed(rssFeedList); + //lstRssItems.ItemsSource = await ParseFeed(rssFeedList); + } + else + { + await App.Current.MainPage.DisplayAlert("Rss Feed", "Algo falló", "Aceptar"); + } + } + } + + private async Task> ParseFeed(string rss) + { + return await Task.Run(() => + { + var xdoc = XDocument.Parse(rss); + var id = 0; + return (from item in xdoc.Descendants("item") + select new RssFeedItem + { + Title = (string)item.Element("title"), + Description = (string)item.Element("description"), + Link = (string)item.Element("link"), + PublishDate = (string)item.Element("pubDate"), + AuthorEmail = (string)item.Element("author"), + Id = id++ + }).ToList(); + }); + } } -} \ No newline at end of file +}