Fix requiring sender name in the initial account setup dialog for IMAP.

This commit is contained in:
Burak Kaan Köse
2024-06-10 16:22:35 +02:00
parent d71b6d0ab0
commit fed9345bea
2 changed files with 17 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ namespace Wino.Core.Domain.Models.Accounts
public string ProviderImage => $"ms-appx:///Assets/Providers/{Type}.png"; public string ProviderImage => $"ms-appx:///Assets/Providers/{Type}.png";
public bool IsSupported => Type == MailProviderType.Outlook || Type == MailProviderType.Gmail || Type == MailProviderType.IMAP4; public bool IsSupported => Type == MailProviderType.Outlook || Type == MailProviderType.Gmail || Type == MailProviderType.IMAP4;
public bool RequireSenderNameOnCreationDialog => Type != MailProviderType.IMAP4;
public ProviderDetail(MailProviderType type) public ProviderDetail(MailProviderType type)
{ {

View File

@@ -35,7 +35,7 @@ namespace Wino.Dialogs
private static void OnSelectedProviderChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) private static void OnSelectedProviderChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{ {
if (obj is NewAccountDialog dialog) if (obj is NewAccountDialog dialog)
dialog.ValidateCreateButton(); dialog.Validate();
} }
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args) private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
@@ -45,7 +45,7 @@ namespace Wino.Dialogs
private void CreateClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args) private void CreateClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{ {
ValidateCreateButton(); Validate();
if (IsSecondaryButtonEnabled) if (IsSecondaryButtonEnabled)
{ {
@@ -54,8 +54,14 @@ namespace Wino.Dialogs
} }
} }
private void AccountNameChanged(object sender, TextChangedEventArgs e) => ValidateCreateButton(); private void AccountNameChanged(object sender, TextChangedEventArgs e) => Validate();
private void SenderNameChanged(object sender, TextChangedEventArgs e) => ValidateCreateButton(); private void SenderNameChanged(object sender, TextChangedEventArgs e) => Validate();
private void Validate()
{
ValidateCreateButton();
ValidateNames();
}
// Returns whether we can create account or not. // Returns whether we can create account or not.
private void ValidateCreateButton() private void ValidateCreateButton()
@@ -63,14 +69,17 @@ namespace Wino.Dialogs
bool shouldEnable = SelectedMailProvider != null bool shouldEnable = SelectedMailProvider != null
&& SelectedMailProvider.IsSupported && SelectedMailProvider.IsSupported
&& !string.IsNullOrEmpty(AccountNameTextbox.Text) && !string.IsNullOrEmpty(AccountNameTextbox.Text)
&& !string.IsNullOrWhiteSpace(SenderNameTextbox.Text); && (SelectedMailProvider.RequireSenderNameOnCreationDialog ? !string.IsNullOrEmpty(SenderNameTextbox.Text) : true);
IsPrimaryButtonEnabled = shouldEnable; IsPrimaryButtonEnabled = shouldEnable;
} }
private void DialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args) private void ValidateNames()
{ {
ValidateCreateButton(); AccountNameTextbox.IsEnabled = SelectedMailProvider != null;
SenderNameTextbox.IsEnabled = SelectedMailProvider != null && SelectedMailProvider.Type != Core.Domain.Enums.MailProviderType.IMAP4;
} }
private void DialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args) => Validate();
} }
} }