From 1ecf4afdc6c09a74740945aab828f7a576ad035a Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Tue, 1 Oct 2019 15:00:59 +0200 Subject: [PATCH] Tests assistant --- AideDeJeu/AideDeJeu.Android/MainActivity.cs | 44 ++++++++++--- AideDeJeu/AideDeJeu/App.xaml.cs | 2 +- .../ViewModels/Library/ItemViewModel.cs | 46 ++++++++++++++ AideDeJeu/AideDeJeu/ViewModels/Navigator.cs | 2 +- .../AideDeJeu/Views/Library/ItemPage.xaml.cs | 7 ++- AideDeJeu/AideDeJeu/Views/MainShell.xaml | 62 ++++++++++--------- AideDeJeu/AideDeJeu/Views/MainShell.xaml.cs | 29 +++++++-- 7 files changed, 147 insertions(+), 45 deletions(-) diff --git a/AideDeJeu/AideDeJeu.Android/MainActivity.cs b/AideDeJeu/AideDeJeu.Android/MainActivity.cs index ee05a8c2..c9dc7c79 100644 --- a/AideDeJeu/AideDeJeu.Android/MainActivity.cs +++ b/AideDeJeu/AideDeJeu.Android/MainActivity.cs @@ -67,7 +67,7 @@ namespace AideDeJeu.Droid string search = Intent.Extras.GetString("search"); if (!string.IsNullOrEmpty(search)) { - Xamarin.Forms.Shell.Current.Navigation.PushAsync(new Views.Library.DeepSearchPage(search)); + Xamarin.Forms.Shell.Current.Navigation.PushAsync(new Views.Library.DeepSearchPage(search), true); } Intent.RemoveExtra("search"); } @@ -157,6 +157,34 @@ namespace AideDeJeu.Droid .Show(); } + public override void OnProvideAssistContent(Android.App.Assist.AssistContent outContent) + { + base.OnProvideAssistContent(outContent); + + outContent.WebUri = Android.Net.Uri.Parse("https://heros-et-dragons.fr/"); + // Provide some JSON + string structuredJson = new Org.Json.JSONObject() + .Put("@type", "Book") + .Put("author", "Lewis Carroll") + .Put("name", "Alice in Wonderland") + .Put("description", + "This is an 1865 novel about a girl named Alice, " + + "who falls through a rabbit hole and " + + "enters a fantasy world." + ).ToString(); + //.Put("@type", "MusicRecording") + //.Put("@id", "https://example.com/music/recording") + //.Put("name", "Album Title") + //.ToString(); + + outContent.StructuredData = structuredJson; + } + + public override void OnProvideAssistData(Bundle data) + { + base.OnProvideAssistData(data); + } + } [IntentFilter(new[] { Android.Content.Intent.ActionAssist }, Categories = new[] { Android.Content.Intent.CategoryDefault })] @@ -187,12 +215,12 @@ namespace AideDeJeu.Droid this.FinishActivity(0); } } - public class AndroidListener : Java.Lang.Object, Application.IOnProvideAssistDataListener - { - public void OnProvideAssistData(Android.App.Activity activity, Bundle data) - { - System.Diagnostics.Debug.WriteLine("OnProvideAssistData"); - } - } + //public class AndroidListener : Java.Lang.Object, Application.IOnProvideAssistDataListener + //{ + // public void OnProvideAssistData(Android.App.Activity activity, Bundle data) + // { + // System.Diagnostics.Debug.WriteLine("OnProvideAssistData"); + // } + //} } diff --git a/AideDeJeu/AideDeJeu/App.xaml.cs b/AideDeJeu/AideDeJeu/App.xaml.cs index b6d58faa..2bd5578a 100644 --- a/AideDeJeu/AideDeJeu/App.xaml.cs +++ b/AideDeJeu/AideDeJeu/App.xaml.cs @@ -40,7 +40,7 @@ namespace AideDeJeu //mainNavigationPage.Navigation.PushAsync(new MainPage()); if (search != null) { - Shell.Current.Navigation.PushAsync(new Views.Library.DeepSearchPage()); + Shell.Current.Navigation.PushAsync(new Views.Library.DeepSearchPage(), true); } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/Library/ItemViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/Library/ItemViewModel.cs index 907ce5e8..695d1a50 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Library/ItemViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Library/ItemViewModel.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; @@ -158,5 +159,50 @@ namespace AideDeJeu.ViewModels.Library await LoadItemsAsync(cancellationTokenSource.Token); } + + public async Task LoadPageAsync(string path) + { + var regex = new Regex("/?(?.*?)(_with_(?.*))?\\.md(#(?.*))?"); + var match = regex.Match(Uri.UnescapeDataString(path)); + var file = match.Groups["file"].Value; + var anchor = match.Groups["anchor"].Value; + var with = match.Groups["with"].Value; + Item item = null; + try + { + Main.IsBusy = true; + Main.IsLoading = true; + item = await Task.Run(async () => await Main.Store.GetItemFromDataAsync(file, anchor)); + + if (item != null) + { + var filterViewModel = item.GetNewFilterViewModel(); + Item = item; + AllItems = item; + Filter = filterViewModel; + await ExecuteLoadItemsCommandAsync(); + if (!string.IsNullOrEmpty(with)) + { + var swith = with.Split('_'); + for (int i = 0; i < swith.Length / 2; i++) + { + var key = swith[i * 2 + 0]; + var val = swith[i * 2 + 1]; + filterViewModel.FilterWith(key, val); + } + } + } + else + { + //await App.Current.MainPage.DisplayAlert("Lien invalide", s, "OK"); + } + } + finally + { + Main.IsBusy = false; + Main.IsLoading = false; + } + } + } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs index 73ec6e3c..82b78e82 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs @@ -342,7 +342,7 @@ namespace AideDeJeu.ViewModels }; // Push the page to Navigation Stack - await PopupNavigation.Instance.PushAsync(popup); + await PopupNavigation.Instance.PushAsync(popup, true); // await for the user to enter the text input var result = await popup.PageClosedTask; diff --git a/AideDeJeu/AideDeJeu/Views/Library/ItemPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/Library/ItemPage.xaml.cs index e244c644..ece50a62 100644 --- a/AideDeJeu/AideDeJeu/Views/Library/ItemPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/Library/ItemPage.xaml.cs @@ -28,7 +28,7 @@ namespace AideDeJeu.Views.Library } } - private ItemViewModel _Item = null; + private ItemViewModel _Item = new ItemViewModel(); public ItemViewModel Item { get @@ -71,7 +71,10 @@ namespace AideDeJeu.Views.Library set { _Path = value; - LoadPageAsync(); + if (Path != null) + { + Item?.LoadPageAsync(Path); + } } } diff --git a/AideDeJeu/AideDeJeu/Views/MainShell.xaml b/AideDeJeu/AideDeJeu/Views/MainShell.xaml index 9c8ca3c3..8e7a7cbe 100644 --- a/AideDeJeu/AideDeJeu/Views/MainShell.xaml +++ b/AideDeJeu/AideDeJeu/Views/MainShell.xaml @@ -29,19 +29,23 @@ - - + - - + + - - + + - - + + @@ -55,7 +59,7 @@ - + - + @@ -95,8 +99,8 @@ - - + + @@ -108,8 +112,8 @@ - - + + @@ -121,8 +125,8 @@ - - + + @@ -134,8 +138,8 @@ - - + + @@ -147,8 +151,8 @@ - - + + @@ -160,8 +164,8 @@ - - + + @@ -173,19 +177,19 @@ - - + + - - + + - + - + - + diff --git a/AideDeJeu/AideDeJeu/Views/MainShell.xaml.cs b/AideDeJeu/AideDeJeu/Views/MainShell.xaml.cs index d4e5defa..eb01bc94 100644 --- a/AideDeJeu/AideDeJeu/Views/MainShell.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/MainShell.xaml.cs @@ -48,13 +48,34 @@ namespace AideDeJeu.Views protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); - Debug.WriteLine(this.CurrentItem.CurrentItem.CurrentItem); - HeaderTitle = this.CurrentItem.CurrentItem.CurrentItem.Route; + Debug.WriteLine(this.CurrentItem?.CurrentItem?.CurrentItem); + HeaderTitle = this.CurrentItem?.CurrentItem?.CurrentItem?.Route; + var content = this.CurrentItem?.CurrentItem?.CurrentItem?.Content; + Debug.WriteLine(content); + + this.CurrentItem.CurrentItem.CurrentItem.PropertyChanged += CurrentItem_PropertyChanged; + this.CurrentItem.CurrentItem.CurrentItem.Appearing += CurrentItem_Appearing; + this.CurrentItem.CurrentItem.CurrentItem.BindingContextChanged += CurrentItem_BindingContextChanged; + } + + private void CurrentItem_BindingContextChanged(object sender, EventArgs e) + { + Debug.WriteLine(e.ToString()); + } + + private void CurrentItem_Appearing(object sender, EventArgs e) + { + Debug.WriteLine(e.ToString()); + } + + private void CurrentItem_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + Debug.WriteLine(e.PropertyName); } protected bool SetProperty(ref T backingStore, T value, - [CallerMemberName]string propertyName = "", - Action onChanged = null) + [CallerMemberName]string propertyName = "", + Action onChanged = null) { if (EqualityComparer.Default.Equals(backingStore, value)) return false;