From 861b8c64d22948bed9cd8b5fb20a5c512f601d8a Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Tue, 18 Sep 2018 23:02:50 +0200 Subject: [PATCH] Remove / move --- .../ViewModels/BookmarksViewModel.cs | 61 ++++++++++++++++++- .../AideDeJeu/Views/BookmarksEditPage.xaml | 14 +++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs index a021885e..327f6a53 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs @@ -7,6 +7,8 @@ using System.Linq; using System.Runtime.Serialization.Json; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; +using Xamarin.Forms; using Xamarin.Forms.Internals; namespace AideDeJeu.ViewModels @@ -25,6 +27,7 @@ namespace AideDeJeu.ViewModels "Bestiaire", "Sac", }; + private int _BookmarkCollectionIndex = 0; public int BookmarkCollectionIndex { @@ -49,7 +52,63 @@ namespace AideDeJeu.ViewModels { SetProperty(ref _BookmarkCollection, value); } - } + } + + + private ICommand _RemoveItemCommand = null; + public ICommand RemoveItemCommand + { + get + { + return _RemoveItemCommand ?? (_RemoveItemCommand = new Command(ExecuteRemoveItemCommand)); + } + } + + private void ExecuteRemoveItemCommand(Item item) + { + BookmarkCollection.Remove(item); + } + + private ICommand _MoveUpItemCommand = null; + public ICommand MoveUpItemCommand + { + get + { + return _MoveUpItemCommand ?? (_MoveUpItemCommand = new Command(ExecuteMoveUpItemCommand)); + } + } + + private void ExecuteMoveUpItemCommand(Item item) + { + var index = BookmarkCollection.IndexOf(item); + if (index > 0) + { + BookmarkCollection.RemoveAt(index); + BookmarkCollection.Insert(index - 1, item); + } + } + + private ICommand _MoveDownItemCommand = null; + public ICommand MoveDownItemCommand + { + get + { + return _MoveDownItemCommand ?? (_MoveDownItemCommand = new Command(ExecuteMoveDownItemCommand)); + } + } + + private void ExecuteMoveDownItemCommand(Item item) + { + var index = BookmarkCollection.IndexOf(item); + if (index < BookmarkCollection.Count - 1) + { + BookmarkCollection.RemoveAt(index); + BookmarkCollection.Insert(index + 1, item); + } + } + + + public async Task> GetBookmarkCollection(string key) { diff --git a/AideDeJeu/AideDeJeu/Views/BookmarksEditPage.xaml b/AideDeJeu/AideDeJeu/Views/BookmarksEditPage.xaml index 2990d9cb..6e363bc4 100644 --- a/AideDeJeu/AideDeJeu/Views/BookmarksEditPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/BookmarksEditPage.xaml @@ -22,17 +22,21 @@ - + - + + + + +