diff --git a/VisualChallenge/VisualChallenge.Android/Resources/Resource.designer.cs b/VisualChallenge/VisualChallenge.Android/Resources/Resource.designer.cs index 1f086b3..4727a74 100644 --- a/VisualChallenge/VisualChallenge.Android/Resources/Resource.designer.cs +++ b/VisualChallenge/VisualChallenge.Android/Resources/Resource.designer.cs @@ -1,11 +1,11 @@ #pragma warning disable 1591 //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Este código fue generado por una herramienta. +// Versión de runtime:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si +// se vuelve a generar el código. // //------------------------------------------------------------------------------ diff --git a/VisualChallenge/VisualChallenge/Models/PokemonDto.cs b/VisualChallenge/VisualChallenge/Models/PokemonDto.cs new file mode 100644 index 0000000..a116c4f --- /dev/null +++ b/VisualChallenge/VisualChallenge/Models/PokemonDto.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace VisualChallenge.Models +{ + public class PokemonDto + { + public int count { get; set; } + public object next { get; set; } + public object previous { get; set; } + [JsonProperty(PropertyName = "results")] + public List PokemonDetalleDto { get; set; } + + } + public class PokemonDetalleDto + { + public string name { get; set; } + public string url { get; set; } + } +} diff --git a/VisualChallenge/VisualChallenge/Services/IPokemonServices.cs b/VisualChallenge/VisualChallenge/Services/IPokemonServices.cs new file mode 100644 index 0000000..28a6da6 --- /dev/null +++ b/VisualChallenge/VisualChallenge/Services/IPokemonServices.cs @@ -0,0 +1,15 @@ +using Refit; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace VisualChallenge.Services +{ + public interface IPokemonServices + { + [Get("/pokemon-form/?limit=151&offset=0")] + Task GetListPokemon(); + } +} diff --git a/VisualChallenge/VisualChallenge/View/CollectionView.xaml b/VisualChallenge/VisualChallenge/View/CollectionView.xaml new file mode 100644 index 0000000..846e4f5 --- /dev/null +++ b/VisualChallenge/VisualChallenge/View/CollectionView.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + diff --git a/VisualChallenge/VisualChallenge/View/CollectionView.xaml.cs b/VisualChallenge/VisualChallenge/View/CollectionView.xaml.cs new file mode 100644 index 0000000..b425610 --- /dev/null +++ b/VisualChallenge/VisualChallenge/View/CollectionView.xaml.cs @@ -0,0 +1,59 @@ +using Newtonsoft.Json; +using System; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using VisualChallenge.Models; +using VisualChallenge.Services; +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace VisualChallenge.View +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class CollectionViewPage : ContentPage + { + public ObservableCollection PokemonList { get; set; } + + public CollectionViewPage() + { + InitializeComponent(); + GetPokemons(); + } + + private void GetPokemons() + { + try + { + var pokemonServices = Refit.RestService.For("https://pokeapi.co/api/v2/"); + + var response = pokemonServices.GetListPokemon().Result; + + if (response.StatusCode.Equals(HttpStatusCode.OK)) + { + var jsonString = response.Content.ReadAsStringAsync().Result; + var lis = JsonConvert.DeserializeObject(jsonString); + PokemonList = new ObservableCollection(lis.PokemonDetalleDto.ToList()); + listPage.ItemsSource = PokemonList; + } + } + catch ( Exception ex) { + Debug.Write("Error"); + } + } + + async void Handle_ItemTapped(object sender, ItemTappedEventArgs e) + { + if (e.Item == null) + return; + + await DisplayAlert("Item Tapped", "An item was tapped.", "OK"); + + //Deselect Item + ((ListView)sender).SelectedItem = null; + } + } +} diff --git a/VisualChallenge/VisualChallenge/VisualChallenge.csproj b/VisualChallenge/VisualChallenge/VisualChallenge.csproj index c971abe..4a7b2ec 100644 --- a/VisualChallenge/VisualChallenge/VisualChallenge.csproj +++ b/VisualChallenge/VisualChallenge/VisualChallenge.csproj @@ -11,6 +11,7 @@ + @@ -20,4 +21,25 @@ VisualChallengePage.xaml + + + + MSBuild:UpdateDesignTimeXaml + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + \ No newline at end of file diff --git a/VisualChallenge/VisualChallenge/VisualChallengePage.xaml b/VisualChallenge/VisualChallenge/VisualChallengePage.xaml index 305cee4..09acf9e 100644 --- a/VisualChallenge/VisualChallenge/VisualChallengePage.xaml +++ b/VisualChallenge/VisualChallenge/VisualChallengePage.xaml @@ -17,7 +17,7 @@