|
|
@ -1,10 +1,14 @@
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System;
|
|
|
|
using Model;
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ViewModel
|
|
|
|
namespace ViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ChampionManagerVM : BaseToolkit
|
|
|
|
public class ChampionManagerVM : BaseToolkit
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyObservableCollection<ChampionVM> ChampionVMs { get; private set; }
|
|
|
|
public ReadOnlyObservableCollection<ChampionVM> ChampionVMs { get; private set; }
|
|
|
|
private ObservableCollection<ChampionVM> _championVMs { get; set; } = new ObservableCollection<ChampionVM>();
|
|
|
|
private ObservableCollection<ChampionVM> _championVMs { get; set; } = new ObservableCollection<ChampionVM>();
|
|
|
|
|
|
|
|
|
|
|
@ -16,18 +20,11 @@ namespace ViewModel
|
|
|
|
if (_dataManager == value) return;
|
|
|
|
if (_dataManager == value) return;
|
|
|
|
_dataManager = value;
|
|
|
|
_dataManager = value;
|
|
|
|
OnPropertyChanged();
|
|
|
|
OnPropertyChanged();
|
|
|
|
LoadChampions();
|
|
|
|
LoadChampions(Index, Count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private IDataManager _dataManager;
|
|
|
|
private IDataManager _dataManager;
|
|
|
|
|
|
|
|
|
|
|
|
public ChampionManagerVM(IDataManager dataManager)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DataManager = dataManager;
|
|
|
|
|
|
|
|
ChampionVMs = new ReadOnlyObservableCollection<ChampionVM>(_championVMs);
|
|
|
|
|
|
|
|
PropertyChanged += ChampionManagerVM_PropertyChanged;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int Index
|
|
|
|
public int Index
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => _index;
|
|
|
|
get => _index;
|
|
|
@ -35,6 +32,9 @@ namespace ViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_index == value) return;
|
|
|
|
if (_index == value) return;
|
|
|
|
_index = value;
|
|
|
|
_index = value;
|
|
|
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
|
|
|
(NextPageCommand as Command).ChangeCanExecute();
|
|
|
|
|
|
|
|
(PreviousPageCommand as Command).ChangeCanExecute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -42,10 +42,46 @@ namespace ViewModel
|
|
|
|
|
|
|
|
|
|
|
|
public int Count { get; set; } = 5;
|
|
|
|
public int Count { get; set; } = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand LoadChampionsCommand { get; private set; }
|
|
|
|
|
|
|
|
public ICommand NextPageCommand { get; private set; }
|
|
|
|
|
|
|
|
public ICommand PreviousPageCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ChampionManagerVM(IDataManager dataManager)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DataManager = dataManager;
|
|
|
|
|
|
|
|
ChampionVMs = new ReadOnlyObservableCollection<ChampionVM>(_championVMs);
|
|
|
|
|
|
|
|
PropertyChanged += ChampionManagerVM_PropertyChanged;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoadChampionsCommand = new Command(
|
|
|
|
|
|
|
|
execute: async () => await LoadChampions(Index, Count),
|
|
|
|
|
|
|
|
canExecute: () => DataManager is not null
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NextPageCommand = new Command(
|
|
|
|
|
|
|
|
execute: () => NextPage(),
|
|
|
|
|
|
|
|
canExecute: () => CanNextPage()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreviousPageCommand = new Command(
|
|
|
|
|
|
|
|
execute: () => PreviousPage(),
|
|
|
|
|
|
|
|
canExecute: () => CanPreviousPage()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
private async void ChampionManagerVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
private async void ChampionManagerVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (e.PropertyName == nameof(Index))
|
|
|
|
if (e.PropertyName == nameof(Index))
|
|
|
|
await LoadChampions();
|
|
|
|
await LoadChampions(Index, Count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int NbPages => NbChampions / Count;
|
|
|
|
public int NbPages => NbChampions / Count;
|
|
|
@ -66,14 +102,40 @@ namespace ViewModel
|
|
|
|
OnPropertyChanged(nameof(NbPages));
|
|
|
|
OnPropertyChanged(nameof(NbPages));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task LoadChampions()
|
|
|
|
#region Commands methods
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task LoadChampions(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_championVMs.Clear();
|
|
|
|
_championVMs.Clear();
|
|
|
|
var champions = await DataManager.ChampionsMgr.GetItems(0, Count);
|
|
|
|
var champions = await DataManager.ChampionsMgr.GetItems(index, count);
|
|
|
|
foreach (var champion in champions)
|
|
|
|
foreach (var champion in champions)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_championVMs.Add(new ChampionVM(champion));
|
|
|
|
_championVMs.Add(new ChampionVM(champion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void NextPage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Index += 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool CanNextPage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void PreviousPage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Index -= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool CanPreviousPage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Index > 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|