From fba3966ae9b61fa610c19be07d3848eae6edf5f2 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Mon, 27 Aug 2018 23:54:12 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20bookmarks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AideDeJeu/AideDeJeu/AideDeJeu.csproj | 12 ++ .../AideDeJeu/Properties/Resource.Designer.cs | 74 +++++++++++ AideDeJeu/AideDeJeu/Properties/Resource.resx | 125 ++++++++++++++++++ AideDeJeu/AideDeJeu/Tools/Converters.cs | 28 ++++ .../ViewModels/BookmarksViewModel.cs | 21 +++ .../AideDeJeu/ViewModels/MainViewModel.cs | 16 +-- AideDeJeu/AideDeJeu/ViewModels/Navigator.cs | 29 ++++ AideDeJeu/AideDeJeu/Views/AboutPage.xaml | 2 +- AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml | 51 +++++++ .../AideDeJeu/Views/BookmarksPage.xaml.cs | 23 ++++ AideDeJeu/AideDeJeu/Views/DeepSearchPage.xaml | 13 +- .../AideDeJeu/Views/FilteredItemsPage.xaml | 2 +- AideDeJeu/AideDeJeu/Views/ItemDetailPage.xaml | 2 +- .../AideDeJeu/Views/ItemDetailPage.xaml.cs | 2 +- AideDeJeu/AideDeJeu/Views/ItemsPage.xaml | 2 +- AideDeJeu/AideDeJeu/Views/MainTabbedPage.xaml | 10 +- 16 files changed, 393 insertions(+), 19 deletions(-) create mode 100644 AideDeJeu/AideDeJeu/Properties/Resource.Designer.cs create mode 100644 AideDeJeu/AideDeJeu/Properties/Resource.resx create mode 100644 AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs create mode 100644 AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml create mode 100644 AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml.cs diff --git a/AideDeJeu/AideDeJeu/AideDeJeu.csproj b/AideDeJeu/AideDeJeu/AideDeJeu.csproj index 02e099a6..aae48e1f 100644 --- a/AideDeJeu/AideDeJeu/AideDeJeu.csproj +++ b/AideDeJeu/AideDeJeu/AideDeJeu.csproj @@ -33,6 +33,11 @@ + + True + True + Resource.resx + Code @@ -335,6 +340,13 @@ + + PublicResXFileCodeGenerator + Resource.Designer.cs + + + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml diff --git a/AideDeJeu/AideDeJeu/Properties/Resource.Designer.cs b/AideDeJeu/AideDeJeu/Properties/Resource.Designer.cs new file mode 100644 index 00000000..f82ac187 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Properties/Resource.Designer.cs @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace AideDeJeu.Properties { + using System; + + + /// + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. + /// + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + /// + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AideDeJeu.Properties.Resource", typeof(Resource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Recherche une chaîne localisée semblable à Lancez une recherche pour voir ici vos résultats ! + /// + ///(Notez que la première recherche peut être assez longue). + /// + public static string EmptySearchAltText { + get { + return ResourceManager.GetString("EmptySearchAltText", resourceCulture); + } + } + } +} diff --git a/AideDeJeu/AideDeJeu/Properties/Resource.resx b/AideDeJeu/AideDeJeu/Properties/Resource.resx new file mode 100644 index 00000000..9c3ecfd1 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Properties/Resource.resx @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Lancez une recherche pour voir ici vos résultats ! + +(Notez que la première recherche peut être assez longue) + + \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/Tools/Converters.cs b/AideDeJeu/AideDeJeu/Tools/Converters.cs index 2183ef2d..b909e226 100644 --- a/AideDeJeu/AideDeJeu/Tools/Converters.cs +++ b/AideDeJeu/AideDeJeu/Tools/Converters.cs @@ -1,10 +1,12 @@ using AideDeJeu.ViewModels; using System; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Xml; using Xamarin.Forms; +using System.Linq; namespace AideDeJeu.Tools { @@ -34,6 +36,32 @@ namespace AideDeJeu.Tools } } + public class IntToValueConverter : IValueConverter + { + public T NullOrZeroValue { get; set; } + public T NonZeroValue { get; set; } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value != null) + { + int? ivalue = value as int?; + if(ivalue.HasValue && ivalue > 0) + { + return NonZeroValue; + } + } + return NullOrZeroValue; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } + + public class IntToBooleanConverter : IntToValueConverter { } + public class HeaderLevelToStyleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs new file mode 100644 index 00000000..f170e6d9 --- /dev/null +++ b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs @@ -0,0 +1,21 @@ +using AideDeJeuLib; +using System; +using System.Collections.Generic; +using System.Text; + +namespace AideDeJeu.ViewModels +{ + public class BookmarksViewModel : BaseViewModel + { + public List>> BookmarksKeyValues { get; set; } = new List>>() + { + new KeyValuePair>("Général", new List()), + new KeyValuePair>("Grimoire", new List()), + new KeyValuePair>("Bestiaire", new List()), + new KeyValuePair>("Sac", new List()), + }; + public int BookmarksIndex { get; set; } = 0; + public IEnumerable Bookmarks { get; set; } + public int BookmarksCount { get; set; } = 0; + } +} diff --git a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs index 21fb268d..e627018f 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs @@ -19,12 +19,12 @@ namespace AideDeJeu.ViewModels set => SetProperty(ref _isLoading, value); } - void AddAnchor(Dictionary anchors, Item item) + void AddAnchor(string source, Dictionary anchors, Item item) { if (item != null && item.Name != null) { var basename = Helpers.IdFromName(item.Name); - var name = basename; + var name = $"{source}.md#{basename}"; int index = 0; while (true) { @@ -35,18 +35,18 @@ namespace AideDeJeu.ViewModels return; } index++; - name = $"{basename}{index}"; + name = $"{source}.md#{basename}{index}"; } } } - void MakeAnchors(Dictionary anchors, Item baseItem) + void MakeAnchors(string source, Dictionary anchors, Item baseItem) { - AddAnchor(anchors, baseItem); + AddAnchor(source, anchors, baseItem); if(baseItem is Items) { foreach(var item in (baseItem as Items)) { - MakeAnchors(anchors, item); + MakeAnchors(source, anchors, item); } } } @@ -77,7 +77,7 @@ namespace AideDeJeu.ViewModels if (item != null) { var anchors = new Dictionary(); - MakeAnchors(anchors, item); + MakeAnchors(source, anchors, item); _AllItems[source] = new ItemWithAnchors() { Item = item, Anchors = anchors }; } } @@ -139,7 +139,7 @@ namespace AideDeJeu.ViewModels if (item != null) { var anchors = new Dictionary(); - MakeAnchors(anchors, item); + MakeAnchors(source, anchors, item); _AllItems[source] = new ItemWithAnchors() { Item = item, Anchors = anchors }; } else diff --git a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs index c1bcb9b0..2598517a 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs @@ -51,6 +51,35 @@ namespace AideDeJeu.ViewModels await Navigation.PushAsync(new Views.DeepSearchPage()); } + private Command _AddToFavoritesCommand = null; + public Command AddToFavoritesCommand + { + get + { + return _AddToFavoritesCommand ?? (_AddToFavoritesCommand = new Command(async () => await ExecuteAddToFavoritesCommandAsync())); + } + } + + public async Task ExecuteAddToFavoritesCommandAsync() + { + var tabbedPage = App.Current.MainPage as MainTabbedPage; + var navigationPage = tabbedPage.MainNavigationPage; + var lastPage = navigationPage.Navigation.NavigationStack.LastOrDefault(); + var context = lastPage.BindingContext; + Item item = null; + if(context is ItemDetailViewModel) + { + item = (context as ItemDetailViewModel).Item; + } + else if(context is ItemsViewModel) + { + item = (context as ItemsViewModel).Items; + } + await Application.Current.MainPage.DisplayAlert("Id", item.Id, "OK"); + var vm = new BookmarksViewModel(); + await Application.Current.MainPage.DisplayActionSheet("Ajouter à", "Annuler", "Nouvelle liste", vm.BookmarksKeyValues.Select(kv => kv.Key).ToArray()); + } + public async Task GotoItemDetailPageAsync(Item item) { if (item == null) diff --git a/AideDeJeu/AideDeJeu/Views/AboutPage.xaml b/AideDeJeu/AideDeJeu/Views/AboutPage.xaml index 47e9bd58..603f2a29 100644 --- a/AideDeJeu/AideDeJeu/Views/AboutPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/AboutPage.xaml @@ -25,7 +25,7 @@ - diff --git a/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml new file mode 100644 index 00000000..4c58e6e9 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml.cs new file mode 100644 index 00000000..2c2fb44d --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml.cs @@ -0,0 +1,23 @@ +using AideDeJeu.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace AideDeJeu.Views +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class BookmarksPage : ContentPage + { + public BookmarksPage () + { + InitializeComponent (); + + BindingContext = new BookmarksViewModel(); + } + } +} \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/Views/DeepSearchPage.xaml b/AideDeJeu/AideDeJeu/Views/DeepSearchPage.xaml index 436785ff..9c51dbca 100644 --- a/AideDeJeu/AideDeJeu/Views/DeepSearchPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/DeepSearchPage.xaml @@ -4,10 +4,16 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="AideDeJeu.Views.DeepSearchPage" xmlns:tools="clr-namespace:AideDeJeu.Tools" + xmlns:properties="clr-namespace:AideDeJeu.Properties" x:Name="This" BackgroundColor="{StaticResource bgtan}" Title="Recherche" Icon="crystal_ball.png"> + + + + + @@ -18,11 +24,16 @@ - + + + + +