mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 06:56:10 +00:00
Début refonte navigation
This commit is contained in:
parent
615181650d
commit
77e2eff092
6 changed files with 96 additions and 45 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeu.Views;
|
||||
using AideDeJeuLib.Models;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
|
|
@ -16,9 +17,10 @@ namespace AideDeJeu
|
|||
|
||||
DependencyService.Register<MainViewModel>();
|
||||
var vm = DependencyService.Get<MainViewModel>();
|
||||
var mainPage = new MainPage();
|
||||
vm.Navigator = new Navigator(mainPage.Detail.Navigation);
|
||||
MainPage = mainPage;
|
||||
var mainPage = new ItemDetailPage(new ItemDetailViewModel(new HomeItem()));// new MainPage();
|
||||
var navigationPage = new NavigationPage(mainPage);
|
||||
vm.Navigator = new Navigator(navigationPage.Navigation); //mainPage.Detail.Navigation);
|
||||
MainPage = navigationPage;
|
||||
}
|
||||
|
||||
protected override void OnStart ()
|
||||
|
|
|
|||
23
AideDeJeu/AideDeJeu/Models/HomeItem.cs
Normal file
23
AideDeJeu/AideDeJeu/Models/HomeItem.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AideDeJeuLib.Models
|
||||
{
|
||||
public class HomeItem : Item
|
||||
{
|
||||
public override string Markdown
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
"# [Sorts](spells_hd.md)\n\n" +
|
||||
"# [Créatures](monsters_hd.md)\n\n" +
|
||||
"# [Etats spéciaux](conditions_hd.md)\n\n" +
|
||||
"# [Spells](spells_vo.md)\n\n" +
|
||||
"# [Monsters](monsters_vo.md)\n\n" +
|
||||
"# [Conditions](conditions_vo.md)\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -195,17 +195,24 @@ namespace AideDeJeu.ViewModels
|
|||
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 itemSourceType = MDFileToItemSourceType(file);
|
||||
var spells = await GetItemsViewModel(itemSourceType).GetAllItemsAsync();
|
||||
var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault();
|
||||
if (spell != null)
|
||||
{
|
||||
if (s.Contains("#"))
|
||||
{
|
||||
await Navigator.GotoItemDetailPageAsync(spell);
|
||||
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 itemSourceType = MDFileToItemSourceType(file);
|
||||
var spells = await GetItemsViewModel(itemSourceType).GetAllItemsAsync();
|
||||
var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault();
|
||||
if (spell != null)
|
||||
{
|
||||
await Navigator.GotoItemDetailPageAsync(spell);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Navigator.GotoItemsPageAsync(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,15 @@ namespace AideDeJeu.ViewModels
|
|||
await Navigation.PushAsync(new ItemDetailPage(vm));
|
||||
}
|
||||
|
||||
public async Task GotoItemsPageAsync(Item item)
|
||||
{
|
||||
//if (item == null)
|
||||
// return;
|
||||
|
||||
//var vm = new ItemDetailViewModel(item);
|
||||
//vm.LoadItemCommand.Execute(null);
|
||||
await Navigation.PushAsync(new MainPage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:AideDeJeu.Views" xmlns:tools="clr-namespace:AideDeJeu.Tools" x:Class="AideDeJeu.Views.MainPage" x:Name="This" IsPresented="False" Title="">
|
||||
<MasterDetailPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:local="clr-namespace:AideDeJeu.Views"
|
||||
xmlns:tools="clr-namespace:AideDeJeu.Tools"
|
||||
x:Class="AideDeJeu.Views.MainPage"
|
||||
x:Name="This"
|
||||
IsPresented="False"
|
||||
Title="{Binding ItemSourceType,Converter={StaticResource ItemSourceTypeToTitleConverter}}">
|
||||
<MasterDetailPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<tools:ItemSourceTypeToStringConverter x:Key="ItemSourceTypeToTitleConverter" SpellVO="Spells" SpellHD="Sorts (H&D)" MonsterVO="Monsters" MonsterHD="Créatures (H&D)" />
|
||||
|
|
@ -31,37 +39,32 @@
|
|||
</ContentPage>
|
||||
</MasterDetailPage.Master>
|
||||
<MasterDetailPage.Detail>
|
||||
<NavigationPage>
|
||||
<x:Arguments>
|
||||
<ContentPage Title="{Binding ItemSourceType,Converter={StaticResource ItemSourceTypeToTitleConverter}}">
|
||||
<ContentPage.ToolbarItems>
|
||||
<!--<ToolbarItem Name="Sorts (H&D)" Text="Sorts (H&D)" Order="Secondary" Command="{Binding SwitchToSpellsHD}" />
|
||||
<ToolbarItem Name="Creatures (H&D)" Text="Créatures (H&D)" Order="Secondary" Command="{Binding SwitchToMonstersHD}" />
|
||||
<ToolbarItem Name="Spells (VO)" Text="Spells (VO)" Order="Secondary" Icon="spell_book.png" Command="{Binding SwitchToSpellsVO}" />
|
||||
<ToolbarItem Name="Monsters (VO)" Text="Monsters (VO)" Order="Secondary" Icon="dragon_head.png" Command="{Binding SwitchToMonstersVO}" />-->
|
||||
<ContentPage Title="">
|
||||
<!--<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill">
|
||||
<SearchBar x:Name="SearchBar" HeightRequest="42" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
|
||||
<SearchBar.Behaviors>
|
||||
<tools:TextChangedBehavior />
|
||||
</SearchBar.Behaviors>
|
||||
</SearchBar>
|
||||
<ListView x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout Padding="10" Orientation="Vertical">
|
||||
<Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" />
|
||||
<Label Text="{Binding NameVOText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
</x:Arguments>
|
||||
</NavigationPage>
|
||||
</ContentPage.ToolbarItems>-->
|
||||
<StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill">
|
||||
<StackLayout Orientation="Horizontal">
|
||||
<Button Text="=" Clicked="Button_Clicked"/>
|
||||
<SearchBar x:Name="SearchBar" HeightRequest="42" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
|
||||
<SearchBar.Behaviors>
|
||||
<tools:TextChangedBehavior />
|
||||
</SearchBar.Behaviors>
|
||||
</SearchBar>
|
||||
</StackLayout>
|
||||
<ListView x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout Padding="10" Orientation="Vertical">
|
||||
<Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" />
|
||||
<Label Text="{Binding NameVOText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
</MasterDetailPage.Detail>
|
||||
</MasterDetailPage>
|
||||
|
|
@ -35,6 +35,8 @@ namespace AideDeJeu.Views
|
|||
{
|
||||
base.OnAppearing();
|
||||
|
||||
this.MasterBehavior = MasterBehavior.Default;
|
||||
this.MasterBehavior = MasterBehavior.Popover;
|
||||
if (Main.Items.Count() == 0)
|
||||
Main.LoadItemsCommand.Execute(null);
|
||||
}
|
||||
|
|
@ -44,5 +46,10 @@ namespace AideDeJeu.Views
|
|||
if (e.Item == null) return;
|
||||
((ListView)sender).SelectedItem = null;
|
||||
}
|
||||
|
||||
private void Button_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.IsPresented = !this.IsPresented;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue