Toolkit
Najlae LAMBARAA 2 years ago
parent 9613c9d6ec
commit 5bf7da5d3e

@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "View", "View\View.csproj", "{E247FCE5-AD0E-4E6B-BD8C-D01E99BE059C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ViewModel", "ViewModel\ViewModel.csproj", "{C118DE32-F945-4ED9-8E2E-B6A9EA7B9B17}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ViewModels", "ViewModels\ViewModels.csproj", "{571BD072-7A40-4900-BCD3-30A81DFCE449}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -45,10 +45,10 @@ Global
{E247FCE5-AD0E-4E6B-BD8C-D01E99BE059C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E247FCE5-AD0E-4E6B-BD8C-D01E99BE059C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E247FCE5-AD0E-4E6B-BD8C-D01E99BE059C}.Release|Any CPU.Build.0 = Release|Any CPU
{C118DE32-F945-4ED9-8E2E-B6A9EA7B9B17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C118DE32-F945-4ED9-8E2E-B6A9EA7B9B17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C118DE32-F945-4ED9-8E2E-B6A9EA7B9B17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C118DE32-F945-4ED9-8E2E-B6A9EA7B9B17}.Release|Any CPU.Build.0 = Release|Any CPU
{571BD072-7A40-4900-BCD3-30A81DFCE449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{571BD072-7A40-4900-BCD3-30A81DFCE449}.Debug|Any CPU.Build.0 = Debug|Any CPU
{571BD072-7A40-4900-BCD3-30A81DFCE449}.Release|Any CPU.ActiveCfg = Release|Any CPU
{571BD072-7A40-4900-BCD3-30A81DFCE449}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -2,7 +2,7 @@
using Model;
using StubLib;
using View.Page;
using ViewModel;
using ViewModels;
using CommunityToolkit.Maui;
using View.ModelViewPage;
namespace View;
@ -20,10 +20,11 @@ public static class MauiProgram
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton<IDataManager, StubData>().AddSingleton<ChampionManagerVM>();
builder.Services.AddTransient<ChampionsView>();
builder.Services.AddTransient<ChampionsViewM>();
builder.Services.AddTransient<ChampionDetailViewM>();
#if DEBUG
builder.Logging.AddDebug();

@ -1,6 +1,6 @@
using System;
using View.Page;
using ViewModel;
using ViewModels;
namespace View.ModelViewPage
{

@ -1,24 +1,29 @@
using System;
using ViewModel;
using ViewModels;
using View.Page;
using Model;
using System.Windows.Input;
using static StubLib.StubData;
using System.Collections.ObjectModel;
namespace View.ModelViewPage
{
public class ChampionsViewM
{
public ICommand NextPageCommand { get; private set; }
public Command NextPageCommand { get; private set; }
public Command PreviousPageCommand { get; }
public Command EditChampionCommand { get; }
public ChampionManagerVM championManagerVm { get; }
public Command DeleteChampionCommand { get; private set; }
public ChampionsViewM(ChampionManagerVM championManager)
{
championManagerVm = championManager;
PushToDetailCommand = new Command<ChampionVm>(PushToDetail);
NextPageCommand = new Command(NextPage);
DeleteChampionCommand = new Command<ChampionVm>(async (ChampionVm obj) => await championManagerVm.DeleteChampion(obj));
NextPageCommand = new Command(NextPage, CanExecuteNext);
PreviousPageCommand = new Command(PreviousPage, CanExecutePrevious);
AddChampionCommand = new Command(Addchampion);
@ -38,11 +43,16 @@ namespace View.ModelViewPage
{
return championManagerVm.Index > 1;
}
private bool CanExecuteNext()
{
var val = (this.championManagerVm.Index) < this.championManagerVm.PageTotale;
return val;
}
void RefreshCanExecute()
{
PreviousPageCommand.ChangeCanExecute();
NextPageCommand.ChangeCanExecute();
}
public Command PushToDetailCommand { get; }
@ -57,7 +67,7 @@ namespace View.ModelViewPage
{
Shell.Current.Navigation.PushAsync(page: new AddChampionPage(new EditChampionViewM(championManagerVm, new EditChampionVm(null), null)));
}
}
}

@ -1,5 +1,7 @@
using System;
using ViewModel;
using System.Collections.ObjectModel;
using Model;
using ViewModels;
namespace View.ModelViewPage
{
@ -24,15 +26,21 @@ namespace View.ModelViewPage
private ChampionManagerVM Manager;
public EditChampionVm EditableChampion { get; }
private ChampionVm ChampionVM;
public Command SaveChampionCommand { get; }
private async void SaveChampion()
{
Manager.SaveChampion(EditableChampion, ChampionVM);
await Shell.Current.Navigation.PopAsync();
}
public ReadOnlyDictionary<string, int> Characteristics
{
get => Characteristics;
}
private async Task PickIcon()

@ -17,13 +17,13 @@
<StackLayout Orientation="Horizontal" Spacing="10">
<Label Text="Icône:" FontSize="Subtitle" VerticalOptions="Center" />
<ImageButton Source="{Binding EditableChampion.Icon,Converter={StaticResource Base64ToImageConverter}}" Command="{Binding PickIconCommand}" />
<ImageButton Source="{Binding EditableChampion.Icon,Converter={StaticResource Base64ToImageConverter}}" Command="{Binding PickIconCommand}" BackgroundColor="#D3D3D3" />
</StackLayout>
<StackLayout Orientation="Horizontal" Spacing="1">
<Label Text="Image:" FontSize="Subtitle" VerticalOptions="Center" />
<ImageButton Source="{Binding EditableChampion.Image,Converter={StaticResource Base64ToImageConverter}}" Command="{Binding PickImageCommand }" />
<ImageButton Source="{Binding EditableChampion.Image,Converter={StaticResource Base64ToImageConverter}}" Command="{Binding PickImageCommand }" BackgroundColor="#D3D3D3" />
</StackLayout>
@ -32,11 +32,33 @@
<Entry Text="{Binding EditableChampion.Bio}" Placeholder="Nom du Champion" HorizontalOptions="FillAndExpand" HeightRequest="200" WidthRequest="200" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" >
<StackLayout Orientation="Horizontal" Margin="16" Spacing="10">
<Label Text="Classe:" FontSize="Subtitle" />
<ListView ItemsSource="{Binding EditableChampion.ListClasses}" SelectedItem="{Binding EditableChampion.Class}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="10">
<Label Text="{Binding .}"
VerticalTextAlignment="Center"
HorizontalOptions="StartAndExpand"
FontAttributes="Bold" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" >
<Button Text="Ajouter" Command="{Binding SaveChampionCommand}" HorizontalOptions="Center" Padding="10" Margin="10" BackgroundColor="#DAA520"/>
<Button Text="Annuler" HorizontalOptions="Center" Padding="10" Margin="10" BackgroundColor="#DAA520" />
</StackLayout>
</StackLayout>
</StackLayout>
</ContentPage>

@ -1,4 +1,4 @@
using ViewModel;
using ViewModels;
using View.ModelViewPage;
namespace View.Page;

@ -1,7 +1,6 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewM="clr-namespace:ViewModel;assembly=ViewModel"
xmlns:convert="clr-namespace:View.ConvertiseurImage"
xmlns:convert="clr-namespace:View.ConvertiseurImage"
xmlns:vm="clr-namespace:View.ModelViewPage"
xmlns:page="clr-namespace:View.Page"
x:Class="View.Page.ChampionsView"
@ -26,15 +25,31 @@
<DataTemplate>
<ViewCell>
<ViewCell.View>
<VerticalStackLayout>
<SwipeView >
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem
Text="Modifier"
BackgroundColor="Gray"
Command="{Binding EditChampionCommand}"
Command= "{Binding Source={RelativeSource AncestorType={x:Type vm:ChampionsViewM}}, Path=EditChampionCommand} "
CommandParameter="{Binding .}"
/>
<SwipeItem Text="Supprimer" BackgroundColor="Red"/>
<SwipeItem Text="Supprimer"
BackgroundColor="Red"
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ChampionsViewM}}, Path=DeleteChampionCommand} "
CommandParameter="{Binding .}" />
</SwipeItems>
</SwipeView.RightItems>
<Grid ColumnDefinitions="50,*,20" ColumnSpacing="10">
<Grid.GestureRecognizers>
@ -47,6 +62,7 @@
</StackLayout>
</Grid>
</SwipeView>
</VerticalStackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
@ -66,8 +82,10 @@
</Grid.RowDefinitions>
<HorizontalStackLayout >
<Button Text="L" HeightRequest="12 " Command="{Binding PreviousPageCommand}"/>
<Button Text="R" HeightRequest="12 "
<Button Text="L" HeightRequest="12 " WidthRequest="12" Padding="15" Command="{Binding PreviousPageCommand}"/>
<Button Text="R" HeightRequest="12 " Padding="10" WidthRequest="12"
Command="{Binding NextPageCommand}" />

@ -1,12 +1,14 @@
namespace View.Page;
using ModelViewPage;
using ViewModel;
using ViewModels;
public partial class ChampionsView : ContentPage
{
public ChampionsView(ChampionsViewM vm)
public ChampionsViewM ChampionsViewModel { get; }
public ChampionsView(ChampionsViewM vm)
{
InitializeComponent();
BindingContext = vm;
ChampionsViewModel = vm;
}
}

@ -1,5 +1,5 @@
using View.ModelViewPage;
using ViewModel;
using ViewModels;
namespace View.Page;
public partial class DetailChampion : ContentPage

@ -72,14 +72,14 @@
<Folder Include="ConvertiseurImage\" />
<Folder Include="ModelViewPage\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
<ProjectReference Include="..\ViewModel\ViewModel.csproj" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\Images\league.png" />
<BundleResource Include="Resources\Images\mage.png" />
<BundleResource Include="Resources\Images\mageicon.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ViewModels\ViewModels.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -13,6 +13,7 @@ namespace ViewModel
public ObservableCollection<ChampionVm> Champions { get; }
public event PropertyChangedEventHandler? PropertyChanged;
public ICommand NextPageCommand { get; private set; }
public ICommand DeleteChampionCommand { get; }
public IDataManager DataManager
{
@ -24,21 +25,24 @@ namespace ViewModel
OnPropertyChanged();
}
}
private IDataManager _dataManager;
private IDataManager _dataManager { get; set; }
public ChampionManagerVM(IDataManager dataManager)
{
DataManager = dataManager;
Champions = new ObservableCollection<ChampionVm>();
DeleteChampionCommand = new Command<ChampionVm>(async (ChampionVm obj) => await DeleteChampion(obj));
LoadChampions(index, Count).ConfigureAwait(false);
PropertyChanged += ChampionManagerVM_PropertyChanged;
PropertyChanged += ChampionMgrm_PropertyChanged;
PropertyChanged += ChampionManager_PropertyChanged;
Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
}
private async void ChampionManagerVM_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Index))
{
Champions.Clear();
await LoadChampions(index, Count);
}
}
@ -60,9 +64,27 @@ namespace ViewModel
get;
set;
} = 5;
public int PageTotale { get { return this.total / Count + ((this.total % Count) > 0 ? 1 : 0); } }
private int total;
public int Total
{
get => total;
private set
{
total = value;
OnPropertyChanged();
}
}
public int nombrepage(int GetNbItems, int count)
{
int result = GetNbItems / count;
if (result < 0) return result + 1;
else
return result;
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
@ -70,6 +92,7 @@ namespace ViewModel
private async Task LoadChampions(int index, int count)
{
Champions.Clear();
var modelChampions = await DataManager.ChampionsMgr.GetItems(Index - 1, Count);
@ -102,18 +125,38 @@ namespace ViewModel
var champ = await DataManager.ChampionsMgr.AddItem(editableChampionVM.Model.Model);
if (champ is null)
{
var result = "null";
var result = "nll";
}
updatePagination();
}
}
private async void ChampionMgrm_PropertyChanged(object? sender, PropertyChangedEventArgs e)
public async Task DeleteChampion(ChampionVm champion)
{
if (e.PropertyName == nameof(Index))
if (champion is null) return;
if (!Champions.Contains(champion)) return;
await DataManager.ChampionsMgr.DeleteItem(champion.Model);
updatePagination();
}
private async void updatePagination()
{
await LoadChampions(this.Index, Count);
if (Champions.Count == 0)
{
Champions.Clear();
await LoadChampions(Index, Count);
this.Index = this.Index - 1;
await LoadChampions(this.Index, Count);
}
this.Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
OnPropertyChanged(nameof(this.Champions));
OnPropertyChanged(nameof(PageTotale));
}

