From 808eb87f7ffde68c6a5207a08a6d6c06d9bae79f Mon Sep 17 00:00:00 2001 From: Manuel Hernan Date: Mon, 29 Apr 2019 00:41:36 +0200 Subject: [PATCH] Initial Commit --- .../CollectionViewChallenge.Android.csproj | 6 + .../MainActivity.cs | 1 + .../AppDelegate.cs | 1 + .../CollectionViewChallenge.iOS.csproj | 6 + .../CollectionViewChallenge.csproj | 8 +- .../Models/ChartType.cs | 10 + .../CollectionViewChallenge/Models/Day.cs | 9 + .../CollectionViewChallenge/Models/Person.cs | 11 + .../ViewModels/Base/BaseViewModel.cs | 55 +++++ .../CollectionViewChallengeViewModel.cs | 180 +++++++++++++++ .../Views/CollectionViewChallengePage.xaml | 211 ++++++++++++++++-- .../Views/CollectionViewChallengePage.xaml.cs | 8 + 12 files changed, 478 insertions(+), 28 deletions(-) create mode 100644 CollectionViewChallenge/CollectionViewChallenge/Models/ChartType.cs create mode 100644 CollectionViewChallenge/CollectionViewChallenge/Models/Day.cs create mode 100644 CollectionViewChallenge/CollectionViewChallenge/Models/Person.cs create mode 100644 CollectionViewChallenge/CollectionViewChallenge/ViewModels/Base/BaseViewModel.cs create mode 100644 CollectionViewChallenge/CollectionViewChallenge/ViewModels/CollectionViewChallengeViewModel.cs diff --git a/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj b/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj index d2c42fc..720d330 100644 --- a/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj +++ b/CollectionViewChallenge/CollectionViewChallenge.Android/CollectionViewChallenge.Android.csproj @@ -52,6 +52,12 @@ + + 0.7.1 + + + 3.0.0.5 + diff --git a/CollectionViewChallenge/CollectionViewChallenge.Android/MainActivity.cs b/CollectionViewChallenge/CollectionViewChallenge.Android/MainActivity.cs index 72e1935..a545d6e 100644 --- a/CollectionViewChallenge/CollectionViewChallenge.Android/MainActivity.cs +++ b/CollectionViewChallenge/CollectionViewChallenge.Android/MainActivity.cs @@ -22,6 +22,7 @@ protected override void OnCreate(Bundle savedInstanceState) global::Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", "FastRenderers_Experimental"); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); + ImageCircle.Forms.Plugin.Droid.ImageCircleRenderer.Init(); LoadApplication(new App()); } public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults) diff --git a/CollectionViewChallenge/CollectionViewChallenge.iOS/AppDelegate.cs b/CollectionViewChallenge/CollectionViewChallenge.iOS/AppDelegate.cs index 3d2ece2..4f222dd 100644 --- a/CollectionViewChallenge/CollectionViewChallenge.iOS/AppDelegate.cs +++ b/CollectionViewChallenge/CollectionViewChallenge.iOS/AppDelegate.cs @@ -24,6 +24,7 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", "FastRenderers_Experimental"); global::Xamarin.Forms.Forms.Init(); + ImageCircleRenderer.Init(); LoadApplication(new App()); return base.FinishedLaunching(app, options); diff --git a/CollectionViewChallenge/CollectionViewChallenge.iOS/CollectionViewChallenge.iOS.csproj b/CollectionViewChallenge/CollectionViewChallenge.iOS/CollectionViewChallenge.iOS.csproj index 49a7105..27d5132 100644 --- a/CollectionViewChallenge/CollectionViewChallenge.iOS/CollectionViewChallenge.iOS.csproj +++ b/CollectionViewChallenge/CollectionViewChallenge.iOS/CollectionViewChallenge.iOS.csproj @@ -133,6 +133,12 @@ + + 0.7.1 + + + 3.0.0.5 + diff --git a/CollectionViewChallenge/CollectionViewChallenge/CollectionViewChallenge.csproj b/CollectionViewChallenge/CollectionViewChallenge/CollectionViewChallenge.csproj index 3ccfc60..feae574 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/CollectionViewChallenge.csproj +++ b/CollectionViewChallenge/CollectionViewChallenge/CollectionViewChallenge.csproj @@ -11,6 +11,9 @@ + + + @@ -20,9 +23,4 @@ MSBuild:UpdateDesignTimeXaml - - - - - \ No newline at end of file diff --git a/CollectionViewChallenge/CollectionViewChallenge/Models/ChartType.cs b/CollectionViewChallenge/CollectionViewChallenge/Models/ChartType.cs new file mode 100644 index 0000000..198d287 --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/Models/ChartType.cs @@ -0,0 +1,10 @@ +using Microcharts; + +namespace CollectionViewChallenge.Models +{ + public class ChartType + { + public string Id { get; set; } + public Chart ChartItem { get; set; } + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/Models/Day.cs b/CollectionViewChallenge/CollectionViewChallenge/Models/Day.cs new file mode 100644 index 0000000..cd68943 --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/Models/Day.cs @@ -0,0 +1,9 @@ +namespace CollectionViewChallenge.Models +{ + public class Day + { + public string Id { get; set; } + public string MonthName { get; set; } + public string DayName { get; set; } + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/Models/Person.cs b/CollectionViewChallenge/CollectionViewChallenge/Models/Person.cs new file mode 100644 index 0000000..7ddb940 --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/Models/Person.cs @@ -0,0 +1,11 @@ +namespace CollectionViewChallenge.Models +{ + public class Person + { + public string FirstName { get; set; } + + public string LastName { get; set; } + + public string Avatar { get; set; } + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/ViewModels/Base/BaseViewModel.cs b/CollectionViewChallenge/CollectionViewChallenge/ViewModels/Base/BaseViewModel.cs new file mode 100644 index 0000000..92d22b2 --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/ViewModels/Base/BaseViewModel.cs @@ -0,0 +1,55 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace CollectionViewChallenge.ViewModels.Base +{ + public abstract class BaseViewModel : INotifyPropertyChanged + { + //protected readonly INavigationService NavigationService; + + + public BaseViewModel() + { + // NavigationService = ViewModelLocator.Instance.Resolve(); + } + + string title; + public string Title + { + get => title; + set + { + if (title == value) + return; + title = value; + OnPropertyChanged(); + } + } + + bool isBusy; + public bool IsBusy + { + get => isBusy; + set + { + if (isBusy == value) + return; + isBusy = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsNotBusy)); + } + } + + public bool IsNotBusy => !IsBusy; + + #region INotifyPropertyChanged + + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged([CallerMemberName]string propertyName = "") => + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + + #endregion INotifyPropertyChanged + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/ViewModels/CollectionViewChallengeViewModel.cs b/CollectionViewChallenge/CollectionViewChallenge/ViewModels/CollectionViewChallengeViewModel.cs new file mode 100644 index 0000000..302e67d --- /dev/null +++ b/CollectionViewChallenge/CollectionViewChallenge/ViewModels/CollectionViewChallengeViewModel.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.ObjectModel; +using CollectionViewChallenge.Models; +using CollectionViewChallenge.ViewModels.Base; +using Microcharts; +using SkiaSharp; +using Entry = Microcharts.Entry; + +namespace CollectionViewChallenge.ViewModels +{ + public class CollectionViewChallengeViewModel : BaseViewModel + { + private ObservableCollection _items; + private Entry _selectedItem; + private Day _selectedDay; + + public ObservableCollection Items + { + get { return _items; } + set + { + _items = value; + OnPropertyChanged("Items"); + } + } + + public Entry SelectedItem + { + get { return _selectedItem; } + set + { + _selectedItem = value; + + // Creando un servicio de navegación + //NavigationService.NavigateToAsync(_selectedItem); + } + } + + private ObservableCollection _days; + + public ObservableCollection Days + { + get { return _days; } + set + { + _days = value; + OnPropertyChanged("Items"); + } + } + + public Day SelectedDay + { + get { return _selectedDay; } + set + { + _selectedDay = value; + + + // Creando un servicio de navegación + //NavigationService.NavigateToAsync(_selectedItem); + } + } + + private ObservableCollection _charts; + + public ObservableCollection Charts + { + get { return _charts; } + set + { + _charts = value; + OnPropertyChanged("Charts"); + } + } + + public ObservableCollection People { get; set; } + + public CollectionViewChallengeViewModel() + { + IsBusy = true; + + Items = new ObservableCollection + { + new Entry(200) {Label = "January", ValueLabel = "200", Color = SKColor.Parse("#266489") }, + new Entry(400) {Label = "February", ValueLabel = "400", Color = SKColor.Parse("#68B9C0") }, + new Entry(-100) {Label = "March", ValueLabel = "-100", Color = SKColor.Parse("#90D585") }, + new Entry(100) {Label = "April", ValueLabel = "100", Color = SKColor.Parse("#ba85d5") } + }; + + int daysInMonth = System.DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); + + Days = new ObservableCollection(); + + for (int i = 1; i <= daysInMonth; i++) + { + DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, i); + var myday = new Day() + { + Id = i.ToString(), + DayName = dt.ToString("ddd").ToUpper(), + MonthName = dt.ToString("MMM").ToUpper() + }; + + Days.Add(myday); + + if (myday.Id == DateTime.Now.Day.ToString()) + { + SelectedDay = myday; + } + } + + Charts = new ObservableCollection + { + new ChartType() {Id="1" , ChartItem = LineChartType }, + new ChartType() {Id="2" , ChartItem = BarChartType}, + new ChartType() {Id="3" , ChartItem = RadarChartType }, + new ChartType() {Id="4" , ChartItem = PointChartType}, + new ChartType() {Id="5" , ChartItem = RadialGaugeType }, + new ChartType() {Id="6" , ChartItem = DonutType}, + }; + + People = new ObservableCollection + { + new Person(){Avatar = "https://randomuser.me/api/portraits/men/54.jpg", FirstName = "Jon", LastName="Coleman" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/men/50.jpg", FirstName = "Vernon", LastName="Walters" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/women/54.jpg", FirstName = "Beverley", LastName="Sutton" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/women/69.jpg", FirstName = "Scarlet", LastName="Kingsley" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/men/36.jpg", FirstName = "Everett", LastName="Riley" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/men/57.jpg", FirstName = "Lenny", LastName="Rodrigues" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/women/29.jpg", FirstName = "Addlynne", LastName="Fowler" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/women/44.jpg", FirstName = "Nicole", LastName="Jennings" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/men/11.jpg", FirstName = "Ole", LastName="Solksjaer" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/women/90.jpg", FirstName = "Avery", LastName="Burke" }, + new Person(){Avatar = "https://randomuser.me/api/portraits/men/6.jpg", FirstName = "Lionel", LastName="Murphy" } + }; + + IsBusy = false; + } + + public Chart LineChartType => new LineChart() + { + Entries = Items, + LabelTextSize = 10 + }; + + public Chart BarChartType => new BarChart() + { + Entries = Items, + LabelTextSize = 20 + }; + + public Chart RadarChartType => new RadarChart() + { + Entries = Items, + LabelTextSize = 20, + Margin = 20 + }; + + public Chart PointChartType => new PointChart() + { + Entries = Items, + LabelTextSize = 20, + Margin = 20 + }; + + public Chart RadialGaugeType => new RadialGaugeChart() + { + Entries = Items, + LabelTextSize = 20, + Margin = 20 + }; + + public Chart DonutType => new DonutChart() + { + Entries = Items, + LabelTextSize = 20, + Margin = 20 + }; + } +} diff --git a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml index f2da7f7..134da95 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml +++ b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml @@ -3,30 +3,195 @@ 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" + xmlns:imagecircle="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin" + xmlns:microchars="clr-namespace:Microcharts.Forms;assembly=Microcharts.Forms" mc:Ignorable="d" - x:Class="CollectionViewChallenge.Views.CollectionViewChallengePage"> + x:Class="CollectionViewChallenge.Views.CollectionViewChallengePage" + BackgroundColor="#1B213B" + Shell.NavBarIsVisible="False"> + - - - - - - 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..f88753d 100644 --- a/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs +++ b/CollectionViewChallenge/CollectionViewChallenge/Views/CollectionViewChallengePage.xaml.cs @@ -6,6 +6,7 @@ using Xamarin.Forms; using Xamarin.Forms.Xaml; +using CollectionViewChallenge.ViewModels; namespace CollectionViewChallenge.Views { @@ -15,6 +16,13 @@ public partial class CollectionViewChallengePage : ContentPage public CollectionViewChallengePage() { InitializeComponent(); + BindingContext = new CollectionViewChallengeViewModel(); + } + + protected override void OnAppearing() + { + base.OnAppearing(); + DaysCollectionView.ScrollTo(DateTime.Now.Day, position: ScrollToPosition.MakeVisible); } } } \ No newline at end of file