Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionViewChallenge - Dashboard demo #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microcharts.Forms">
<Version>0.7.1</Version>
</PackageReference>
<PackageReference Include="Xam.Plugins.Forms.ImageCircle">
<Version>3.0.0.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="Xamarin.Android.Support.ViewPager" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microcharts.Forms">
<Version>0.7.1</Version>
</PackageReference>
<PackageReference Include="Xam.Plugins.Forms.ImageCircle">
<Version>3.0.0.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microcharts" Version="0.7.1" />
<PackageReference Include="Microcharts.Forms" Version="0.7.1" />
<PackageReference Include="Xam.Plugins.Forms.ImageCircle" Version="3.0.0.5" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
</ItemGroup>
Expand All @@ -20,9 +23,4 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Folder Include="Models\" />
<Folder Include="ViewModels\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microcharts;

namespace CollectionViewChallenge.Models
{
public class ChartType
{
public string Id { get; set; }
public Chart ChartItem { get; set; }
}
}
9 changes: 9 additions & 0 deletions CollectionViewChallenge/CollectionViewChallenge/Models/Day.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
11 changes: 11 additions & 0 deletions CollectionViewChallenge/CollectionViewChallenge/Models/Person.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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<INavigationService>();
}

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
}
}
Original file line number Diff line number Diff line change
@@ -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<Entry> _items;
private Entry _selectedItem;
private Day _selectedDay;

public ObservableCollection<Entry> 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<XamagramItemDetailViewModel>(_selectedItem);
}
}

private ObservableCollection<Day> _days;

public ObservableCollection<Day> 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<XamagramItemDetailViewModel>(_selectedItem);
}
}

private ObservableCollection<ChartType> _charts;

public ObservableCollection<ChartType> Charts
{
get { return _charts; }
set
{
_charts = value;
OnPropertyChanged("Charts");
}
}

public ObservableCollection<Person> People { get; set; }

public CollectionViewChallengeViewModel()
{
IsBusy = true;

Items = new ObservableCollection<Entry>
{
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<Day>();

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<ChartType>
{
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<Person>
{
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
};
}
}
Loading