@ -0,0 +1,92 @@
using System;
using Model;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace ViewModel
{
public class DataManagerVM : INotifyPropertyChanged
{
private ObservableCollection<ChampionVm> ChampionsObs { get; set; } = new ObservableCollection<ChampionVm>();
public ReadOnlyObservableCollection<ChampionVm> ChampionVMs { get; private set; }
public int PageId
{
get => _pageId;
set
{
if (_pageId != value)
{
_pageId = value;
OnPropertyChanged();
(PreviousPageCommand as Command).ChangeCanExecute();
(NextPageCommand as Command).ChangeCanExecute();
LoadData();
}
}
}
public int _pageId = 1;
public int PageSize { get; set; } = 5;
public int NbItem
{
get => _nbItem;
set
{
if (_nbItem != value)
{
_nbItem = value;
OnPropertyChanged();
}
}
}
public int _nbItem;
public IDataManager DataManager
{
get => _dataManager;
set
{
if (_dataManager == value) return;
_dataManager = value;
OnPropertyChanged();
LoadData();
}
}
private IDataManager _dataManager;
public ICommand NextPageCommand { get; private set; }
public ICommand PreviousPageCommand { get; private set; }
public DataManagerVM(IDataManager dataManager)
{
DataManager = dataManager;
ChampionVMs = new ReadOnlyObservableCollection<ChampionVm>(ChampionsObs);
NextPageCommand = new Command(
execute: () => { PageId++; },
canExecute: () => { return NbItem - (PageSize * (PageId - 1)) > PageSize; }
);
PreviousPageCommand = new Command(
execute: () => { PageId--; },
canExecute: () => { return PageId > 1; }
);
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public event PropertyChangedEventHandler PropertyChanged;
public async void LoadData()
{
ChampionsObs.Clear();
NbItem = await DataManager.ChampionsMgr.GetNbItems();
IEnumerable<Champion> champions = await DataManager.ChampionsMgr.GetItems(PageId - 1, PageSize);
foreach (var item in champions)
{
ChampionsObs.Add(new ChampionVm(item));
}
}
}
}

@ -3,11 +3,12 @@ using Model;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using static System.Net.Mime.MediaTypeNames;
using System.Collections.ObjectModel;
namespace ViewModel
{
public class EditChampionVm
{
public class EditChampionVm : INotifyPropertyChanged
{
public ChampionVm Model { get; set; }
public EditChampionVm(ChampionVm vm)
{
@ -17,11 +18,13 @@ namespace ViewModel
icon = IsNew ? string.Empty : Model.Icon;
_name = IsNew ? string.Empty : Model.Name;
image = IsNew ? string.Empty : Model.Image.Base64;
_classe = IsNew ? ChampionClass.Unknown : Model.Class;
ListClasses = Enum.GetValues<ChampionClass>().Where(c => c != ChampionClass.Unknown).ToArray();
}
public bool IsNew { get; private set; }
public IEnumerable<ChampionClass> ListClasses { get; }
private string _name;
public string Name
@ -72,12 +75,37 @@ namespace ViewModel
}
}
private ChampionClass _classe;
public ChampionClass Class
{
get => _classe;
set
{
if (_classe == null) return;
_classe = value;
OnPropertyChanged();
}
}
private int index;
public int Index
{
get => index;
set
{
if (index == value) return;
index = value;
OnPropertyChanged();
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public ReadOnlyDictionary<string, int> Characteristics
{
get => Model.Characteristics;
}
public event PropertyChangedEventHandler PropertyChanged;
public void SaveChampion()
@ -86,17 +114,17 @@ namespace ViewModel
{
Model.Bio = Bio;
Model.Icon = Icon;
}
Model.Class = Class;
Model.Image.Base64 = Image;
else
{
//Model.Model = new Champion(Name,ChampionClass.Unknown,Icon,"",Bio);
Model = new ChampionVm(new Champion(Name, ChampionClass.Unknown, Icon, "", Bio));
var data = "";
//foreach (KeyValuePair<string,int> c in Characteristique)
//{
// Model.Model.AddCharacteristics(new Tuple<string, int>(c.Key, c.Value));
//}
{
Model = new ChampionVm(new Champion(Name, ChampionClass.Unknown, Icon, "", Bio));
var data = "";
}
}
}
}

@ -0,0 +1,51 @@
using System;
using Model;
using System.ComponentModel;
namespace ViewModel
{
public class SkillVm : INotifyPropertyChanged
{
public SkillType Type { get => Model.Type; }
public Skill Model
{
get => _model;
set
{
if (value != _model)
{
_model = value;
}
}
}
private Skill _model;
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get => Model.Name;
}
public string Description
{
get => Model.Description;
set
{
if (value != Model.Description)
{
Model.Description = value;
}
}
}
public SkillVm(Skill model)
{
this.Model = model;
}
}
}

@ -0,0 +1,7 @@
namespace ViewModels;
// All the code in this file is included in all platforms.
public class Class1
{
}

@ -0,0 +1,7 @@
namespace ViewModels;
// All the code in this file is only included on Android.
public class PlatformClass1
{
}

@ -0,0 +1,7 @@
namespace ViewModels;
// All the code in this file is only included on Mac Catalyst.
public class PlatformClass1
{
}

@ -0,0 +1,9 @@
using System;
namespace ViewModels
{
// All the code in this file is only included on Tizen.
public class PlatformClass1
{
}
}

@ -0,0 +1,7 @@
namespace ViewModels;
// All the code in this file is only included on Windows.
public class PlatformClass1
{
}

@ -0,0 +1,7 @@
namespace ViewModels;
// All the code in this file is only included on iOS.
public class PlatformClass1
{
}

@ -0,0 +1,166 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Model;
namespace ViewModels
{
public class ChampionManagerVM : INotifyPropertyChanged
{
public ObservableCollection<ChampionVm> Champions { get; }
public event PropertyChangedEventHandler? PropertyChanged;
public ICommand NextPageCommand { get; private set; }
public ICommand DeleteChampionCommand { get; }
public IDataManager DataManager
{
get => _dataManager;
set
{
if (_dataManager == value) return;
_dataManager = value;
OnPropertyChanged();
}
}
private IDataManager _dataManager { get; set; }
public ChampionManagerVM(IDataManager dataManager)
{
DataManager = dataManager;
Champions = new ObservableCollection<ChampionVm>();
LoadChampions(index, Count).ConfigureAwait(false);
PropertyChanged += ChampionManagerVM_PropertyChanged;
PropertyChanged += ChampionManager_PropertyChanged;
Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
}
private async void ChampionManagerVM_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Index))
{
Champions.Clear();
await LoadChampions(index, Count);
}
}
public int Index
{
get => index;
set
{
if (index == value) return;
index = value;
OnPropertyChanged();
}
}
private int index;
public int Count
{
get;
set;
} = 5;
public int PageTotale { get { return this.total / Count + ((this.total % Count) > 0 ? 1 : 0); } }
private int total;
public int Total
{
get => total;
private set
{
total = value;
OnPropertyChanged();
}
}
public int nombrepage(int GetNbItems, int count)
{
int result = GetNbItems / count;
if (result < 0) return result + 1;
else
return result;
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private async Task LoadChampions(int index, int count)
{
Champions.Clear();
var modelChampions = await DataManager.ChampionsMgr.GetItems(Index - 1, Count);
foreach (var champion in modelChampions)
{
Champions.Add(new ChampionVm(champion));
}
}
private async void ChampionManager_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Index))
{
Champions.Clear();
await LoadChampions(Index, Count);
}
}
public async void SaveChampion(EditChampionVm editableChampionVM, ChampionVm? championVM)
{
if (editableChampionVM is null) return;
if (!editableChampionVM.IsNew)
{
editableChampionVM.SaveChampion();
var champ = await DataManager.ChampionsMgr.UpdateItem(championVM.Model, editableChampionVM.Model.Model);
}
else
{
editableChampionVM.SaveChampion();
var champ = await DataManager.ChampionsMgr.AddItem(editableChampionVM.Model.Model);
if (champ is null)
{
var result = "nll";
}
updatePagination();
}
}
private async void updatePagination()
{
await LoadChampions(this.Index, Count);
if (Champions.Count == 0)
{
this.Index = this.Index - 1;
await LoadChampions(this.Index, Count);
}
this.Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
OnPropertyChanged(nameof(this.Champions));
OnPropertyChanged(nameof(PageTotale));
}
public async Task DeleteChampion(ChampionVm champion)
{
if (champion is null) return;
if (!Champions.Contains(champion)) return;
await DataManager.ChampionsMgr.DeleteItem(champion.Model);
updatePagination();
}
}
}

