mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-31 23:45:39 +00:00
Test bookmarks
This commit is contained in:
parent
fba3966ae9
commit
b5670b5614
6 changed files with 124 additions and 14 deletions
|
|
@ -15,6 +15,7 @@ namespace AideDeJeu
|
|||
InitializeComponent();
|
||||
|
||||
DependencyService.Register<MainViewModel>();
|
||||
DependencyService.Register<BookmarksViewModel>();
|
||||
var vm = DependencyService.Get<MainViewModel>();
|
||||
var tabbeddPage = new AideDeJeu.Views.MainTabbedPage();
|
||||
//var mainPage = new ItemDetailPage(new ItemDetailViewModel(new HomeItem()) { Title = "Haches & Dés" });
|
||||
|
|
|
|||
|
|
@ -1,13 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Markdig.Syntax;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
[DataContract]
|
||||
public class HomeItem : Item
|
||||
{
|
||||
public new string Markdown
|
||||
[DataMember]
|
||||
public override string Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return "index.md";
|
||||
}
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public override string Markdown
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,15 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
[DataContract]
|
||||
public class Item
|
||||
{
|
||||
public string Id { get; set; }
|
||||
[DataMember]
|
||||
public virtual string Id { get; set; }
|
||||
[DataMember]
|
||||
public string Name { get; set; }
|
||||
[DataMember]
|
||||
public int NameLevel { get; set; }
|
||||
[DataMember]
|
||||
public string AltName { get; set; }
|
||||
[IgnoreDataMember]
|
||||
public string AltNameText
|
||||
{
|
||||
get
|
||||
|
|
@ -32,7 +39,9 @@ namespace AideDeJeuLib
|
|||
}
|
||||
}
|
||||
}
|
||||
[DataMember]
|
||||
public string Source { get; set; }
|
||||
public string Markdown { get; set; }
|
||||
[DataMember]
|
||||
public virtual string Markdown { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@ namespace AideDeJeu.ViewModels
|
|||
return DependencyService.Get<MainViewModel>();
|
||||
}
|
||||
}
|
||||
public BookmarksViewModel Bookmarks
|
||||
{
|
||||
get
|
||||
{
|
||||
return DependencyService.Get<BookmarksViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
bool isBusy = false;
|
||||
public bool IsBusy
|
||||
|
|
|
|||
|
|
@ -1,21 +1,96 @@
|
|||
using AideDeJeuLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
{
|
||||
public class BookmarksViewModel : BaseViewModel
|
||||
public class BookmarksViewModel //: BaseViewModel
|
||||
{
|
||||
public List<KeyValuePair<string, IEnumerable<Item>>> BookmarksKeyValues { get; set; } = new List<KeyValuePair<string, IEnumerable<Item>>>()
|
||||
public BookmarksViewModel()
|
||||
{
|
||||
new KeyValuePair<string, IEnumerable<Item>>("Général", new List<Item>()),
|
||||
new KeyValuePair<string, IEnumerable<Item>>("Grimoire", new List<Item>()),
|
||||
new KeyValuePair<string, IEnumerable<Item>>("Bestiaire", new List<Item>()),
|
||||
new KeyValuePair<string, IEnumerable<Item>>("Sac", new List<Item>()),
|
||||
LoadBookmarks();
|
||||
}
|
||||
|
||||
public List<KeyValuePair<string, List<Item>>> BookmarksKeyValues { get; set; } = new List<KeyValuePair<string, List<Item>>>()
|
||||
{
|
||||
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>()),
|
||||
};
|
||||
public int BookmarksIndex { get; set; } = 0;
|
||||
public IEnumerable<Item> Bookmarks { get; set; }
|
||||
public List<Item> Bookmarks { get; set; }
|
||||
public int BookmarksCount { get; set; } = 0;
|
||||
|
||||
public void LoadBookmarks()
|
||||
{
|
||||
foreach(var key in App.Current.Properties.Keys)
|
||||
{
|
||||
var property = App.Current.Properties[key] as string;
|
||||
if(property != null)
|
||||
{
|
||||
BookmarksKeyValues.Add(new KeyValuePair<string, List<Item>>(key, ToItems(property)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveBookmarksAsync()
|
||||
{
|
||||
foreach(var keyValues in BookmarksKeyValues)
|
||||
{
|
||||
App.Current.Properties[keyValues.Key] = ToString(keyValues.Value);
|
||||
}
|
||||
await App.Current.SavePropertiesAsync();
|
||||
}
|
||||
|
||||
public string ToString(List<Item> items)
|
||||
{
|
||||
var serializer = ItemJsonSerializer;
|
||||
using(var stream = new MemoryStream())
|
||||
{
|
||||
serializer.WriteObject(stream, items);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Item> ToItems(string str)
|
||||
{
|
||||
var serializer = ItemJsonSerializer;
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(str);
|
||||
using (var stream = new MemoryStream(byteArray))
|
||||
{
|
||||
return serializer.ReadObject(stream) as List<Item>;
|
||||
}
|
||||
}
|
||||
|
||||
public DataContractJsonSerializer ItemJsonSerializer
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = new DataContractJsonSerializerSettings();
|
||||
settings.KnownTypes = new List<Type>()
|
||||
{
|
||||
typeof(HomeItem),
|
||||
typeof(Spell),
|
||||
typeof(Monster),
|
||||
//typeof(Items),
|
||||
typeof(LinkItem),
|
||||
typeof(Equipment),
|
||||
//typeof(Spells),
|
||||
//typeof(Monsters),
|
||||
//typeof(Equipments),
|
||||
typeof(PageItem),
|
||||
};
|
||||
return new DataContractJsonSerializer(typeof(List<Item>), settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,11 +73,14 @@ namespace AideDeJeu.ViewModels
|
|||
}
|
||||
else if(context is ItemsViewModel)
|
||||
{
|
||||
item = (context as ItemsViewModel).Items;
|
||||
item = (context as ItemsViewModel).AllItems;
|
||||
}
|
||||
await Application.Current.MainPage.DisplayAlert("Id", item.Id, "OK");
|
||||
var vm = new BookmarksViewModel();
|
||||
await Application.Current.MainPage.DisplayActionSheet("Ajouter à", "Annuler", "Nouvelle liste", vm.BookmarksKeyValues.Select(kv => kv.Key).ToArray());
|
||||
//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();
|
||||
}
|
||||
|
||||
public async Task GotoItemDetailPageAsync(Item item)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue