1
0
Fork 0
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:
Yan Maniez 2018-07-08 23:36:40 +02:00
parent 615181650d
commit 77e2eff092
6 changed files with 96 additions and 45 deletions

View file

@ -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 ()

View 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";
}
}
}
}

View file

@ -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);
}
}
}

View file

@ -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());
}
}
}

View file

@ -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&amp;D)" MonsterVO="Monsters" MonsterHD="Créatures (H&amp;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&amp;D)" Text="Sorts (H&amp;D)" Order="Secondary" Command="{Binding SwitchToSpellsHD}" />
<ToolbarItem Name="Creatures (H&amp;D)" Text="Créatures (H&amp;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>

View file

@ -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;
}
}
}