1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Suite bookmarks

This commit is contained in:
Yan Maniez 2018-08-29 13:38:50 +02:00
parent d040f11a81
commit a2d1019916
5 changed files with 69 additions and 42 deletions

View file

@ -9,18 +9,6 @@ namespace AideDeJeuLib
[DataContract]
public class HomeItem : Item
{
[DataMember]
public override string Id
{
get
{
return "index.md";
}
set
{
}
}
[DataMember]
public override string Markdown
{

View file

@ -1,49 +1,90 @@
using AideDeJeuLib;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
namespace AideDeJeu.ViewModels
{
public class BookmarksViewModel //: BaseViewModel
public class BookmarksViewModel : BaseViewModel
{
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>()),
new KeyValuePair<string, List<Item>>("Grimoire", new List<Item>()),
new KeyValuePair<string, List<Item>>("Bestiaire", new List<Item>()),
new KeyValuePair<string, List<Item>>("Sac", new List<Item>()),
"Général",
"Grimoire",
"Bestiaire",
"Sac",
};
public int BookmarksIndex { get; set; } = 0;
public List<Item> Bookmarks { get; set; }
public int BookmarksCount { get; set; } = 0;
public void LoadBookmarks()
private int _BookmarkCollectionIndex = 0;
public int BookmarkCollectionIndex
{
foreach(var key in App.Current.Properties.Keys)
get
{
var property = App.Current.Properties[key] as string;
if(property != null)
{
BookmarksKeyValues.Add(new KeyValuePair<string, List<Item>>(key, ToItems(property)));
}
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;
if (property != null)
{
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();
}

View file

@ -77,10 +77,8 @@ namespace AideDeJeu.ViewModels
}
//await Application.Current.MainPage.DisplayAlert("Id", item.Id, "OK");
var vm = Main.Bookmarks;
var result = await Application.Current.MainPage.DisplayActionSheet("Ajouter à", "Annuler", "Nouvelle liste", vm.BookmarksKeyValues.Select(kv => kv.Key).ToArray());
var kval = vm.BookmarksKeyValues.FirstOrDefault(kv => kv.Key == result);
kval.Value.Add(item);
await vm.SaveBookmarksAsync();
var result = await Application.Current.MainPage.DisplayActionSheet("Ajouter à", "Annuler", "Nouvelle liste", vm.BookmarkCollectionNames.ToArray<string>());
await vm.AddBookmarkAsync(result, item);
}
public async Task GotoItemDetailPageAsync(Item item)

View file

@ -16,17 +16,17 @@
<RowDefinition Height="*" />
</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>
<DataTemplate>
<ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop">
<StackLayout Padding="10" Orientation="Vertical">
<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>
</ViewCell>
</DataTemplate>

View file

@ -35,7 +35,7 @@ namespace AideDeJeu.Views
{
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
//{
// Name = "",