@ -0,0 +1,95 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Model;
namespace ViewModels
{
public class ChampionVm : INotifyPropertyChanged
{
public ChampionVm(Champion champion) => Model = champion;
private Champion model;
public ReadOnlyDictionary<string, int> Characteristics
{
get => Model.Characteristics;
}
public Champion Model
{
get => model;
set
{
if (value.Equals(model)) return;
if (value == null) return;
model = value;
OnPropertyChanged();
}
}
public string Name
{
get => Model.Name;
}
public string Icon
{
get => Model.Icon;
set
{
if (model == null) return;
Model.Icon = value;
OnPropertyChanged();
}
}
public LargeImage Image
{
get => Model.Image;
set
{
if (model == null) return;
Model.Image = value;
OnPropertyChanged();
}
}
public ChampionClass Class
{
get => Model.Class;
set
{
if (model == null) return;
Model.Class = value;
OnPropertyChanged();
}
}
public string Bio
{
get => Model.Bio;
set
{
if (model == null) return;
Model.Bio = value;
OnPropertyChanged();
}
}
private ObservableCollection<Skill> skills;
public HashSet<Skill> Skills
{
get => Model.Skills.ToHashSet();
set
{
if (value.Equals(skills)) return;
skills = new ObservableCollection<Skill>(Skills);
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -0,0 +1,91 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Model;
namespace ViewModels
{
public class DataManagerVM : INotifyPropertyChanged
{
private ObservableCollection<ChampionVm> ChampionsObs { get; set; } = new ObservableCollection<ChampionVm>();
public ReadOnlyObservableCollection<ChampionVm> ChampionVMs { get; private set; }
public int PageId
{
get => _pageId;
set
{
if (_pageId != value)
{
_pageId = value;
OnPropertyChanged();
(PreviousPageCommand as Command).ChangeCanExecute();
(NextPageCommand as Command).ChangeCanExecute();
LoadData();
}
}
}
public int _pageId = 1;
public int PageSize { get; set; } = 5;
public int NbItem
{
get => _nbItem;
set
{
if (_nbItem != value)
{
_nbItem = value;
OnPropertyChanged();
}
}
}
public int _nbItem;
public IDataManager DataManager
{
get => _dataManager;
set
{
if (_dataManager == value) return;
_dataManager = value;
OnPropertyChanged();
LoadData();
}
}
private IDataManager _dataManager;
public ICommand NextPageCommand { get; private set; }
public ICommand PreviousPageCommand { get; private set; }
public DataManagerVM(IDataManager dataManager)
{
DataManager = dataManager;
ChampionVMs = new ReadOnlyObservableCollection<ChampionVm>(ChampionsObs);
NextPageCommand = new Command(
execute: () => { PageId++; },
canExecute: () => { return NbItem - (PageSize * (PageId - 1)) > PageSize; }
);
PreviousPageCommand = new Command(
execute: () => { PageId--; },
canExecute: () => { return PageId > 1; }
);
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public event PropertyChangedEventHandler PropertyChanged;
public async void LoadData()
{
ChampionsObs.Clear();
NbItem = await DataManager.ChampionsMgr.GetNbItems();
IEnumerable<Champion> champions = await DataManager.ChampionsMgr.GetItems(PageId - 1, PageSize);
foreach (var item in champions)
{
ChampionsObs.Add(new ChampionVm(item));
}
}
}
}

@ -0,0 +1,130 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Model;
namespace ViewModels
{
public class EditChampionVm : INotifyPropertyChanged
{
public ChampionVm Model { get; set; }
public EditChampionVm(ChampionVm vm)
{
IsNew = vm is null;
Model = IsNew ? null : vm;
_bio = IsNew ? string.Empty : Model.Bio;
icon = IsNew ? string.Empty : Model.Icon;
_name = IsNew ? string.Empty : Model.Name;
image = IsNew ? string.Empty : Model.Image.Base64;
_classe = IsNew ? ChampionClass.Unknown : Model.Class;
ListClasses = Enum.GetValues<ChampionClass>().Where(c => c != ChampionClass.Unknown).ToArray();
}
public bool IsNew { get; private set; }
public IEnumerable<ChampionClass> ListClasses { get; }
private string _name;
public string Name
{
get => _name;
set
{
if (_name == value) return;
_name = value;
OnPropertyChanged();
}
}
private string icon;
public string Icon
{
get => icon;
set
{
if (icon == value) return;
icon = value;
OnPropertyChanged();
}
}
private string _bio;
public string Bio
{
get => _bio;
set
{
if (_bio == value) return;
_bio = value;
OnPropertyChanged();
}
}
private string image;
public string Image
{
get => image;
set
{
if (image == value) return;
image = value;
OnPropertyChanged();
}
}
private ChampionClass _classe;
public ChampionClass Class
{
get => _classe;
set
{
if (_classe == null) return;
_classe = value;
OnPropertyChanged();
}
}
private int index;
public int Index
{
get => index;
set
{
if (index == value) return;
index = value;
OnPropertyChanged();
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public ReadOnlyDictionary<string, int> Characteristics
{
get => Model.Characteristics;
}
public event PropertyChangedEventHandler PropertyChanged;
public void SaveChampion()
{
if (!IsNew)
{
Model.Bio = Bio;
Model.Icon = Icon;
Model.Image.Base64 = Image;
Model.Class = Class;
}
else
{
Model = new ChampionVm(new Champion(Name, ChampionClass.Unknown, Icon, "", Bio));
var data = "";
}
}
}
}

@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<None Remove="ViewM\" />
</ItemGroup>
<ItemGroup>
<Folder Include="ViewM\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>
Loading…
Cancel
Save