/// <summary> /// Begins an asynchronous operation showing a <see cref="MegaContentDialog"/>. /// If another <see cref="MegaContentDialog"/> is already shown using this method, it will wait for that previous dialog /// to be dismissed before showing the new one. /// </summary> /// <param name="dialog">The <see cref="MegaContentDialog"/>.</param> /// <returns>The <see cref="MegaContentDialog"/> result.</returns> /// <exception cref="InvalidOperationException">This method can only be invoked from the UI thread.</exception> public static async Task <ContentDialogResult> ShowAsyncQueue(this MegaContentDialog dialog) { if (!Window.Current.Dispatcher.HasThreadAccess) { throw new InvalidOperationException("This method can only be invoked from UI thread."); } while (_contentDialogShowRequest != null) { await _contentDialogShowRequest.Task; } while (_messageDialogShowRequest != null) { await _messageDialogShowRequest.Task; } var request = _contentDialogShowRequest = new TaskCompletionSource <MegaContentDialog>(); var result = await dialog.ShowAsync(); _contentDialogShowRequest = null; request.SetResult(dialog); return(result); }
/// <summary> /// Begins an asynchronous operation showing a <see cref="MegaContentDialog"/>. /// If another <see cref="MegaContentDialog"/> is already shown using this method, it will wait for that previous dialog /// to be dismissed before showing the new one. /// </summary> /// <param name="dialog">The <see cref="MegaContentDialog"/>.</param> /// <returns>The <see cref="MegaContentDialog"/> result as <see cref="bool"/> value.</returns> /// <exception cref="InvalidOperationException">This method can only be invoked from the UI thread.</exception> public static async Task <bool> ShowAsyncQueueBool(this MegaContentDialog dialog) { var result = await ShowAsyncQueue(dialog); return(result == ContentDialogResult.Primary || dialog.DialogResult); }
/// <summary> /// Shows a dialog to allow copy a node link to the clipboard or share it using other app /// </summary> /// <param name="node">Node to share the link</param> public static async void ShowShareLink(NodeViewModel node) { var dialog = new MegaContentDialog { Background = (Brush)Application.Current.Resources["MegaAppBackgroundBrush"], BorderBrush = (Brush)Application.Current.Resources["MegaDialogBorderBrush"], CloseButtonVisibility = Visibility.Visible, IsPrimaryButtonEnabled = true, IsSecondaryButtonEnabled = true, Margin = new Thickness(0, 0, 24, 24), PrimaryButtonText = ResourceService.UiResources.GetString("UI_Copy"), SecondaryButtonText = ResourceService.UiResources.GetString("UI_Share"), Style = (Style)Application.Current.Resources["MegaAlertDialogStyle"], Title = ResourceService.UiResources.GetString("UI_ExportLink") }; dialog.CloseButtonCommand = new RelayCommand(() => dialog.Hide()); var stackPanel = new StackPanel { Margin = new Thickness(24, 24, 0, 0) }; var messageText = new TextBlock { Text = node.ExportLink, Margin = new Thickness(0, 20, 0, 12), TextWrapping = TextWrapping.WrapWholeWords, HorizontalAlignment = HorizontalAlignment.Stretch, }; var linkWithoutKey = new RadioButton { Content = ResourceService.UiResources.GetString("UI_LinkWithoutKey") }; linkWithoutKey.Checked += (sender, args) => messageText.Text = node.OriginalMNode.getPublicLink(false); var decryptionKey = new RadioButton { Content = ResourceService.UiResources.GetString("UI_DecryptionKey") }; decryptionKey.Checked += (sender, args) => messageText.Text = node.OriginalMNode.getBase64Key(); var linkWithKey = new RadioButton { Content = ResourceService.UiResources.GetString("UI_LinkWithKey"), IsChecked = true }; linkWithKey.Checked += (sender, args) => messageText.Text = node.OriginalMNode.getPublicLink(true); stackPanel.Children.Add(linkWithoutKey); stackPanel.Children.Add(decryptionKey); stackPanel.Children.Add(linkWithKey); var stackPanelLinkWithExpirationDate = new StackPanel { Orientation = Orientation.Horizontal }; var linkWithExpirationDateLabel = new TextBlock { Text = node.SetLinkExpirationDateText, Margin = new Thickness(0, 20, 0, 8), TextWrapping = TextWrapping.WrapWholeWords, HorizontalAlignment = HorizontalAlignment.Stretch, }; var enableLinkExpirationDateSwitch = new ToggleSwitch { IsOn = node.LinkWithExpirationTime, IsEnabled = AccountService.AccountDetails.IsProAccount }; var expirationDateCalendarDatePicker = new CalendarDatePicker { IsEnabled = enableLinkExpirationDateSwitch.IsOn, DateFormat = "{day.integer(2)}/{month.integer(2)}/{year.full}", Date = node.LinkExpirationDate }; expirationDateCalendarDatePicker.Opened += (sender, args) => { expirationDateCalendarDatePicker.LightDismissOverlayMode = LightDismissOverlayMode.On; expirationDateCalendarDatePicker.MinDate = DateTime.Today.AddDays(1); }; expirationDateCalendarDatePicker.DateChanged += (sender, args) => { expirationDateCalendarDatePicker.IsCalendarOpen = false; if (expirationDateCalendarDatePicker.Date == null) { enableLinkExpirationDateSwitch.IsOn = false; if (node.LinkExpirationTime > 0) { node.SetLinkExpirationTime(0); } } else if (node.LinkExpirationDate == null || !node.LinkExpirationDate.Value.ToUniversalTime().Equals(expirationDateCalendarDatePicker.Date.Value.ToUniversalTime())) { node.SetLinkExpirationTime(expirationDateCalendarDatePicker.Date.Value.ToUniversalTime().ToUnixTimeSeconds()); } }; enableLinkExpirationDateSwitch.Toggled += (sender, args) => { expirationDateCalendarDatePicker.IsEnabled = enableLinkExpirationDateSwitch.IsOn; if (enableLinkExpirationDateSwitch.IsOn) { expirationDateCalendarDatePicker.Date = node.LinkExpirationDate; } else { expirationDateCalendarDatePicker.Date = null; } }; stackPanelLinkWithExpirationDate.Children.Add(enableLinkExpirationDateSwitch); stackPanelLinkWithExpirationDate.Children.Add(expirationDateCalendarDatePicker); stackPanel.Children.Add(linkWithExpirationDateLabel); stackPanel.Children.Add(stackPanelLinkWithExpirationDate); stackPanel.Children.Add(messageText); dialog.Content = stackPanel; var result = await dialog.ShowAsyncQueue(); switch (result) { case ContentDialogResult.None: break; case ContentDialogResult.Primary: ShareService.CopyLinkToClipboard(messageText.Text); break; case ContentDialogResult.Secondary: ShareService.ShareLink(messageText.Text); break; default: throw new ArgumentOutOfRangeException(); } }