Compare commits

..

1 Commits

Author SHA1 Message Date
Najlae LAMBARAA 365fc74cb7 Add Toolkit
2 years ago

@ -1,21 +1,21 @@
using System;
using CommunityToolkit.Mvvm.Input;
using View.Page;
using ViewModels;
namespace View.ModelViewPage
{
public class ChampionDetailViewM
public partial class ChampionDetailViewM
{
public ChampionDetailViewM(ChampionManagerVM manager, ChampionVm championVm)
{
ChampionVM = championVm;
EditChampionCommand = new Command(EditChampion);
Manager = manager;
}
public ChampionVm ChampionVM { get; }
private ChampionManagerVM Manager;
public Command EditChampionCommand { get; }
[RelayCommand]
private async void EditChampion()
{
await Shell.Current.Navigation.PushAsync(new AddChampionPage(new EditChampionViewM(Manager, new EditChampionVm(ChampionVM), ChampionVM)));

@ -5,12 +5,12 @@ using Model;
using System.Windows.Input;
using static StubLib.StubData;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
namespace View.ModelViewPage
{
public class ChampionsViewM
public partial class ChampionsViewM
{
public Command EditChampionCommand { get; }
public ChampionManagerVM championManagerVm { get; }
@ -18,27 +18,21 @@ namespace View.ModelViewPage
{
championManagerVm = championManager;
PushToDetailCommand = new Command<ChampionVm>(PushToDetail);
AddChampionCommand = new Command(Addchampion);
EditChampionCommand = new Command<ChampionVm>(EditChampion);
}
public Command PushToDetailCommand { get; }
public Command AddChampionCommand { get; }
[RelayCommand]
private void PushToDetail(ChampionVm champion)
{
Shell.Current.Navigation.PushAsync(new DetailChampion(new ChampionDetailViewM(championManagerVm, champion)));
}
private void Addchampion()
[RelayCommand]
private void AddChampion()
{
Shell.Current.Navigation.PushAsync(page: new AddChampionPage(new EditChampionViewM(championManagerVm, new EditChampionVm(null), null)));
}
[RelayCommand]
private async void EditChampion(ChampionVm championVM)
{
await Shell.Current.Navigation.PushAsync(new AddChampionPage(new EditChampionViewM(championManagerVm, new EditChampionVm(championVM), championVM)));

@ -1,23 +1,19 @@
using System;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using Model;
using ViewModels;
namespace View.ModelViewPage
{
public class EditChampionViewM
public partial class EditChampionViewM
{
public Command PickIconCommand { get; }
public Command PickImageCommand { get; }
public EditChampionViewM(ChampionManagerVM manager, EditChampionVm aditableChampion,ChampionVm championVM)
{
Manager = manager;
EditableChampion = aditableChampion;
ChampionVM = championVM;
SaveChampionCommand = new Command(SaveChampion);
PickIconCommand = new Command(async () => await PickIcon());
PickImageCommand = new Command(async () => await PickImage());
Title = aditableChampion.IsNew ? "Create" : "Update";
}
@ -28,9 +24,8 @@ namespace View.ModelViewPage
private ChampionVm ChampionVM;
public Command SaveChampionCommand { get; }
[RelayCommand]
private async void SaveChampion()
{
Manager.SaveChampion(EditableChampion, ChampionVM);
@ -40,9 +35,9 @@ namespace View.ModelViewPage
{
get => Characteristics;
}
[RelayCommand]
private async Task PickIcon()
{
var result = await FilePicker.PickAsync(new PickOptions
@ -60,6 +55,7 @@ namespace View.ModelViewPage
}
}
[RelayCommand]
private async Task PickImage()
{
var result = await FilePicker.PickAsync(new PickOptions

@ -25,7 +25,7 @@
</Grid.RowDefinitions>
<Grid Grid.Row="1" WidthRequest="420" HeightRequest="200" Margin="20">
<Image Source="{Binding ChampionVM.Image, Converter={StaticResource Base64ToImageConverter}}"></Image>
<Image Source="{Binding ChampionVM.Image.Base64, Converter={StaticResource Base64ToImageConverter}}"></Image>
</Grid>
<Grid Grid.Row="2" Margin="20">
<Grid.ColumnDefinitions>

@ -57,6 +57,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="CommunityToolkit.Maui" Version="5.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
</ItemGroup>
<ItemGroup>

@ -3,29 +3,21 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model;
namespace ViewModels
{
public class ChampionManagerVM : INotifyPropertyChanged
public partial class ChampionManagerVM : ObservableObject
{
public ObservableCollection<ChampionVm> Champions { get; }
public event PropertyChangedEventHandler? PropertyChanged;
public Command NextPageCommand { get; private set; }
public Command PreviousPageCommand { get; }
public Command DeleChampionCommand { get; }
public ICommand DeleteChampionCommand { get; }
public IDataManager DataManager
{
get => _dataManager;
set
{
if (_dataManager == value) return;
_dataManager = value;
OnPropertyChanged();
}
set => _dataManager = value;
}
private IDataManager _dataManager { get; set; }
@ -33,11 +25,8 @@ namespace ViewModels
{
DataManager = dataManager;
Champions = new ObservableCollection<ChampionVm>();
DeleteChampionCommand = new Command<ChampionVm>(async (ChampionVm obj) => await DeleteChampion(obj));
NextPageCommand = new Command(NextPage, CanExecuteNext);
PreviousPageCommand = new Command(PreviousPage, CanExecutePrevious);
LoadChampions(index, Count).ConfigureAwait(false);
LoadChampions(index, Count).ConfigureAwait(false);
PropertyChanged += ChampionManagerVM_PropertyChanged;
Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
}
@ -51,66 +40,21 @@ namespace ViewModels
}
}
private void NextPage()
{
Index++;
RefreshCanExecute();
}
private void PreviousPage()
{
Index--;
RefreshCanExecute();
}
private bool CanExecutePrevious()
{
return Index > 1;
}
private bool CanExecuteNext()
{
var val = (this.Index) < this.PageTotale;
return val;
}
void RefreshCanExecute()
{
PreviousPageCommand.ChangeCanExecute();
NextPageCommand.ChangeCanExecute();
}
public int Index
{
get => index;
set
{
if (index == value) return;
index = value;
OnPropertyChanged();
}
}
private int index;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(PreviousPageCommand),nameof(NextPageCommand))]
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;
[ObservableProperty]
private int total;
public int Total
{
get => total;
private set
{
total = value;
OnPropertyChanged();
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private async Task LoadChampions(int index, int count)
{
@ -124,6 +68,7 @@ namespace ViewModels
}
}
public async void SaveChampion(EditChampionVm editableChampionVM, ChampionVm? championVM)
{
if (editableChampionVM is null) return;
@ -145,10 +90,29 @@ namespace ViewModels
}
[RelayCommand(CanExecute =nameof(CanExecuteNext))]
private void NextPage()
{
Index++;
}
private async void updatePagination()
[RelayCommand(CanExecute =nameof(CanExecutePrevious))]
private void PreviousPage()
{
Index--;
}
private bool CanExecutePrevious()
{
return Index > 1;
}
private bool CanExecuteNext()
{
var val = (this.Index) < this.PageTotale;
return val;
}
private async void updatePagination()
{
@ -164,6 +128,8 @@ namespace ViewModels
OnPropertyChanged(nameof(PageTotale));
}
[RelayCommand]
public async Task DeleteChampion(ChampionVm champion)
{
if (champion is null) return;

@ -2,10 +2,11 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.ComponentModel;
using Model;
namespace ViewModels
{
public class ChampionVm : INotifyPropertyChanged
public class ChampionVm : ObservableObject
{
public ChampionVm(Champion champion) => Model = champion;
@ -19,10 +20,7 @@ namespace ViewModels
get => model;
set
{
if (value.Equals(model)) return;
if (value == null) return;
model = value;
OnPropertyChanged();
}
}
@ -34,43 +32,23 @@ namespace ViewModels
public string Icon
{
get => Model.Icon;
set
{
if (model == null) return;
Model.Icon = value;
OnPropertyChanged();
}
set => SetProperty(Model.Icon, value, Model, (mod, val) => model.Icon = val);
}
public string Image
public LargeImage Image
{
get => Model.Image.Base64;
set
{
if (model == null) return;
Model.Image.Base64 = value;
OnPropertyChanged();
}
get => Model.Image;
set=> SetProperty(Model.Image, value, Model, (mod, val) => model.Image = val);
}
public ChampionClass Class
{
get => Model.Class;
set
{
if (model == null) return;
Model.Class = value;
OnPropertyChanged();
}
set=> SetProperty(Model.Class, value, Model, (mod, val) => model.Class = val);
}
public string Bio
{
get => Model.Bio;
set
{
if (model == null) return;
Model.Bio = value;
OnPropertyChanged();
}
set=> SetProperty(Model.Bio, value, Model, (mod, val) => model.Bio = val);
}
private ObservableCollection<Skill> skills;
public HashSet<Skill> Skills
@ -83,13 +61,6 @@ namespace ViewModels
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -2,11 +2,12 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.ComponentModel;
using Model;
namespace ViewModels
{
public class EditChampionVm : INotifyPropertyChanged
public partial class EditChampionVm : ObservableObject
{
public ChampionVm Model { get; set; }
public EditChampionVm(ChampionVm vm)
@ -16,8 +17,8 @@ namespace ViewModels
_bio = IsNew ? string.Empty : Model.Bio;
icon = IsNew ? string.Empty : Model.Icon;
_name = IsNew ? string.Empty : Model.Name;
image = IsNew ? string.Empty : Model.Image;
_classe = IsNew ? ChampionClass.Unknown : Model.Class;
image = IsNew ? string.Empty : Model.Image.Base64;
_class = IsNew ? ChampionClass.Unknown : Model.Class;
ListClasses = Enum.GetValues<ChampionClass>().Where(c => c != ChampionClass.Unknown).ToArray();
}
@ -25,87 +26,31 @@ namespace ViewModels
public IEnumerable<ChampionClass> ListClasses { get; }
[ObservableProperty]
private string _name;
public string Name
{
get => _name;
set
{
if (_name == value) return;
_name = value;
OnPropertyChanged();
}
}
[ObservableProperty]
private string icon;
public string Icon
{
get => icon;
set
{
if (icon == value) return;
icon = value;
OnPropertyChanged();
}
}
[ObservableProperty]
private string _bio;
public string Bio
{
get => _bio;
set
{
if (_bio == value) return;
_bio = value;
OnPropertyChanged();
}
}
[ObservableProperty]
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();
}
}
[ObservableProperty]
private ChampionClass _class;
[ObservableProperty]
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()
{
@ -113,7 +58,7 @@ namespace ViewModels
{
Model.Bio = Bio;
Model.Icon = Icon;
Model.Image = Image;
Model.Image.Base64 = Image;
Model.Class = Class;
}
else

@ -29,4 +29,7 @@
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
</ItemGroup>
</Project>

Loading…
Cancel
Save