diff --git a/App/App.csproj b/App/App.csproj index 85e9b12..7525df6 100644 --- a/App/App.csproj +++ b/App/App.csproj @@ -12,7 +12,7 @@ enable - App + LOL App com.companyname.app @@ -62,10 +62,15 @@ + - + + + + + diff --git a/App/AppShell.xaml.cs b/App/AppShell.xaml.cs index 60f8ec8..dc45408 100644 --- a/App/AppShell.xaml.cs +++ b/App/AppShell.xaml.cs @@ -1,10 +1,15 @@ -namespace App; +using App.Pages; + +namespace App; public partial class AppShell : Shell { public AppShell() { InitializeComponent(); - } + + Routing.RegisterRoute(nameof(ChampionAddEditPage), typeof(ChampionAddEditPage)); + Routing.RegisterRoute(nameof(ChampionDetailPage), typeof(ChampionDetailPage)); + } } diff --git a/App/MauiProgram.cs b/App/MauiProgram.cs index 15e1a2e..9b09708 100644 --- a/App/MauiProgram.cs +++ b/App/MauiProgram.cs @@ -1,4 +1,8 @@ using Microsoft.Extensions.Logging; +using Model; +using StubLib; +using ViewModel; +using App.Pages; namespace App; @@ -13,7 +17,13 @@ public static class MauiProgram { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); - }); + }) + .Services.AddSingleton() + .AddSingleton() + .AddSingleton() + + .AddTransient() + .AddTransient(); #if DEBUG builder.Logging.AddDebug(); diff --git a/App/Pages/ChampionAddEditPage.xaml b/App/Pages/ChampionAddEditPage.xaml new file mode 100644 index 0000000..25ee6d1 --- /dev/null +++ b/App/Pages/ChampionAddEditPage.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/App/Pages/ChampionAddEditPage.xaml.cs b/App/Pages/ChampionAddEditPage.xaml.cs new file mode 100644 index 0000000..19116aa --- /dev/null +++ b/App/Pages/ChampionAddEditPage.xaml.cs @@ -0,0 +1,9 @@ +namespace App.Pages; + +public partial class ChampionAddEditPage : ContentPage +{ + public ChampionAddEditPage() + { + InitializeComponent(); + } +} diff --git a/App/Pages/ChampionDetailPage.xaml b/App/Pages/ChampionDetailPage.xaml new file mode 100644 index 0000000..f6b1604 --- /dev/null +++ b/App/Pages/ChampionDetailPage.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/App/Pages/ChampionDetailPage.xaml.cs b/App/Pages/ChampionDetailPage.xaml.cs new file mode 100644 index 0000000..d321107 --- /dev/null +++ b/App/Pages/ChampionDetailPage.xaml.cs @@ -0,0 +1,14 @@ +using ViewModel; + +namespace App.Pages; + +public partial class ChampionDetailPage : ContentPage +{ + //public ChampionVM ChampionVM { get; private set; } + + public ChampionDetailPage(ChampionVM championVM) + { + InitializeComponent(); + BindingContext = championVM; + } +} diff --git a/App/Pages/ChampionsListPage.xaml b/App/Pages/ChampionsListPage.xaml index a68bb63..4e46368 100644 --- a/App/Pages/ChampionsListPage.xaml +++ b/App/Pages/ChampionsListPage.xaml @@ -4,19 +4,17 @@ x:Class="App.Pages.ChampionsListPage" Title="Champions"> - + - - - - - - - - - - + + + + + + + + diff --git a/App/Pages/ChampionsListPage.xaml.cs b/App/Pages/ChampionsListPage.xaml.cs index b25929a..34f9853 100644 --- a/App/Pages/ChampionsListPage.xaml.cs +++ b/App/Pages/ChampionsListPage.xaml.cs @@ -1,9 +1,28 @@ -namespace App.Pages; +using ViewModel; + +namespace App.Pages; public partial class ChampionsListPage : ContentPage { - public ChampionsListPage() + public ChampionManagerVM ChampionManagerVM { get; private set; } + + public ChampionsListPage(ChampionManagerVM championManagerVM) { + ChampionManagerVM = championManagerVM; InitializeComponent(); - } + BindingContext = ChampionManagerVM; + } + + async void AddClicked(System.Object sender, System.EventArgs e) + { + await Shell.Current.GoToAsync(nameof(ChampionAddEditPage)); + } + + async void ListView_ItemSelected(System.Object sender, Microsoft.Maui.Controls.SelectedItemChangedEventArgs e) + { + await Shell.Current.GoToAsync(nameof(ChampionDetailPage), true, new Dictionary + { + { "ChampionVM", e.SelectedItem } + }); + } } diff --git a/App/Pages/MainPage.xaml b/App/Pages/MainPage.xaml index b817a0f..5c610e9 100644 --- a/App/Pages/MainPage.xaml +++ b/App/Pages/MainPage.xaml @@ -4,13 +4,12 @@ x:Class="App.Pages.MainPage" Title="Home"> - - - - + + + + diff --git a/App/Resources/Images/icon_home.png b/App/Resources/Images/icon_home.png index c6745dd..ae78116 100644 Binary files a/App/Resources/Images/icon_home.png and b/App/Resources/Images/icon_home.png differ diff --git a/App/Resources/Images/lol_logo.png b/App/Resources/Images/lol_logo.png new file mode 100644 index 0000000..389cf3f Binary files /dev/null and b/App/Resources/Images/lol_logo.png differ diff --git a/LeagueOfLegends.sln b/LeagueOfLegends.sln index 87503f3..01782d8 100644 --- a/LeagueOfLegends.sln +++ b/LeagueOfLegends.sln @@ -13,7 +13,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTests", "Tests\Conso EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A88951E3-B544-49E0-A7A2-47360DD69239}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.csproj", "{AF68E1F2-F41E-42C5-A8DA-331A22854064}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.csproj", "{9A58F419-4627-4656-9C36-959DA39A55E9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ViewModel", "ViewModel\ViewModel.csproj", "{7A222D06-D84F-4DA7-ADCC-71D339261117}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,10 +39,14 @@ Global {D2E5D03F-C14A-4E6D-AF5C-9749A75ACBA0}.Debug|Any CPU.Build.0 = Debug|Any CPU {D2E5D03F-C14A-4E6D-AF5C-9749A75ACBA0}.Release|Any CPU.ActiveCfg = Release|Any CPU {D2E5D03F-C14A-4E6D-AF5C-9749A75ACBA0}.Release|Any CPU.Build.0 = Release|Any CPU - {AF68E1F2-F41E-42C5-A8DA-331A22854064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AF68E1F2-F41E-42C5-A8DA-331A22854064}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AF68E1F2-F41E-42C5-A8DA-331A22854064}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AF68E1F2-F41E-42C5-A8DA-331A22854064}.Release|Any CPU.Build.0 = Release|Any CPU + {9A58F419-4627-4656-9C36-959DA39A55E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A58F419-4627-4656-9C36-959DA39A55E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A58F419-4627-4656-9C36-959DA39A55E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A58F419-4627-4656-9C36-959DA39A55E9}.Release|Any CPU.Build.0 = Release|Any CPU + {7A222D06-D84F-4DA7-ADCC-71D339261117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A222D06-D84F-4DA7-ADCC-71D339261117}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A222D06-D84F-4DA7-ADCC-71D339261117}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A222D06-D84F-4DA7-ADCC-71D339261117}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ViewModel/BaseToolkit.cs b/ViewModel/BaseToolkit.cs new file mode 100644 index 0000000..6a5c88e --- /dev/null +++ b/ViewModel/BaseToolkit.cs @@ -0,0 +1,15 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace ViewModel +{ + public class BaseToolkit : INotifyPropertyChanged + { + public event PropertyChangedEventHandler? PropertyChanged; + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} \ No newline at end of file diff --git a/ViewModel/ChampionManagerVM.cs b/ViewModel/ChampionManagerVM.cs new file mode 100644 index 0000000..f65ef78 --- /dev/null +++ b/ViewModel/ChampionManagerVM.cs @@ -0,0 +1,61 @@ +using System.Collections.ObjectModel; +using Model; + +namespace ViewModel +{ + public class ChampionManagerVM : BaseToolkit + { + public ReadOnlyObservableCollection ChampionVMs { get; private set; } + private ObservableCollection _championVMs { get; set; } = new ObservableCollection(); + + public IDataManager DataManager + { + get => _dataManager; + set + { + if (_dataManager == value) return; + _dataManager = value; + OnPropertyChanged(); + LoadChampions(); + } + } + private IDataManager _dataManager; + + public ChampionManagerVM(IDataManager dataManager) + { + DataManager = dataManager; + ChampionVMs = new ReadOnlyObservableCollection(_championVMs); + PropertyChanged += ChampionManagerVM_PropertyChanged; + } + + public int Index + { + get => _index; + set + { + if (_index == value) return; + _index = value; + } + + } + private int _index; + + public int Count { get; set; } = 5; + + private async void ChampionManagerVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(Index)) + await LoadChampions(); + } + + private async Task LoadChampions() + { + _championVMs.Clear(); + var champions = await DataManager.ChampionsMgr.GetItems(0, Count); + foreach (var champion in champions) + { + _championVMs.Add(new ChampionVM(champion)); + } + } + } +} \ No newline at end of file diff --git a/ViewModel/ChampionVM.cs b/ViewModel/ChampionVM.cs new file mode 100644 index 0000000..8236d66 --- /dev/null +++ b/ViewModel/ChampionVM.cs @@ -0,0 +1,46 @@ +using Model; + +namespace ViewModel +{ + public class ChampionVM : BaseToolkit + { + public Champion Model + { + get => _model; + set + { + //if (_model.Equals(value) || _model.Equals(null)) return; + _model = value; + OnPropertyChanged(); + } + } + private Champion _model; + + + public ChampionVM(Champion model) + { + Model = model; + } + + public ChampionVM() + { + Model = new Champion("Poppy", ChampionClass.Tank); + } + + public string Name + { + get => Model.Name; + } + + public string Bio + { + get => Model.Bio; + set + { + if (value == null) return; + _model.Bio = value; + OnPropertyChanged(); + } + } + } +} \ No newline at end of file diff --git a/ViewModel/ViewModel.csproj b/ViewModel/ViewModel.csproj new file mode 100644 index 0000000..c1e1d83 --- /dev/null +++ b/ViewModel/ViewModel.csproj @@ -0,0 +1,12 @@ + + + + net7.0 + enable + enable + + + + + +