mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +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 System; | ||||||
| using AideDeJeu.ViewModels; | using AideDeJeu.ViewModels; | ||||||
| using AideDeJeu.Views; | using AideDeJeu.Views; | ||||||
|  | using AideDeJeuLib.Models; | ||||||
| using Xamarin.Forms; | using Xamarin.Forms; | ||||||
| using Xamarin.Forms.Xaml; | using Xamarin.Forms.Xaml; | ||||||
| 
 | 
 | ||||||
|  | @ -16,9 +17,10 @@ namespace AideDeJeu | ||||||
| 
 | 
 | ||||||
|             DependencyService.Register<MainViewModel>(); |             DependencyService.Register<MainViewModel>(); | ||||||
|             var vm = DependencyService.Get<MainViewModel>(); |             var vm = DependencyService.Get<MainViewModel>(); | ||||||
|             var mainPage = new MainPage(); |             var mainPage = new ItemDetailPage(new ItemDetailViewModel(new HomeItem()));// new MainPage(); | ||||||
|             vm.Navigator = new Navigator(mainPage.Detail.Navigation); |             var navigationPage = new NavigationPage(mainPage); | ||||||
|             MainPage = mainPage; |             vm.Navigator = new Navigator(navigationPage.Navigation); //mainPage.Detail.Navigation); | ||||||
|  |             MainPage = navigationPage; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         protected override void OnStart () |         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) |         public async Task NavigateToLink(string s) | ||||||
|         { |         { | ||||||
|             if (s != null) |             if (s != null) | ||||||
|             {  |             { | ||||||
|                 var regex = new Regex("/(?<file>.*)\\.md#(?<anchor>.*)"); |                 if (s.Contains("#")) | ||||||
|                 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); |                     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)); |             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"?> | <?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> |     <MasterDetailPage.Resources> | ||||||
|         <ResourceDictionary> |         <ResourceDictionary> | ||||||
|             <tools:ItemSourceTypeToStringConverter x:Key="ItemSourceTypeToTitleConverter" SpellVO="Spells" SpellHD="Sorts (H&D)" MonsterVO="Monsters" MonsterHD="Créatures (H&D)" /> |             <tools:ItemSourceTypeToStringConverter x:Key="ItemSourceTypeToTitleConverter" SpellVO="Spells" SpellHD="Sorts (H&D)" MonsterVO="Monsters" MonsterHD="Créatures (H&D)" /> | ||||||
|  | @ -31,37 +39,32 @@ | ||||||
|         </ContentPage> |         </ContentPage> | ||||||
|     </MasterDetailPage.Master> |     </MasterDetailPage.Master> | ||||||
|     <MasterDetailPage.Detail> |     <MasterDetailPage.Detail> | ||||||
|         <NavigationPage> |         <ContentPage Title=""> | ||||||
|             <x:Arguments> |             <!--<ContentPage.ToolbarItems> | ||||||
|                 <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}" />--> |  | ||||||
|                         <ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" /> |                         <ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" /> | ||||||
|                     </ContentPage.ToolbarItems> |                     </ContentPage.ToolbarItems>--> | ||||||
|                     <StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill"> |             <StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill"> | ||||||
|                         <SearchBar x:Name="SearchBar" HeightRequest="42" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}"> |                 <StackLayout Orientation="Horizontal"> | ||||||
|                             <SearchBar.Behaviors> |                     <Button Text="=" Clicked="Button_Clicked"/> | ||||||
|                                 <tools:TextChangedBehavior /> |                     <SearchBar x:Name="SearchBar" HeightRequest="42" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}"> | ||||||
|                             </SearchBar.Behaviors> |                         <SearchBar.Behaviors> | ||||||
|                         </SearchBar> |                             <tools:TextChangedBehavior /> | ||||||
|                         <ListView x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> |                         </SearchBar.Behaviors> | ||||||
|                             <ListView.ItemTemplate> |                     </SearchBar> | ||||||
|                                 <DataTemplate> |                 </StackLayout> | ||||||
|                                     <ViewCell> |                 <ListView x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> | ||||||
|                                         <StackLayout Padding="10" Orientation="Vertical"> |                     <ListView.ItemTemplate> | ||||||
|                                             <Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" /> |                         <DataTemplate> | ||||||
|                                             <Label Text="{Binding NameVOText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" /> |                             <ViewCell> | ||||||
|                                         </StackLayout> |                                 <StackLayout Padding="10" Orientation="Vertical"> | ||||||
|                                     </ViewCell> |                                     <Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="16" /> | ||||||
|                                 </DataTemplate> |                                     <Label Text="{Binding NameVOText}" LineBreakMode="NoWrap" Style="{DynamicResource subsubsection}" FontSize="12" /> | ||||||
|                             </ListView.ItemTemplate> |                                 </StackLayout> | ||||||
|                         </ListView> |                             </ViewCell> | ||||||
|                     </StackLayout> |                         </DataTemplate> | ||||||
|                 </ContentPage> |                     </ListView.ItemTemplate> | ||||||
|             </x:Arguments> |                 </ListView> | ||||||
|         </NavigationPage> |             </StackLayout> | ||||||
|  |         </ContentPage> | ||||||
|     </MasterDetailPage.Detail> |     </MasterDetailPage.Detail> | ||||||
| </MasterDetailPage> | </MasterDetailPage> | ||||||
|  | @ -35,6 +35,8 @@ namespace AideDeJeu.Views | ||||||
|         { |         { | ||||||
|             base.OnAppearing(); |             base.OnAppearing(); | ||||||
| 
 | 
 | ||||||
|  |             this.MasterBehavior = MasterBehavior.Default; | ||||||
|  |             this.MasterBehavior = MasterBehavior.Popover; | ||||||
|             if (Main.Items.Count() == 0) |             if (Main.Items.Count() == 0) | ||||||
|                 Main.LoadItemsCommand.Execute(null); |                 Main.LoadItemsCommand.Execute(null); | ||||||
|         } |         } | ||||||
|  | @ -44,5 +46,10 @@ namespace AideDeJeu.Views | ||||||
|             if (e.Item == null) return; |             if (e.Item == null) return; | ||||||
|             ((ListView)sender).SelectedItem = null; |             ((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
	
	 Yan Maniez
						Yan Maniez