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

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

@ -2,7 +2,7 @@
using Model; using Model;
using StubLib; using StubLib;
using View.Page; using View.Page;
using ViewModel; using ViewModels;
using CommunityToolkit.Maui; using CommunityToolkit.Maui;
using View.ModelViewPage; using View.ModelViewPage;
namespace View; namespace View;
@ -24,6 +24,7 @@ public static class MauiProgram
builder.Services.AddSingleton<IDataManager, StubData>().AddSingleton<ChampionManagerVM>(); builder.Services.AddSingleton<IDataManager, StubData>().AddSingleton<ChampionManagerVM>();
builder.Services.AddTransient<ChampionsView>(); builder.Services.AddTransient<ChampionsView>();
builder.Services.AddTransient<ChampionsViewM>(); builder.Services.AddTransient<ChampionsViewM>();
builder.Services.AddTransient<ChampionDetailViewM>();
#if DEBUG #if DEBUG
builder.Logging.AddDebug(); builder.Logging.AddDebug();

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

@ -1,24 +1,29 @@
using System; using System;
using ViewModel; using ViewModels;
using View.Page; using View.Page;
using Model; using Model;
using System.Windows.Input; using System.Windows.Input;
using static StubLib.StubData; using static StubLib.StubData;
using System.Collections.ObjectModel;
namespace View.ModelViewPage namespace View.ModelViewPage
{ {
public class ChampionsViewM public class ChampionsViewM
{ {
public ICommand NextPageCommand { get; private set; } public Command NextPageCommand { get; private set; }
public Command PreviousPageCommand { get; } public Command PreviousPageCommand { get; }
public Command EditChampionCommand { get; } public Command EditChampionCommand { get; }
public ChampionManagerVM championManagerVm { get; } public ChampionManagerVM championManagerVm { get; }
public Command DeleteChampionCommand { get; private set; }
public ChampionsViewM(ChampionManagerVM championManager) public ChampionsViewM(ChampionManagerVM championManager)
{ {
championManagerVm = championManager; championManagerVm = championManager;
PushToDetailCommand = new Command<ChampionVm>(PushToDetail); 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); PreviousPageCommand = new Command(PreviousPage, CanExecutePrevious);
AddChampionCommand = new Command(Addchampion); AddChampionCommand = new Command(Addchampion);
@ -38,11 +43,16 @@ namespace View.ModelViewPage
{ {
return championManagerVm.Index > 1; return championManagerVm.Index > 1;
} }
private bool CanExecuteNext()
{
var val = (this.championManagerVm.Index) < this.championManagerVm.PageTotale;
return val;
}
void RefreshCanExecute() void RefreshCanExecute()
{ {
PreviousPageCommand.ChangeCanExecute(); PreviousPageCommand.ChangeCanExecute();
NextPageCommand.ChangeCanExecute();
} }
public Command PushToDetailCommand { get; } public Command PushToDetailCommand { get; }

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

@ -17,13 +17,13 @@
<StackLayout Orientation="Horizontal" Spacing="10"> <StackLayout Orientation="Horizontal" Spacing="10">
<Label Text="Icône:" FontSize="Subtitle" VerticalOptions="Center" /> <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>
<StackLayout Orientation="Horizontal" Spacing="1"> <StackLayout Orientation="Horizontal" Spacing="1">
<Label Text="Image:" FontSize="Subtitle" VerticalOptions="Center" /> <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> </StackLayout>
@ -32,12 +32,34 @@
<Entry Text="{Binding EditableChampion.Bio}" Placeholder="Nom du Champion" HorizontalOptions="FillAndExpand" HeightRequest="200" WidthRequest="200" /> <Entry Text="{Binding EditableChampion.Bio}" Placeholder="Nom du Champion" HorizontalOptions="FillAndExpand" HeightRequest="200" WidthRequest="200" />
</StackLayout> </StackLayout>
<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" > <StackLayout Orientation="Horizontal" HorizontalOptions="Center" >
<Button Text="Ajouter" Command="{Binding SaveChampionCommand}" HorizontalOptions="Center" Padding="10" Margin="10" BackgroundColor="#DAA520"/> <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" /> <Button Text="Annuler" HorizontalOptions="Center" Padding="10" Margin="10" BackgroundColor="#DAA520" />
</StackLayout> </StackLayout>
</StackLayout> </StackLayout>
</StackLayout>
</ContentPage> </ContentPage>

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

@ -1,6 +1,5 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 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:vm="clr-namespace:View.ModelViewPage"
xmlns:page="clr-namespace:View.Page" xmlns:page="clr-namespace:View.Page"
@ -26,15 +25,31 @@
<DataTemplate> <DataTemplate>
<ViewCell> <ViewCell>
<ViewCell.View> <ViewCell.View>
<VerticalStackLayout>
<SwipeView > <SwipeView >
<SwipeView.RightItems> <SwipeView.RightItems>
<SwipeItems>
<SwipeItem <SwipeItem
Text="Modifier" Text="Modifier"
BackgroundColor="Gray" 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> </SwipeView.RightItems>
<Grid ColumnDefinitions="50,*,20" ColumnSpacing="10"> <Grid ColumnDefinitions="50,*,20" ColumnSpacing="10">
<Grid.GestureRecognizers> <Grid.GestureRecognizers>
@ -47,6 +62,7 @@
</StackLayout> </StackLayout>
</Grid> </Grid>
</SwipeView> </SwipeView>
</VerticalStackLayout>
</ViewCell.View> </ViewCell.View>
</ViewCell> </ViewCell>
</DataTemplate> </DataTemplate>
@ -66,8 +82,10 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<HorizontalStackLayout > <HorizontalStackLayout >
<Button Text="L" HeightRequest="12 " Command="{Binding PreviousPageCommand}"/> <Button Text="L" HeightRequest="12 " WidthRequest="12" Padding="15" Command="{Binding PreviousPageCommand}"/>
<Button Text="R" HeightRequest="12 "
<Button Text="R" HeightRequest="12 " Padding="10" WidthRequest="12"
Command="{Binding NextPageCommand}" /> Command="{Binding NextPageCommand}" />

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

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

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

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

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

@ -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