1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-11-01 16:05:42 +00:00

Popup 3 boutons

This commit is contained in:
Yan Maniez 2018-09-26 13:58:30 +02:00
parent e8852bb569
commit 1ad8da9fd3
5 changed files with 56 additions and 13 deletions

View file

@ -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
{

View file

@ -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");
}
}

View file

@ -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<string> OpenCancellableTextInputAlertDialog(string inputText)
public enum PopupResultEnum
{
Save,
Cancel,
Delete
}
public async Task<Tuple<string, PopupResultEnum>> 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<string>(inputView);
var popup = new InputAlertDialogBase<Tuple<string, PopupResultEnum>>(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<string, PopupResultEnum>(((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<string, PopupResultEnum>(null, PopupResultEnum.Cancel));
};
inputView.DeleteButtonEventHandler +=
(sender, obj) =>
{
popup.PageClosedTaskCompletionSource.SetResult(new Tuple<string, PopupResultEnum>(null, PopupResultEnum.Delete));
};
// Push the page to Navigation Stack

View file

@ -23,8 +23,22 @@
<Entry x:Name="InputEntry" Placeholder="Enter Here..." />
<Grid>
<Button
x:Name="SaveButton"
x:Name="DeleteButton"
Grid.Column="0"
BackgroundColor="Red"
Text="Supprimer"
TextColor="White">
<Button.HeightRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="Android" Value="40" />
<On Platform="iOS" Value="30" />
<On Platform="UWP, Windows" Value="35" />
</OnPlatform>
</Button.HeightRequest>
</Button>
<Button
x:Name="SaveButton"
Grid.Column="1"
BackgroundColor="DodgerBlue"
Text="Save"
TextColor="White">
@ -38,7 +52,9 @@
</Button>
<Button
x:Name="CancelButton"
Grid.Column="1"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
BackgroundColor="Gray"
Text="Cancel"
TextColor="White">
@ -52,6 +68,7 @@
</Button>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />

View file

@ -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)
{