diff --git a/AideDeJeu/AideDeJeu.Android/AideDeJeu.Android.csproj b/AideDeJeu/AideDeJeu.Android/AideDeJeu.Android.csproj index 860fb8a1..2a13f680 100644 --- a/AideDeJeu/AideDeJeu.Android/AideDeJeu.Android.csproj +++ b/AideDeJeu/AideDeJeu.Android/AideDeJeu.Android.csproj @@ -58,6 +58,9 @@ + + 1.1.4.168 + 1.60.0 diff --git a/AideDeJeu/AideDeJeu.Android/MainActivity.cs b/AideDeJeu/AideDeJeu.Android/MainActivity.cs index b367e5cb..e45b25af 100644 --- a/AideDeJeu/AideDeJeu.Android/MainActivity.cs +++ b/AideDeJeu/AideDeJeu.Android/MainActivity.cs @@ -20,9 +20,23 @@ namespace AideDeJeu.Droid base.OnCreate(bundle); + Rg.Plugins.Popup.Popup.Init(this, bundle); + global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); } + + public override void OnBackPressed() + { + if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed)) + { + // Do something if there are some pages in the `PopupStack` + } + else + { + // Do something if there are not any pages in the `PopupStack` + } + } } } diff --git a/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj b/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj index 2044d40b..7a0220f9 100644 --- a/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj +++ b/AideDeJeu/AideDeJeu.UWP/AideDeJeu.UWP.csproj @@ -188,6 +188,9 @@ + + 1.1.4.168 + 1.60.0 diff --git a/AideDeJeu/AideDeJeu.UWP/App.xaml.cs b/AideDeJeu/AideDeJeu.UWP/App.xaml.cs index 97ee9746..6372a76e 100644 --- a/AideDeJeu/AideDeJeu.UWP/App.xaml.cs +++ b/AideDeJeu/AideDeJeu.UWP/App.xaml.cs @@ -52,6 +52,8 @@ namespace AideDeJeu.UWP rootFrame.NavigationFailed += OnNavigationFailed; + Rg.Plugins.Popup.Popup.Init(); + Xamarin.Forms.Forms.Init(e); if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) diff --git a/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj b/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj index 292b777c..e5b278c9 100644 --- a/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj +++ b/AideDeJeu/AideDeJeu.iOS/AideDeJeu.iOS.csproj @@ -111,6 +111,9 @@ + + 1.1.4.168 + 1.60.0 diff --git a/AideDeJeu/AideDeJeu.iOS/AppDelegate.cs b/AideDeJeu/AideDeJeu.iOS/AppDelegate.cs index 4cabc1d1..53e1d6d2 100644 --- a/AideDeJeu/AideDeJeu.iOS/AppDelegate.cs +++ b/AideDeJeu/AideDeJeu.iOS/AppDelegate.cs @@ -22,6 +22,8 @@ namespace AideDeJeu.iOS // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { + Rg.Plugins.Popup.Popup.Init(); + global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); diff --git a/AideDeJeu/AideDeJeu/AideDeJeu.csproj b/AideDeJeu/AideDeJeu/AideDeJeu.csproj index cadd34e7..df58bbc5 100644 --- a/AideDeJeu/AideDeJeu/AideDeJeu.csproj +++ b/AideDeJeu/AideDeJeu/AideDeJeu.csproj @@ -29,6 +29,7 @@ + @@ -358,6 +359,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs index 0286a0e1..2cf8f6c6 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs @@ -143,6 +143,20 @@ namespace AideDeJeu.ViewModels } } + private ICommand _ConfigureCommand = null; + public ICommand ConfigureCommand + { + get + { + return _ConfigureCommand ?? (_ConfigureCommand = new Command(async () => await ExecuteConfigureCommand())); + } + } + + private async Task ExecuteConfigureCommand() + { + await Main.Navigator.OpenCancellableTextInputAlertDialog(BookmarkCollectionNames[BookmarkCollectionIndex]); + + } diff --git a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs index 0a2f5cc2..4df19e27 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs @@ -1,5 +1,6 @@ using AideDeJeu.Views; using AideDeJeuLib; +using Rg.Plugins.Popup.Services; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -204,5 +205,54 @@ namespace AideDeJeu.ViewModels } } + + + + 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."); + + // create the Transparent Popup Page + // of type string since we need a string return + var popup = new InputAlertDialogBase(inputView); + + + // subscribe to the TextInputView's Button click event + inputView.SaveButtonEventHandler += + (sender, obj) => + { + if (!string.IsNullOrEmpty(((TextInputCancellableView)sender).TextInputResult)) + { + ((TextInputCancellableView)sender).IsValidationLabelVisible = false; + popup.PageClosedTaskCompletionSource.SetResult(((TextInputCancellableView)sender).TextInputResult); + } + else + { + ((TextInputCancellableView)sender).IsValidationLabelVisible = true; + } + }; + + // subscribe to the TextInputView's Button click event + inputView.CancelButtonEventHandler += + (sender, obj) => + { + popup.PageClosedTaskCompletionSource.SetResult(null); + }; + + // Push the page to Navigation Stack + await PopupNavigation.Instance.PushAsync(popup); + + // await for the user to enter the text input + var result = await popup.PageClosedTask; + + // Pop the page from Navigation Stack + await PopupNavigation.Instance.PopAsync(); + + // return user inserted text value + return result; + } + } } diff --git a/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml index ca7cde8d..e020459b 100644 --- a/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml @@ -14,6 +14,7 @@ + diff --git a/AideDeJeu/AideDeJeu/Views/InputAlertDialogBase.cs b/AideDeJeu/AideDeJeu/Views/InputAlertDialogBase.cs new file mode 100644 index 00000000..3690b7b2 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/InputAlertDialogBase.cs @@ -0,0 +1,63 @@ +using Rg.Plugins.Popup.Pages; +using System.Threading.Tasks; +using Xamarin.Forms; + +namespace AideDeJeu.Views +{ + /// + /// The awesome Transparent Popup Page + /// sub-classed from Rg.Plugins.Popup + /// Customized for our usecase with + /// Generic data type support for the result + /// + /// + public class InputAlertDialogBase : PopupPage + { + // the awaitable task + public Task PageClosedTask { get { return PageClosedTaskCompletionSource.Task; } } + + // the task completion source + public TaskCompletionSource PageClosedTaskCompletionSource { get; set; } + + public InputAlertDialogBase(View contentBody) + { + Content = contentBody; + + // init the task completion source + PageClosedTaskCompletionSource = new System.Threading.Tasks.TaskCompletionSource(); + + this.BackgroundColor = new Color(0, 0, 0, 0.4); + } + + // Method for animation child in PopupPage + // Invoced after custom animation end + protected override Task OnAppearingAnimationEndAsync() + { + return Content.FadeTo(1); + } + + // Method for animation child in PopupPage + // Invoked before custom animation begin + protected override Task OnDisappearingAnimationBeginAsync() + { + return Content.FadeTo(1); + } + + protected override bool OnBackButtonPressed() + { + // Prevent back button pressed action on android + //return base.OnBackButtonPressed(); + return true; + } + + // Invoced when background is clicked + protected override bool OnBackgroundClicked() + { + // Prevent background clicked action + //return base.OnBackgroundClicked(); + return false; + } + } + + +} diff --git a/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml new file mode 100644 index 00000000..b4461032 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml @@ -0,0 +1,63 @@ + + + + + + + \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs new file mode 100644 index 00000000..382ba14d --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace AideDeJeu.Views +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class TextInputCancellableView : ContentView + { + // public event handler to expose + // the Save button's click event + public EventHandler SaveButtonEventHandler { get; set; } + + // public event handler to expose + // the Cancel button's click event + public EventHandler CancelButtonEventHandler { get; set; } + + // public string to expose the + // text Entry input's value + public string TextInputResult { get; set; } + + public static readonly BindableProperty IsValidationLabelVisibleProperty = + BindableProperty.Create( + nameof(IsValidationLabelVisible), + typeof(bool), + typeof(TextInputCancellableView), + false, BindingMode.OneWay, null, + (bindable, value, newValue) => + { + if ((bool)newValue) + { + ((TextInputCancellableView)bindable).ValidationLabel + .IsVisible = true; + } + else + { + ((TextInputCancellableView)bindable).ValidationLabel + .IsVisible = false; + } + }); + + /// + /// Gets or Sets if the ValidationLabel is visible + /// + public bool IsValidationLabelVisible + { + get + { + return (bool)GetValue(IsValidationLabelVisibleProperty); + } + set + { + SetValue(IsValidationLabelVisibleProperty, value); + } + } + + public TextInputCancellableView(string titleText, string placeHolderText, string inputText, + string saveButtonText, string cancelButtonText, string validationText) + { + InitializeComponent(); + + // update the Element's textual values + TitleLabel.Text = titleText; + InputEntry.Text = inputText; + InputEntry.Placeholder = placeHolderText; + SaveButton.Text = saveButtonText; + CancelButton.Text = cancelButtonText; + ValidationLabel.Text = validationText; + + // handling events to expose to public + SaveButton.Clicked += SaveButton_Clicked; + CancelButton.Clicked += CancelButton_Clicked; + InputEntry.TextChanged += InputEntry_TextChanged; + } + + private void SaveButton_Clicked(object sender, EventArgs e) + { + // invoke the event handler if its being subscribed + SaveButtonEventHandler?.Invoke(this, e); + } + + private void CancelButton_Clicked(object sender, EventArgs e) + { + // invoke the event handler if its being subscribed + CancelButtonEventHandler?.Invoke(this, e); + } + + private void InputEntry_TextChanged(object sender, + TextChangedEventArgs e) + { + // update the public string value + // accordingly to the text Entry's value + TextInputResult = InputEntry.Text; + } + } +} \ No newline at end of file