1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Sync current page avec shell

This commit is contained in:
Yan Maniez 2019-10-01 16:27:44 +02:00
parent 1ecf4afdc6
commit 2ebe1c2b25
5 changed files with 88 additions and 53 deletions

View file

@ -21,6 +21,7 @@ namespace AideDeJeu.ViewModels.Library
set set
{ {
SetProperty(ref _Item, value); SetProperty(ref _Item, value);
Title = _Item?.Name;
} }
} }

View file

@ -213,5 +213,18 @@ namespace AideDeJeu.ViewModels
public MainViewModel() public MainViewModel()
{ {
} }
private Library.ItemViewModel _CurrentItem = null;
public Library.ItemViewModel CurrentItem
{
get
{
return _CurrentItem;
}
set
{
SetProperty(ref _CurrentItem, value);
}
}
} }
} }

View file

@ -61,6 +61,17 @@ namespace AideDeJeu.Views.Library
// LoadPageAsync(); // LoadPageAsync();
//} //}
protected override void OnAppearing()
{
base.OnAppearing();
Main.CurrentItem = Item;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
Main.CurrentItem = null;
}
private string _Path { get; set; } = null; //"index.md"; private string _Path { get; set; } = null; //"index.md";
public string Path public string Path
{ {
@ -78,59 +89,59 @@ namespace AideDeJeu.Views.Library
} }
} }
private async Task LoadPageAsync() //private async Task LoadPageAsync()
{ //{
if (Path == null) return; // if (Path == null) return;
var regex = new Regex("/?(?<file>.*?)(_with_(?<with>.*))?\\.md(#(?<anchor>.*))?"); // var regex = new Regex("/?(?<file>.*?)(_with_(?<with>.*))?\\.md(#(?<anchor>.*))?");
var match = regex.Match(Uri.UnescapeDataString(Path)); // var match = regex.Match(Uri.UnescapeDataString(Path));
var file = match.Groups["file"].Value; // var file = match.Groups["file"].Value;
var anchor = match.Groups["anchor"].Value; // var anchor = match.Groups["anchor"].Value;
var with = match.Groups["with"].Value; // var with = match.Groups["with"].Value;
Item item = null; // Item item = null;
try // try
{ // {
Main.IsBusy = true; // Main.IsBusy = true;
Main.IsLoading = true; // Main.IsLoading = true;
item = await Task.Run(async () => await Main.Store.GetItemFromDataAsync(file, anchor)); // item = await Task.Run(async () => await Main.Store.GetItemFromDataAsync(file, anchor));
} // }
finally // finally
{ // {
Main.IsBusy = false; // Main.IsBusy = false;
Main.IsLoading = false; // Main.IsLoading = false;
} // }
if (item != null) // if (item != null)
{ // {
var items = item; // as Items; // var items = item; // as Items;
var filterViewModel = items.GetNewFilterViewModel(); // var filterViewModel = items.GetNewFilterViewModel();
var itemsViewModel = new ItemViewModel() { Item = items, AllItems = items, Filter = filterViewModel }; // var itemsViewModel = new ItemViewModel() { Item = items, AllItems = items, Filter = filterViewModel };
this.Item = itemsViewModel; // this.Item = itemsViewModel;
itemsViewModel.LoadItemsCommand.Execute(null); // itemsViewModel.LoadItemsCommand.Execute(null);
if (!string.IsNullOrEmpty(with)) // if (!string.IsNullOrEmpty(with))
{ // {
var swith = with.Split('_'); // var swith = with.Split('_');
for (int i = 0; i < swith.Length / 2; i++) // for (int i = 0; i < swith.Length / 2; i++)
{ // {
var key = swith[i * 2 + 0]; // var key = swith[i * 2 + 0];
var val = swith[i * 2 + 1]; // var val = swith[i * 2 + 1];
filterViewModel.FilterWith(key, val); // filterViewModel.FilterWith(key, val);
} // }
} // }
//SwitchToMainTab(); // //SwitchToMainTab();
//if (filterViewModel == null) // //if (filterViewModel == null)
//{ // //{
// await GotoItemsPageAsync(itemsViewModel); // // await GotoItemsPageAsync(itemsViewModel);
//} // //}
//else // //else
//{ // //{
// await GotoFilteredItemsPageAsync(itemsViewModel); // // await GotoFilteredItemsPageAsync(itemsViewModel);
//} // //}
} // }
else // else
{ // {
//await App.Current.MainPage.DisplayAlert("Lien invalide", s, "OK"); // //await App.Current.MainPage.DisplayAlert("Lien invalide", s, "OK");
} // }
} //}
private void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e) private void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e)
{ {

View file

@ -33,6 +33,7 @@
<Label Text="{Binding HeaderTitle}" /> <Label Text="{Binding HeaderTitle}" />
<Label Text="{Binding CurrentItem.CurrentItem.CurrentItem.Route}" /> <Label Text="{Binding CurrentItem.CurrentItem.CurrentItem.Route}" />
<Label Text="{Binding CurrentItem.CurrentItem.CurrentItem.Content.BindingContext.Item.Title}" /> <Label Text="{Binding CurrentItem.CurrentItem.CurrentItem.Content.BindingContext.Item.Title}" />
<Label Text="{Binding Main.CurrentItem.Item.Name}" />
</StackLayout> </StackLayout>
</Shell.FlyoutHeader> </Shell.FlyoutHeader>

View file

@ -1,4 +1,5 @@
using System; using AideDeJeu.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
@ -21,6 +22,14 @@ namespace AideDeJeu.Views
BindingContext = this; BindingContext = this;
} }
public MainViewModel Main
{
get
{
return DependencyService.Get<MainViewModel>();
}
}
public ICommand ShellNavigateCommand public ICommand ShellNavigateCommand
{ {
get get