57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using WinWARP.Core.Enums;
|
|
using WinWARP.Core.Services.Interfaces;
|
|
using WinWARP.Ui.Helpers;
|
|
using WinWARP.Ui.Views.Dialogs;
|
|
|
|
namespace WinWARP.Ui.Services;
|
|
|
|
public class DialogService(XamlRootTracker tracker, ILocalizationService localizationService) : IDialogService
|
|
{
|
|
private readonly XamlRootTracker _tracker = tracker;
|
|
private readonly ILocalizationService _localizationService = localizationService;
|
|
|
|
public async Task<(CommonDialogResult Result, string Title, string URL, int UpdateInterval)> ShowAddSubscriptionAsync()
|
|
{
|
|
var dialog = App.Services.GetRequiredService<AddSubscriptionDialog>();
|
|
//dialog.Title = "Add new subscription";
|
|
//dialog.PrimaryButtonText = "Add";
|
|
//dialog.CloseButtonText = "Cancel";
|
|
dialog.XamlRoot = _tracker.XamlRoot;
|
|
dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
|
|
|
|
var result = await dialog.ShowAsync();
|
|
|
|
var mappedResult = result switch
|
|
{
|
|
ContentDialogResult.Primary => CommonDialogResult.Primary,
|
|
ContentDialogResult.Secondary => CommonDialogResult.Secondary,
|
|
ContentDialogResult.None => CommonDialogResult.Cancel,
|
|
_ => CommonDialogResult.None
|
|
};
|
|
|
|
return (mappedResult, dialog.ViewModel.CustomName, dialog.ViewModel.SubscriptionLink, dialog.ViewModel.UpdateInterval);
|
|
}
|
|
|
|
public async Task ShowErrorAsync(string message)
|
|
{
|
|
var dialog = new ContentDialog
|
|
{
|
|
Title = _localizationService.GetString("ErrorDialog.Title"),
|
|
Content = message,
|
|
CloseButtonText = _localizationService.GetString("ErrorDialog.CloseButtonText"),
|
|
XamlRoot = _tracker.XamlRoot,
|
|
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style
|
|
};
|
|
await dialog.ShowAsync();
|
|
}
|
|
}
|