mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Popup
This commit is contained in:
		
							parent
							
								
									a4933c52ba
								
							
						
					
					
						commit
						c34ce571ea
					
				
					 13 changed files with 323 additions and 0 deletions
				
			
		|  | @ -58,6 +58,9 @@ | |||
|     <Reference Include="System.Xml" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Rg.Plugins.Popup"> | ||||
|       <Version>1.1.4.168</Version> | ||||
|     </PackageReference> | ||||
|     <PackageReference Include="SkiaSharp.Svg"> | ||||
|       <Version>1.60.0</Version> | ||||
|     </PackageReference> | ||||
|  |  | |||
|  | @ -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` | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -188,6 +188,9 @@ | |||
|     </Page> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Rg.Plugins.Popup"> | ||||
|       <Version>1.1.4.168</Version> | ||||
|     </PackageReference> | ||||
|     <PackageReference Include="SkiaSharp.Svg"> | ||||
|       <Version>1.60.0</Version> | ||||
|     </PackageReference> | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -111,6 +111,9 @@ | |||
|     <Reference Include="Xamarin.iOS" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Rg.Plugins.Popup"> | ||||
|       <Version>1.1.4.168</Version> | ||||
|     </PackageReference> | ||||
|     <PackageReference Include="SkiaSharp.Svg"> | ||||
|       <Version>1.60.0</Version> | ||||
|     </PackageReference> | ||||
|  |  | |||
|  | @ -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()); | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,6 +29,7 @@ | |||
| 
 | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Markdig" Version="0.15.2" /> | ||||
|     <PackageReference Include="Rg.Plugins.Popup" Version="1.1.4.168" /> | ||||
|     <PackageReference Include="SkiaSharp.Svg" Version="1.60.0" /> | ||||
|     <PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.3" /> | ||||
|     <PackageReference Include="Xamarin.Forms" Version="3.2.0.839982" /> | ||||
|  | @ -358,6 +359,9 @@ | |||
|     <EmbeddedResource Update="Views\MainTabbedPage.xaml"> | ||||
|       <Generator>MSBuild:UpdateDesignTimeXaml</Generator> | ||||
|     </EmbeddedResource> | ||||
|     <EmbeddedResource Update="Views\TextInputCancellableView.xaml"> | ||||
|       <Generator>MSBuild:UpdateDesignTimeXaml</Generator> | ||||
|     </EmbeddedResource> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
|  | @ -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]); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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<string> 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<string>(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; | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ | |||
|         </ResourceDictionary> | ||||
|     </ContentPage.Resources> | ||||
|     <ContentPage.ToolbarItems> | ||||
|         <ToolbarItem Name="Configure" Text="Configurer" Order="Primary" Icon="settings_knobs.png" Command="{Binding BindingContext.ConfigureCommand, Source={x:Reference This}}" /> | ||||
|     </ContentPage.ToolbarItems> | ||||
|     <ContentPage.Content> | ||||
|         <Grid BackgroundColor="{StaticResource HDWhite}"> | ||||
|  |  | |||
							
								
								
									
										63
									
								
								AideDeJeu/AideDeJeu/Views/InputAlertDialogBase.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								AideDeJeu/AideDeJeu/Views/InputAlertDialogBase.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,63 @@ | |||
| using Rg.Plugins.Popup.Pages; | ||||
| using System.Threading.Tasks; | ||||
| using Xamarin.Forms; | ||||
| 
 | ||||
| namespace AideDeJeu.Views | ||||
| { | ||||
|     /// <summary> | ||||
|     /// The awesome Transparent Popup Page | ||||
|     /// sub-classed from Rg.Plugins.Popup | ||||
|     /// Customized for our usecase with | ||||
|     /// Generic data type support for the result | ||||
|     /// </summary> | ||||
|     /// <typeparam name="T"></typeparam> | ||||
|     public class InputAlertDialogBase<T> : PopupPage | ||||
|     { | ||||
|         // the awaitable task | ||||
|         public Task<T> PageClosedTask { get { return PageClosedTaskCompletionSource.Task; } } | ||||
| 
 | ||||
|         // the task completion source | ||||
|         public TaskCompletionSource<T> PageClosedTaskCompletionSource { get; set; } | ||||
| 
 | ||||
|         public InputAlertDialogBase(View contentBody) | ||||
|         { | ||||
|             Content = contentBody; | ||||
| 
 | ||||
|             // init the task completion source | ||||
|             PageClosedTaskCompletionSource = new System.Threading.Tasks.TaskCompletionSource<T>(); | ||||
| 
 | ||||
|             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; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										63
									
								
								AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,63 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <ContentView xmlns="http://xamarin.com/schemas/2014/forms"  | ||||
|              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||||
|              x:Class="AideDeJeu.Views.TextInputCancellableView"> | ||||
|     <ContentView.Content> | ||||
|         <StackLayout | ||||
|             Padding="10" | ||||
|             BackgroundColor="White" | ||||
|             HorizontalOptions="CenterAndExpand" | ||||
|             Spacing="5" | ||||
|             VerticalOptions="CenterAndExpand" | ||||
|             WidthRequest="300"> | ||||
|             <Label | ||||
|                 x:Name="TitleLabel" | ||||
|                 FontSize="Medium" | ||||
|                 Text="Enter the value:" /> | ||||
|             <Label | ||||
|                 x:Name="ValidationLabel" | ||||
|                 FontSize="Micro" | ||||
|                 IsVisible="False" | ||||
|                 Text="You can't leave this field empty!" | ||||
|                 TextColor="Red" /> | ||||
|             <Entry x:Name="InputEntry" Placeholder="Enter Here..." /> | ||||
|             <Grid> | ||||
|                 <Button | ||||
|                     x:Name="SaveButton" | ||||
|                     Grid.Column="0" | ||||
|                     BackgroundColor="DodgerBlue" | ||||
|                     Text="Save" | ||||
|                     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="CancelButton" | ||||
|                     Grid.Column="1" | ||||
|                     BackgroundColor="Gray" | ||||
|                     Text="Cancel" | ||||
|                     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> | ||||
|                 <Grid.RowDefinitions> | ||||
|                     <RowDefinition Height="*" /> | ||||
|                 </Grid.RowDefinitions> | ||||
|                 <Grid.ColumnDefinitions> | ||||
|                     <ColumnDefinition Width="*" /> | ||||
|                     <ColumnDefinition Width="*" /> | ||||
|                 </Grid.ColumnDefinitions> | ||||
|             </Grid> | ||||
|         </StackLayout> | ||||
|     </ContentView.Content> | ||||
| </ContentView> | ||||
							
								
								
									
										101
									
								
								AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								AideDeJeu/AideDeJeu/Views/TextInputCancellableView.xaml.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
|                     } | ||||
|                 }); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Gets or Sets if the ValidationLabel is visible | ||||
|         /// </summary> | ||||
|         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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez