diff --git a/App/App.csproj b/App/App.csproj
index 855fd29..5c8fe88 100644
--- a/App/App.csproj
+++ b/App/App.csproj
@@ -52,17 +52,20 @@
+
+
+
diff --git a/App/AppShell.xaml.cs b/App/AppShell.xaml.cs
index dc45408..7dd4687 100644
--- a/App/AppShell.xaml.cs
+++ b/App/AppShell.xaml.cs
@@ -8,7 +8,6 @@ public partial class AppShell : Shell
{
InitializeComponent();
- Routing.RegisterRoute(nameof(ChampionAddEditPage), typeof(ChampionAddEditPage));
Routing.RegisterRoute(nameof(ChampionDetailPage), typeof(ChampionDetailPage));
}
}
diff --git a/App/MauiProgram.cs b/App/MauiProgram.cs
index f3a6caf..c19fcc0 100644
--- a/App/MauiProgram.cs
+++ b/App/MauiProgram.cs
@@ -1,8 +1,10 @@
using Microsoft.Extensions.Logging;
+using CommunityToolkit.Maui;
using Model;
using StubLib;
using ViewModel;
using App.Pages;
+using App.ViewModel;
namespace App;
@@ -13,14 +15,16 @@ public static class MauiProgram
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
- .ConfigureFonts(fonts =>
+ .UseMauiCommunityToolkit()
+ .ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.Services.AddSingleton()
- .AddSingleton()
- .AddSingleton();
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton();
#if DEBUG
builder.Logging.AddDebug();
diff --git a/App/Pages/ChampionDetailPage.xaml.cs b/App/Pages/ChampionDetailPage.xaml.cs
index b84ded8..2516ca8 100644
--- a/App/Pages/ChampionDetailPage.xaml.cs
+++ b/App/Pages/ChampionDetailPage.xaml.cs
@@ -6,15 +6,15 @@ public partial class ChampionDetailPage : ContentPage
{
public ChampionVM ChampionVM { get; private set; }
- public ChampionDetailPage(ChampionVM championVM)
+ public ChampionDetailPage()
{
- ChampionVM = championVM;
+ //ChampionVM = championVM;
InitializeComponent();
BindingContext = ChampionVM;
}
async void ToolbarItem_Clicked(System.Object sender, System.EventArgs e)
{
- await Navigation.PushAsync(new ChampionAddEditPage());
+ await Navigation.PushModalAsync(new ChampionAddEditPage());
}
}
diff --git a/App/Pages/ChampionsListPage.xaml b/App/Pages/ChampionsListPage.xaml
index 9b6ca4f..b570af4 100644
--- a/App/Pages/ChampionsListPage.xaml
+++ b/App/Pages/ChampionsListPage.xaml
@@ -2,10 +2,11 @@
-
+
@@ -24,9 +25,14 @@
+
+
+
+
@@ -60,11 +66,11 @@
-
-
+
+
-
-
+
+
diff --git a/App/Pages/ChampionsListPage.xaml.cs b/App/Pages/ChampionsListPage.xaml.cs
index 0145309..f6ccb99 100644
--- a/App/Pages/ChampionsListPage.xaml.cs
+++ b/App/Pages/ChampionsListPage.xaml.cs
@@ -1,25 +1,17 @@
using ViewModel;
+using App.ViewModel;
namespace App.Pages;
public partial class ChampionsListPage : ContentPage
{
- public ChampionManagerVM ChampionManagerVM { get; private set; }
+ public ChampionListPageVM ChampionListPageVM { get; private set; }
- public ChampionsListPage(ChampionManagerVM championManagerVM)
+ public ChampionsListPage(ChampionListPageVM championListPageVM)
{
- ChampionManagerVM = championManagerVM;
- InitializeComponent();
- BindingContext = ChampionManagerVM;
- }
-
- async void AddClicked(System.Object sender, System.EventArgs e)
- {
- await Navigation.PushAsync(new ChampionAddEditPage());
- }
-
- async void ListView_ItemSelected(System.Object sender, Microsoft.Maui.Controls.SelectedItemChangedEventArgs e)
- {
- await Navigation.PushAsync(new ChampionDetailPage(e.SelectedItem as ChampionVM));
+ ChampionListPageVM = championListPageVM;
+ ChampionListPageVM.Navigation = this.Navigation;
+ InitializeComponent();
+ BindingContext = ChampionListPageVM;
}
}
diff --git a/App/ViewModel/ChampionListPageVM.cs b/App/ViewModel/ChampionListPageVM.cs
new file mode 100644
index 0000000..80e3cec
--- /dev/null
+++ b/App/ViewModel/ChampionListPageVM.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Windows.Input;
+using App.Pages;
+using ViewModel;
+
+namespace App.ViewModel
+{
+ public class ChampionListPageVM
+ {
+ public INavigation Navigation { get; set; }
+
+ public ChampionManagerVM ChampionManagerVM { get; private set; }
+
+ public ICommand NavigateToChampionDetailCommand { get; private set; }
+ public ICommand NaviagteToChampionAddEditPageCommand { get; private set; }
+
+ public ChampionListPageVM(ChampionManagerVM championManager)
+ {
+ ChampionManagerVM = championManager;
+
+ NavigateToChampionDetailCommand = new Command (
+ execute: async () => await Shell.Current.GoToAsync(nameof(ChampionDetailPage)),
+ canExecute: () => ChampionManagerVM is not null
+ );
+
+ NaviagteToChampionAddEditPageCommand = new Command(
+ execute: async () => await Navigation.PushModalAsync(new ChampionAddEditPage()),
+ canExecute: () => ChampionManagerVM is not null
+ );
+ }
+ }
+}
+
diff --git a/ViewModel/BaseToolkit.cs b/ViewModel/BaseToolkit.cs
index 6a5c88e..88907ff 100644
--- a/ViewModel/BaseToolkit.cs
+++ b/ViewModel/BaseToolkit.cs
@@ -1,9 +1,10 @@
-using System.ComponentModel;
+using System;
+using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace ViewModel
{
- public class BaseToolkit : INotifyPropertyChanged
+ public class BaseToolkit
{
public event PropertyChangedEventHandler? PropertyChanged;
@@ -12,4 +13,5 @@ namespace ViewModel
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
-}
\ No newline at end of file
+}
+
diff --git a/ViewModel/ChampionManagerVM.cs b/ViewModel/ChampionManagerVM.cs
index 9cd6c0b..57f420f 100644
--- a/ViewModel/ChampionManagerVM.cs
+++ b/ViewModel/ChampionManagerVM.cs
@@ -1,10 +1,14 @@
-using System.Collections.ObjectModel;
+using System;
using Model;
+using System.Collections.ObjectModel;
+using System.Windows.Input;
namespace ViewModel
{
- public class ChampionManagerVM : BaseToolkit
- {
+ public class ChampionManagerVM : BaseToolkit
+ {
+ #region Properties
+
public ReadOnlyObservableCollection ChampionVMs { get; private set; }
private ObservableCollection _championVMs { get; set; } = new ObservableCollection();
@@ -16,18 +20,11 @@ namespace ViewModel
if (_dataManager == value) return;
_dataManager = value;
OnPropertyChanged();
- LoadChampions();
+ LoadChampions(Index, Count);
}
}
private IDataManager _dataManager;
- public ChampionManagerVM(IDataManager dataManager)
- {
- DataManager = dataManager;
- ChampionVMs = new ReadOnlyObservableCollection(_championVMs);
- PropertyChanged += ChampionManagerVM_PropertyChanged;
- }
-
public int Index
{
get => _index;
@@ -35,6 +32,9 @@ namespace ViewModel
{
if (_index == value) return;
_index = value;
+ OnPropertyChanged();
+ (NextPageCommand as Command).ChangeCanExecute();
+ (PreviousPageCommand as Command).ChangeCanExecute();
}
}
@@ -42,10 +42,46 @@ namespace ViewModel
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(_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)
{
if (e.PropertyName == nameof(Index))
- await LoadChampions();
+ await LoadChampions(Index, Count);
}
public int NbPages => NbChampions / Count;
@@ -66,14 +102,40 @@ namespace ViewModel
OnPropertyChanged(nameof(NbPages));
}
- private async Task LoadChampions()
+ #region Commands methods
+
+ private async Task LoadChampions(int index, int count)
{
_championVMs.Clear();
- var champions = await DataManager.ChampionsMgr.GetItems(0, Count);
+ var champions = await DataManager.ChampionsMgr.GetItems(index, count);
foreach (var champion in champions)
{
_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
}
-}
\ No newline at end of file
+}
+
diff --git a/ViewModel/ChampionVM.cs b/ViewModel/ChampionVM.cs
index 0a99621..996874c 100644
--- a/ViewModel/ChampionVM.cs
+++ b/ViewModel/ChampionVM.cs
@@ -1,10 +1,10 @@
-using Model;
-using System;
+using System;
+using Model;
namespace ViewModel
{
- public class ChampionVM : BaseToolkit
- {
+ public class ChampionVM : BaseToolkit
+ {
public Champion Model
{
get => _model;
@@ -17,17 +17,6 @@ namespace ViewModel
}
private Champion _model;
-
- public ChampionVM(Champion model)
- {
- _model = model;
- }
-
- public ChampionVM()
- {
- _model = new Champion("Poppy", ChampionClass.Tank);
- }
-
public string Name
{
get => Model.Name;
@@ -70,5 +59,16 @@ namespace ViewModel
{
get => Model.Characteristics;
}
+
+ public ChampionVM(Champion model)
+ {
+ _model = model;
+ }
+
+ public ChampionVM()
+ {
+ _model = new Champion("Poppy", ChampionClass.Tank);
+ }
}
-}
\ No newline at end of file
+}
+
diff --git a/ViewModel/Platforms/Android/PlatformClass1.cs b/ViewModel/Platforms/Android/PlatformClass1.cs
new file mode 100644
index 0000000..f2f65bf
--- /dev/null
+++ b/ViewModel/Platforms/Android/PlatformClass1.cs
@@ -0,0 +1,7 @@
+namespace ViewModel;
+
+// All the code in this file is only included on Android.
+public class PlatformClass1
+{
+}
+
diff --git a/ViewModel/Platforms/MacCatalyst/PlatformClass1.cs b/ViewModel/Platforms/MacCatalyst/PlatformClass1.cs
new file mode 100644
index 0000000..c589630
--- /dev/null
+++ b/ViewModel/Platforms/MacCatalyst/PlatformClass1.cs
@@ -0,0 +1,7 @@
+namespace ViewModel;
+
+// All the code in this file is only included on Mac Catalyst.
+public class PlatformClass1
+{
+}
+
diff --git a/ViewModel/Platforms/Tizen/PlatformClass1.cs b/ViewModel/Platforms/Tizen/PlatformClass1.cs
new file mode 100644
index 0000000..232af5f
--- /dev/null
+++ b/ViewModel/Platforms/Tizen/PlatformClass1.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace ViewModel
+{
+ // All the code in this file is only included on Tizen.
+ public class PlatformClass1
+ {
+ }
+}
diff --git a/ViewModel/Platforms/Windows/PlatformClass1.cs b/ViewModel/Platforms/Windows/PlatformClass1.cs
new file mode 100644
index 0000000..5ec13fc
--- /dev/null
+++ b/ViewModel/Platforms/Windows/PlatformClass1.cs
@@ -0,0 +1,7 @@
+namespace ViewModel;
+
+// All the code in this file is only included on Windows.
+public class PlatformClass1
+{
+}
+
diff --git a/ViewModel/Platforms/iOS/PlatformClass1.cs b/ViewModel/Platforms/iOS/PlatformClass1.cs
new file mode 100644
index 0000000..5a3f6c6
--- /dev/null
+++ b/ViewModel/Platforms/iOS/PlatformClass1.cs
@@ -0,0 +1,7 @@
+namespace ViewModel;
+
+// All the code in this file is only included on iOS.
+public class PlatformClass1
+{
+}
+
diff --git a/ViewModel/ViewModel.csproj b/ViewModel/ViewModel.csproj
index c1e1d83..c41cf7d 100644
--- a/ViewModel/ViewModel.csproj
+++ b/ViewModel/ViewModel.csproj
@@ -1,12 +1,26 @@
-
- net7.0
- enable
- enable
-
+
+ net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst
+ $(TargetFrameworks);net7.0-windows10.0.19041.0
+
+
+ true
+ true
+ enable
-
-
-
+ 14.2
+ 14.0
+ 21.0
+ 10.0.17763.0
+ 10.0.17763.0
+ 6.5
+
+
+
+ false
+
+
+
+