Cleanup GUI

This commit is contained in:
Oleksii Holub
2022-04-01 00:10:17 +03:00
parent 3a2b119618
commit 1daff4178d
15 changed files with 254 additions and 201 deletions

View File

@@ -7,20 +7,41 @@ public class MessageBoxViewModel : DialogScreen
public string? Title { get; set; }
public string? Message { get; set; }
public bool IsOkButtonVisible { get; set; } = true;
public string? OkButtonText { get; set; }
public bool IsCancelButtonVisible { get; set; }
public string? CancelButtonText { get; set; }
public int ButtonsCount =>
(IsOkButtonVisible ? 1 : 0) +
(IsCancelButtonVisible ? 1 : 0);
}
public static class MessageBoxViewModelExtensions
{
public static MessageBoxViewModel CreateMessageBoxViewModel(
this IViewModelFactory factory,
string title,
string message)
string title, string message,
string? okButtonText, string? cancelButtonText)
{
var viewModel = factory.CreateMessageBoxViewModel();
viewModel.Title = title;
viewModel.Message = message;
viewModel.IsOkButtonVisible = !string.IsNullOrWhiteSpace(okButtonText);
viewModel.OkButtonText = okButtonText;
viewModel.IsCancelButtonVisible = !string.IsNullOrWhiteSpace(cancelButtonText);
viewModel.CancelButtonText = cancelButtonText;
return viewModel;
}
public static MessageBoxViewModel CreateMessageBoxViewModel(
this IViewModelFactory factory,
string title, string message) =>
factory.CreateMessageBoxViewModel(title, message, "CLOSE", null);
}

View File

@@ -71,6 +71,23 @@ public class RootViewModel : Screen
Progress.Bind(o => o.Current, (_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate));
}
private async Task ShowWarInUkraineMessageAsync()
{
var dialog = _viewModelFactory.CreateMessageBoxViewModel(
"Ukraine is at war!", @"
My country, Ukraine, has been invaded by Russian military forces in an act of aggression that can only be described as genocide.
Be on the right side of history! Consider supporting Ukraine in its fight for freedom.
Press LEARN MORE to find ways that you can help.".Trim(),
"LEARN MORE", "CLOSE"
);
if (await _dialogManager.ShowDialogAsync(dialog) == true)
{
ProcessEx.StartShellExecute("https://tyrrrz.me");
}
}
private async ValueTask CheckForUpdatesAsync()
{
try
@@ -97,6 +114,12 @@ public class RootViewModel : Screen
Notifications.Enqueue("Failed to perform application update");
}
}
// This is a custom event that fires when the dialog host is loaded
public async void OnViewFullyLoaded()
{
await ShowWarInUkraineMessageAsync();
}
protected override async void OnViewLoaded()
{
@@ -118,19 +141,6 @@ public class RootViewModel : Screen
App.SetLightTheme();
}
// War in Ukraine message
Notifications.Enqueue(
"⚠ Ukraine is at war! Support my country in its fight for freedom",
"LEARN MORE", _ =>
{
ProcessEx.StartShellExecute("https://tyrrrz.me");
},
null,
true,
true,
TimeSpan.FromMinutes(1)
);
await CheckForUpdatesAsync();
}