diff --git a/AideDeJeu/AideDeJeu.Android/MainActivity.cs b/AideDeJeu/AideDeJeu.Android/MainActivity.cs index e6ef28b5..dc98b3e0 100644 --- a/AideDeJeu/AideDeJeu.Android/MainActivity.cs +++ b/AideDeJeu/AideDeJeu.Android/MainActivity.cs @@ -31,7 +31,7 @@ namespace AideDeJeu.Droid if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed)) { // Do something if there are some pages in the `PopupStack` - Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAsync(); + //Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAsync(); } else { diff --git a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs index 55b02e94..92df97cb 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs @@ -73,7 +73,7 @@ namespace AideDeJeu.ViewModels } else if(BookmarkCollectionIndex == BookmarkCollectionNames.Count - 1) { - await Main.Navigator.OpenCancellableTextInputAlertDialog(""); + var result = await Main.Navigator.OpenCancellableTextInputAlertDialog(""); } } @@ -159,7 +159,11 @@ namespace AideDeJeu.ViewModels private async Task ExecuteConfigureCommand() { - await Main.Navigator.OpenCancellableTextInputAlertDialog(BookmarkCollectionNames[BookmarkCollectionIndex]); + var result = await Main.Navigator.OpenCancellableTextInputAlertDialog(BookmarkCollectionNames[BookmarkCollectionIndex]); + if (result.Item2 == Navigator.PopupResultEnum.Delete) + { + var confirm = await App.Current.MainPage.DisplayAlert("Supprimer ?", "Etes vous sûr de vouloir supprimer la liste ?", "Supprimer", "Annuler"); + } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs index 4df19e27..c539b09f 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs @@ -1,6 +1,7 @@ using AideDeJeu.Views; using AideDeJeuLib; using Rg.Plugins.Popup.Services; +using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -207,16 +208,21 @@ namespace AideDeJeu.ViewModels - - public async Task OpenCancellableTextInputAlertDialog(string inputText) + public enum PopupResultEnum + { + Save, + Cancel, + Delete + } + public async Task> OpenCancellableTextInputAlertDialog(string inputText) { // create the TextInputView var inputView = new TextInputCancellableView( - "Nom de la liste ?", "Nouveau nom...", inputText, "Enregistrer", "Annuler", "Le nom ne peut pas être vide."); + "Nom de la liste ?", "Nouveau nom...", inputText, "Enregistrer", "Annuler", "Supprimer", "Le nom ne peut pas être vide."); // create the Transparent Popup Page // of type string since we need a string return - var popup = new InputAlertDialogBase(inputView); + var popup = new InputAlertDialogBase>(inputView); // subscribe to the TextInputView's Button click event @@ -226,7 +232,7 @@ namespace AideDeJeu.ViewModels if (!string.IsNullOrEmpty(((TextInputCancellableView)sender).TextInputResult)) { ((TextInputCancellableView)sender).IsValidationLabelVisible = false; - popup.PageClosedTaskCompletionSource.SetResult(((TextInputCancellableView)sender).TextInputResult); + popup.PageClosedTaskCompletionSource.SetResult(new Tuple(((TextInputCancellableView)sender).TextInputResult, PopupResultEnum.Save)); } else { @@ -238,7 +244,13 @@ namespace AideDeJeu.ViewModels inputView.CancelButtonEventHandler += (sender, obj) => { - popup.PageClosedTaskCompletionSource.SetResult(null); + popup.PageClosedTaskCompletionSource.SetResult(new Tuple(null, PopupResultEnum.Cancel)); + }; + + inputView.DeleteButtonEventHandler += + (sender, obj) => + { + popup.PageClosedTaskCompletionSource.SetResult(new Tuple(null, PopupResultEnum.Delete)); }; // Push the page to Navigation Stack diff --git a/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml index b4461032..595d72ad 100644 --- a/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml +++ b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml @@ -23,8 +23,22 @@ + + diff --git a/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs index 382ba14d..8c6a26f4 100644 --- a/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs @@ -20,6 +20,8 @@ namespace AideDeJeu.Views // the Cancel button's click event public EventHandler CancelButtonEventHandler { get; set; } + public EventHandler DeleteButtonEventHandler { get; set; } + // public string to expose the // text Entry input's value public string TextInputResult { get; set; } @@ -60,21 +62,23 @@ namespace AideDeJeu.Views } public TextInputCancellableView(string titleText, string placeHolderText, string inputText, - string saveButtonText, string cancelButtonText, string validationText) + string saveButtonText, string cancelButtonText, string deleteButtonText, string validationText) { InitializeComponent(); // update the Element's textual values TitleLabel.Text = titleText; - InputEntry.Text = inputText; + TextInputResult = InputEntry.Text = inputText; InputEntry.Placeholder = placeHolderText; SaveButton.Text = saveButtonText; CancelButton.Text = cancelButtonText; + DeleteButton.Text = deleteButtonText; ValidationLabel.Text = validationText; // handling events to expose to public SaveButton.Clicked += SaveButton_Clicked; CancelButton.Clicked += CancelButton_Clicked; + DeleteButton.Clicked += DeleteButton_Clicked; InputEntry.TextChanged += InputEntry_TextChanged; } @@ -90,6 +94,12 @@ namespace AideDeJeu.Views CancelButtonEventHandler?.Invoke(this, e); } + private void DeleteButton_Clicked(object sender, EventArgs e) + { + // invoke the event handler if its being subscribed + DeleteButtonEventHandler?.Invoke(this, e); + } + private void InputEntry_TextChanged(object sender, TextChangedEventArgs e) {