Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CollectionViewChallenge/CollectionViewChallenge/RssFeedItem.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="CollectionViewChallenge.Views.CollectionViewChallengePage">
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="CollectionViewChallenge.Views.CollectionViewChallengePage">
<ContentPage.Content>
<StackLayout>
<!-- Use your own layout and functionality here! -->
<CollectionView>
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>This is a CollectionView!</x:String>
<x:String>Your feedback on the experience of converting a ListView to a CollectionView is incredibly appreciated.</x:String>
<x:String>Here are three general questions:</x:String>
<x:String>1. How was the experience of converting your existing ListView to a CollectionView?</x:String>
<x:String>2. How is the performance compared to the ListView?</x:String>
<x:String>3. Is there a specific piece of functionality that you'd like to see?</x:String>
</x:Array>
</CollectionView.ItemsSource>
<StackLayout Padding="15, 25, 15, 15" Spacing="10" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<Label FontSize="18" Text="Lector de RSS con CollectionView">
</Label>
<CollectionView x:Name="clvRssItems">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="5">
<Label Text="{Binding .}" d:Text="Design Time Data" FontSize="10"/>
<StackLayout Spacing="10" Padding="15">
<Label Text="{Binding Title}" FontSize="16">
</Label>
<Label Text="{Binding AuthorEmail}" FontSize="12">
</Label>
<Label Text="{Binding PublishDate}" FontSize="12">
</Label>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<!--<Label FontSize="18" Text="Lector de RSS con ListView">
</Label>
<ListView x:Name="lstRssItems" HasUnevenRows="true" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Spacing="10" Padding="15">
<Label Text="{Binding Title}" FontSize="16">
</Label>
<Label Text="{Binding AuthorEmail}" FontSize="12">
</Label>
<Label Text="{Binding PublishDate}" FontSize="12">
</Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>-->
</StackLayout>
</ContentPage.Content>
</ContentPage>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<List<RssFeedItem>> 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();
});
}
}
}
}