mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +00:00 
			
		
		
		
	Suite bookmarks
This commit is contained in:
		
							parent
							
								
									d040f11a81
								
							
						
					
					
						commit
						a2d1019916
					
				
					 5 changed files with 69 additions and 42 deletions
				
			
		|  | @ -9,18 +9,6 @@ namespace AideDeJeuLib | ||||||
|     [DataContract] |     [DataContract] | ||||||
|     public class HomeItem : Item |     public class HomeItem : Item | ||||||
|     { |     { | ||||||
|         [DataMember] |  | ||||||
|         public override string Id |  | ||||||
|         { |  | ||||||
|             get |  | ||||||
|             { |  | ||||||
|                 return "index.md"; |  | ||||||
|             } |  | ||||||
|             set |  | ||||||
|             { |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         [DataMember] |         [DataMember] | ||||||
|         public override string Markdown |         public override string Markdown | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -1,49 +1,90 @@ | ||||||
| using AideDeJeuLib; | using AideDeJeuLib; | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
|  | using System.Collections.ObjectModel; | ||||||
| using System.IO; | using System.IO; | ||||||
| using System.Runtime.Serialization.Json; | using System.Runtime.Serialization.Json; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
|  | using Xamarin.Forms.Internals; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeu.ViewModels | namespace AideDeJeu.ViewModels | ||||||
| { | { | ||||||
|     public class BookmarksViewModel //: BaseViewModel |     public class BookmarksViewModel : BaseViewModel | ||||||
|     { |     { | ||||||
|         public BookmarksViewModel() |         public BookmarksViewModel() | ||||||
|         { |         { | ||||||
|             LoadBookmarks(); |             LoadBookmarkCollection(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public List<KeyValuePair<string, List<Item>>> BookmarksKeyValues { get; set; } = new List<KeyValuePair<string, List<Item>>>() |         public ObservableCollection<string> BookmarkCollectionNames { get; set; } = new ObservableCollection<string>() | ||||||
|         { |         { | ||||||
|             new KeyValuePair<string, List<Item>>("Général", new List<Item>()), |             "Général", | ||||||
|             new KeyValuePair<string, List<Item>>("Grimoire", new List<Item>()), |             "Grimoire", | ||||||
|             new KeyValuePair<string, List<Item>>("Bestiaire", new List<Item>()), |             "Bestiaire", | ||||||
|             new KeyValuePair<string, List<Item>>("Sac", new List<Item>()), |             "Sac", | ||||||
|         }; |         }; | ||||||
|         public int BookmarksIndex { get; set; } = 0; |         private int _BookmarkCollectionIndex = 0; | ||||||
|         public List<Item> Bookmarks { get; set; } |         public int BookmarkCollectionIndex | ||||||
|         public int BookmarksCount { get; set; } = 0; |  | ||||||
| 
 |  | ||||||
|         public void LoadBookmarks() |  | ||||||
|         { |         { | ||||||
|             foreach(var key in App.Current.Properties.Keys) |             get | ||||||
|  |             { | ||||||
|  |                 return _BookmarkCollectionIndex; | ||||||
|  |             } | ||||||
|  |             set | ||||||
|  |             { | ||||||
|  |                 SetProperty(ref _BookmarkCollectionIndex, value); | ||||||
|  |                 LoadBookmarkCollection(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         private ObservableCollection<Item> _BookmarkCollection = new ObservableCollection<Item>(); | ||||||
|  |         public ObservableCollection<Item> BookmarkCollection | ||||||
|  |         { | ||||||
|  |             get | ||||||
|  |             { | ||||||
|  |                 return _BookmarkCollection; | ||||||
|  |             } | ||||||
|  |             set | ||||||
|  |             { | ||||||
|  |                 SetProperty(ref _BookmarkCollection, value); | ||||||
|  |             } | ||||||
|  |         }  | ||||||
|  | 
 | ||||||
|  |         public List<Item> GetBookmarkCollection(string key) | ||||||
|         { |         { | ||||||
|             var property = App.Current.Properties[key] as string; |             var property = App.Current.Properties[key] as string; | ||||||
|             if (property != null) |             if (property != null) | ||||||
|             { |             { | ||||||
|                     BookmarksKeyValues.Add(new KeyValuePair<string, List<Item>>(key, ToItems(property))); |                 return ToItems(property); | ||||||
|             } |             } | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |         public void LoadBookmarkCollection() | ||||||
|  |         { | ||||||
|  |             var items = GetBookmarkCollection(BookmarkCollectionNames[BookmarkCollectionIndex]); | ||||||
|  |             BookmarkCollection.Clear(); | ||||||
|  |             if (items != null) | ||||||
|  |             { | ||||||
|  |                 items.ForEach(item => BookmarkCollection.Add(item)); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public async Task SaveBookmarksAsync() |         public async Task AddBookmarkAsync(string key, Item item) | ||||||
|         { |         { | ||||||
|             foreach(var keyValues in BookmarksKeyValues) |             var linkItem = new LinkItem() { Name = item.Name, AltName = item.AltName, Link = item.Id }; | ||||||
|  |             var items = GetBookmarkCollection(key); | ||||||
|  |             if(items == null) | ||||||
|             { |             { | ||||||
|                 App.Current.Properties[keyValues.Key] = ToString(keyValues.Value); |                 items = new List<Item>(); | ||||||
|             } |             } | ||||||
|  |             items.Add(linkItem); | ||||||
|  |             await SaveBookmarksAsync(key, items); | ||||||
|  |             LoadBookmarkCollection(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public async Task SaveBookmarksAsync(string key, List<Item> items) | ||||||
|  |         { | ||||||
|  |             App.Current.Properties[key] = ToString(items); | ||||||
|             await App.Current.SavePropertiesAsync(); |             await App.Current.SavePropertiesAsync(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -77,10 +77,8 @@ namespace AideDeJeu.ViewModels | ||||||
|             } |             } | ||||||
|             //await Application.Current.MainPage.DisplayAlert("Id", item.Id, "OK"); |             //await Application.Current.MainPage.DisplayAlert("Id", item.Id, "OK"); | ||||||
|             var vm = Main.Bookmarks; |             var vm = Main.Bookmarks; | ||||||
|             var result = await Application.Current.MainPage.DisplayActionSheet("Ajouter à", "Annuler", "Nouvelle liste", vm.BookmarksKeyValues.Select(kv => kv.Key).ToArray()); |             var result = await Application.Current.MainPage.DisplayActionSheet("Ajouter à", "Annuler", "Nouvelle liste", vm.BookmarkCollectionNames.ToArray<string>()); | ||||||
|             var kval = vm.BookmarksKeyValues.FirstOrDefault(kv => kv.Key == result); |             await vm.AddBookmarkAsync(result, item); | ||||||
|             kval.Value.Add(item); |  | ||||||
|             await vm.SaveBookmarksAsync(); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public async Task GotoItemDetailPageAsync(Item item) |         public async Task GotoItemDetailPageAsync(Item item) | ||||||
|  |  | ||||||
|  | @ -16,17 +16,17 @@ | ||||||
|                 <RowDefinition Height="*" /> |                 <RowDefinition Height="*" /> | ||||||
|             </Grid.RowDefinitions> |             </Grid.RowDefinitions> | ||||||
|              |              | ||||||
|             <Picker Style="{StaticResource heading1}" HorizontalOptions="FillAndExpand" ItemsSource="{Binding BookmarksKeyValues, Mode=OneWay}" ItemDisplayBinding="{Binding Key, Mode=OneWay}" SelectedIndex="{Binding BookmarksIndex, Mode=TwoWay}" /> |             <Picker Style="{StaticResource heading1}" HorizontalOptions="FillAndExpand" ItemsSource="{Binding BookmarkCollectionNames, Mode=OneWay}" ItemDisplayBinding="{Binding Mode=OneWay}" SelectedIndex="{Binding BookmarkCollectionIndex, Mode=TwoWay}" /> | ||||||
| 
 | 
 | ||||||
|             <Label Grid.Column="0" Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Margin="15,0,15,0" Style="{StaticResource subsubsection}" Text="Cette liste est vide, ajoutez des éléments à partir de la bibliothèque !" IsVisible="{Binding Bookmarks.Count, Converter={StaticResource IntToBooleanConverter}}" /> |             <Label Grid.Column="0" Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Margin="15,0,15,0" Style="{StaticResource subsubsection}" Text="Cette liste est vide, ajoutez des éléments à partir de la bibliothèque !" IsVisible="{Binding BookmarkCollection.Count, Converter={StaticResource IntToBooleanConverter}}" /> | ||||||
| 
 | 
 | ||||||
|             <ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding Bookmarks}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}"> |             <ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}"> | ||||||
|                 <ListView.ItemTemplate> |                 <ListView.ItemTemplate> | ||||||
|                     <DataTemplate> |                     <DataTemplate> | ||||||
|                         <ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop"> |                         <ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop"> | ||||||
|                             <StackLayout Padding="10" Orientation="Vertical"> |                             <StackLayout Padding="10" Orientation="Vertical"> | ||||||
|                                 <Label Text="{Binding Name}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="16" /> |                                 <Label Text="{Binding Name}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="16" /> | ||||||
|                                 <Label Text="{Binding AltNameText}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="12" /> |                                 <Label Text="{Binding Id}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="12" /> | ||||||
|                             </StackLayout> |                             </StackLayout> | ||||||
|                         </ViewCell> |                         </ViewCell> | ||||||
|                     </DataTemplate> |                     </DataTemplate> | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ namespace AideDeJeu.Views | ||||||
|         { |         { | ||||||
|             InitializeComponent(); |             InitializeComponent(); | ||||||
| 
 | 
 | ||||||
|             BindingContext = this.viewModel = new ItemDetailViewModel(new HomeItem()) { Title = "Bibliothèque" }; |             BindingContext = this.viewModel = new ItemDetailViewModel(new HomeItem() { Name = "Bibliothèque", Id = "index.md" }) { Title = "Bibliothèque" }; | ||||||
|             //var item = new Item |             //var item = new Item | ||||||
|             //{ |             //{ | ||||||
|             //    Name = "", |             //    Name = "", | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez