diff --git a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs index 3f8b7ff7..b127f9b1 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs @@ -16,7 +16,7 @@ namespace AideDeJeu.ViewModels public abstract class FilterViewModel : BaseViewModel { public ICommand LoadItemsCommand { get; protected set; } - public abstract Task> FilterItems(IEnumerable items, CancellationToken token = default); + public abstract Task> FilterItems(IEnumerable items, CancellationToken cancellationToken = default); public abstract IEnumerable Filters { get; } private string _SearchText = ""; public string SearchText diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemDetailViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemDetailViewModel.cs index 47240540..864644cc 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemDetailViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemDetailViewModel.cs @@ -17,188 +17,9 @@ namespace AideDeJeu.ViewModels set { SetProperty(ref _Item, value); - //OnPropertyChanged(nameof(TypeSizeAlignment)); - //OnPropertyChanged(nameof(ArmorClass)); - //OnPropertyChanged(nameof(HitPoints)); - //OnPropertyChanged(nameof(Speed)); - //OnPropertyChanged(nameof(SavingThrows)); - //OnPropertyChanged(nameof(Skills)); - //OnPropertyChanged(nameof(DamageVulnerabilities)); - //OnPropertyChanged(nameof(DamageResistances)); - //OnPropertyChanged(nameof(DamageImmunities)); - //OnPropertyChanged(nameof(ConditionImmunities)); - //OnPropertyChanged(nameof(Senses)); - //OnPropertyChanged(nameof(Languages)); - //OnPropertyChanged(nameof(Challenge)); - //OnPropertyChanged(nameof(Duration)); - //OnPropertyChanged(nameof(Duration)); } } - //public FormattedString TypeSizeAlignment - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("contentital"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = string.Format("{0} de taille {1}, {2}", Item.Type, Item.Size, Item.Alignment), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString ArmorClass - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = string.Format("Classe d'armure {0}", Item.ArmorClass), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString HitPoints - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = string.Format("Points de vie {0}", Item.HitPoints), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString Speed - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = string.Format("Vitesse {0}", Item.Speed), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString SavingThrows - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Jets de sauvegarde ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.SavingThrows, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString Skills - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Compétence ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.Skills, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - - //public FormattedString DamageVulnerabilities - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Vulnérabilité aux dégâts ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.DamageVulnerabilities, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString DamageImmunities - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Immunité contre les dégâts ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.DamageImmunities, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString ConditionImmunities - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Immunité contre les états ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.ConditionImmunities, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString DamageResistances - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Résistance aux dégâts ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.DamageResistances, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - - - //public FormattedString Senses - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Sens ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.Senses, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString Languages - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Langues ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.Languages, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - - //public FormattedString Challenge - //{ - // get - // { - // var fd = FormatedTextHelpers.FontData.FromResource("content"); - // var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); - // var fs = new FormattedString(); - // fs.Spans.Add(new Span() { Text = "Dangerosité ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); - // fs.Spans.Add(new Span() { Text = Item.Challenge, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); - // return fs; - // } - //} - public Command LoadItemCommand { get; set; } public ItemDetailViewModel(Item item = null) diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index 3ad4cbce..e1f01fcd 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -73,16 +73,15 @@ namespace AideDeJeu.ViewModels return _AllItems; } - async Task LoadItemsAsync(CancellationToken token = default) + async Task LoadItemsAsync(CancellationToken cancellationToken = default) { IsBusy = true; Main.IsLoading = true; try { var filterViewModel = Main.GetFilterViewModel(ItemSourceType); - var items = await filterViewModel.FilterItems(await GetAllItemsAsync(), token); + var items = await filterViewModel.FilterItems(await GetAllItemsAsync(), cancellationToken: cancellationToken); Main.Items = items.ToList(); - Main.IsLoading = false; } catch (OperationCanceledException ex) { @@ -90,16 +89,14 @@ namespace AideDeJeu.ViewModels } finally { + Main.IsLoading = false; IsBusy = false; } } public async Task ExecuteLoadItemsCommandAsync() { - if (cancellationTokenSource != null) - { - cancellationTokenSource.Cancel(); - } + cancellationTokenSource?.Cancel(); cancellationTokenSource = new CancellationTokenSource(); await LoadItemsAsync(cancellationTokenSource.Token); } diff --git a/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs index 685a6b3b..87d881c2 100644 --- a/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml.cs @@ -28,11 +28,6 @@ namespace AideDeJeu.Views BindingContext = this.viewModel = itemVM; mdMarkdown.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s); - //mdNameVO.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s); - //mdSpecialFeatures.NavigateToLink = async(s) => await viewModel.Main.NavigateToLink(s); - //mdActions.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s); - //mdReactions.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s); - //mdLegendaryActions.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s); } public ItemDetailPage()