mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 22:45:44 +00:00
Déplacement navigate
This commit is contained in:
parent
bc8096ce4d
commit
4b037da1e9
4 changed files with 54 additions and 58 deletions
|
|
@ -68,7 +68,7 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
if (_SelectedItem is LinkItem)
|
||||
{
|
||||
Main.NavigateToLink("/" + (_SelectedItem as LinkItem).Link);
|
||||
Main.Navigator.NavigateToLink("/" + (_SelectedItem as LinkItem).Link);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,13 +38,6 @@ namespace AideDeJeu.ViewModels
|
|||
return _AllItems[source];
|
||||
}
|
||||
|
||||
//public async Task<ItemsViewModel> GetItemsViewModelAsync(string source)
|
||||
//{
|
||||
// var itemsViewModel = new ItemsViewModel();
|
||||
// itemsViewModel.AllItems = await GetAllItemsAsync(source);
|
||||
// return itemsViewModel;
|
||||
//}
|
||||
|
||||
public Command LoadItemsCommand { get; private set; }
|
||||
public Command AboutCommand { get; private set; }
|
||||
|
||||
|
|
@ -54,53 +47,5 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
AboutCommand = new Command(async () => await Main.Navigator.GotoAboutPageAsync());
|
||||
}
|
||||
|
||||
public async Task NavigateToLink(string s)
|
||||
{
|
||||
if (s != null)
|
||||
{
|
||||
var regex = new Regex("/(?<file>.*)\\.md(#(?<anchor>.*))?");
|
||||
var match = regex.Match(s);
|
||||
var file = match.Groups["file"].Value;
|
||||
var anchor = match.Groups["anchor"].Value;
|
||||
var item = await GetItemFromDataAsync(file);
|
||||
if (item != null)
|
||||
{
|
||||
if (item is Items)
|
||||
{
|
||||
var items = item as Items;
|
||||
if (!string.IsNullOrEmpty(anchor))
|
||||
{
|
||||
var subitem = items.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault();
|
||||
if (subitem != null)
|
||||
{
|
||||
await Navigator.GotoItemDetailPageAsync(subitem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var itemsViewModel = new ItemsViewModel() { AllItems = items };
|
||||
itemsViewModel.LoadItemsCommand.Execute(null);
|
||||
if (items.GetNewFilterViewModel() == null)
|
||||
{
|
||||
await Navigator.GotoItemsPageAsync(itemsViewModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Navigator.GotoFilteredItemsPageAsync(itemsViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Navigator.GotoItemDetailPageAsync(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await App.Current.MainPage.DisplayAlert("Lien invalide", s, "OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
using AideDeJeu.Views;
|
||||
using AideDeJeuLib;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
|
|
@ -11,7 +13,7 @@ namespace AideDeJeu.ViewModels
|
|||
Task GotoAboutPageAsync();
|
||||
Task GotoItemDetailPageAsync(Item item);
|
||||
}
|
||||
public class Navigator : INavigator
|
||||
public class Navigator : BaseViewModel, INavigator
|
||||
{
|
||||
INavigation Navigation;
|
||||
|
||||
|
|
@ -50,5 +52,54 @@ namespace AideDeJeu.ViewModels
|
|||
await Navigation.PushAsync(new FilteredItemsPage(itemsVM));
|
||||
}
|
||||
|
||||
|
||||
public async Task NavigateToLink(string s)
|
||||
{
|
||||
if (s != null)
|
||||
{
|
||||
var regex = new Regex("/(?<file>.*)\\.md(#(?<anchor>.*))?");
|
||||
var match = regex.Match(s);
|
||||
var file = match.Groups["file"].Value;
|
||||
var anchor = match.Groups["anchor"].Value;
|
||||
var item = await Main.GetItemFromDataAsync(file);
|
||||
if (item != null)
|
||||
{
|
||||
if (item is Items)
|
||||
{
|
||||
var items = item as Items;
|
||||
if (!string.IsNullOrEmpty(anchor))
|
||||
{
|
||||
var subitem = items.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault();
|
||||
if (subitem != null)
|
||||
{
|
||||
await GotoItemDetailPageAsync(subitem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var itemsViewModel = new ItemsViewModel() { AllItems = items };
|
||||
itemsViewModel.LoadItemsCommand.Execute(null);
|
||||
if (items.GetNewFilterViewModel() == null)
|
||||
{
|
||||
await GotoItemsPageAsync(itemsViewModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
await GotoFilteredItemsPageAsync(itemsViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await GotoItemDetailPageAsync(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await App.Current.MainPage.DisplayAlert("Lien invalide", s, "OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace AideDeJeu.Views
|
|||
|
||||
BindingContext = this.viewModel = itemVM;
|
||||
|
||||
mdMarkdown.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s);
|
||||
mdMarkdown.NavigateToLink = async (s) => await viewModel.Main.Navigator.NavigateToLink(s);
|
||||
}
|
||||
|
||||
public ItemDetailPage()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue