2024-02-14 02:07:22 +01:00
|
|
|
|
using Microsoft.UI.Xaml.Data;
|
2024-02-13 02:59:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2024-03-05 17:01:00 +01:00
|
|
|
|
using VDownload.Core.ViewModels.About;
|
2024-02-14 02:07:22 +01:00
|
|
|
|
using VDownload.Core.ViewModels.Authentication;
|
|
|
|
|
|
using VDownload.Core.ViewModels.Home;
|
|
|
|
|
|
using VDownload.Core.ViewModels.Settings;
|
2024-03-08 20:48:31 +01:00
|
|
|
|
using VDownload.Core.ViewModels.Subscriptions;
|
2024-03-05 17:01:00 +01:00
|
|
|
|
using VDownload.Core.Views.About;
|
2024-02-14 02:07:22 +01:00
|
|
|
|
using VDownload.Core.Views.Authentication;
|
|
|
|
|
|
using VDownload.Core.Views.Home;
|
|
|
|
|
|
using VDownload.Core.Views.Settings;
|
2024-03-08 20:48:31 +01:00
|
|
|
|
using VDownload.Core.Views.Subscriptions;
|
2024-02-13 02:59:40 +01:00
|
|
|
|
|
2024-02-14 02:07:22 +01:00
|
|
|
|
namespace VDownload.Core.Views
|
2024-02-13 02:59:40 +01:00
|
|
|
|
{
|
|
|
|
|
|
public class ViewModelToViewConverter : IValueConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
#region FIELDS
|
|
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<Type, Type> _viewModelViewBinding = new Dictionary<Type, Type>
|
|
|
|
|
|
{
|
|
|
|
|
|
{ typeof(HomeViewModel), typeof(HomeView) },
|
2024-02-14 02:07:22 +01:00
|
|
|
|
{ typeof(HomeDownloadsViewModel), typeof(HomeDownloadsView) },
|
|
|
|
|
|
{ typeof(HomeVideoViewModel), typeof(HomeVideoView) },
|
2024-03-08 00:07:22 +01:00
|
|
|
|
{ typeof(HomeVideoCollectionViewModel), typeof(HomeVideoCollectionView) },
|
2024-03-08 20:48:31 +01:00
|
|
|
|
{ typeof(SubscriptionsViewModel), typeof(SubscriptionsView) },
|
2024-02-13 02:59:40 +01:00
|
|
|
|
{ typeof(SettingsViewModel), typeof(SettingsView) },
|
2024-03-05 17:01:00 +01:00
|
|
|
|
{ typeof(AboutViewModel), typeof(AboutView) },
|
2024-02-13 02:59:40 +01:00
|
|
|
|
{ typeof(AuthenticationViewModel), typeof(AuthenticationView) }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-02-14 02:07:22 +01:00
|
|
|
|
#region PROPERTIES
|
|
|
|
|
|
|
|
|
|
|
|
public static IServiceProvider ServiceProvider { protected get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PUBLIC METHODS
|
2024-02-13 02:59:40 +01:00
|
|
|
|
|
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (value is Type type && _viewModelViewBinding.ContainsKey(type))
|
|
|
|
|
|
{
|
2024-02-14 02:07:22 +01:00
|
|
|
|
return ServiceProvider.GetService(_viewModelViewBinding[type]);
|
2024-02-13 02:59:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
if (_viewModelViewBinding.ContainsKey(value.GetType()))
|
|
|
|
|
|
{
|
2024-02-14 02:07:22 +01:00
|
|
|
|
return ServiceProvider.GetService(_viewModelViewBinding[value.GetType()]);
|
2024-02-13 02:59:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
|
|
|
|
{
|
2024-02-14 02:07:22 +01:00
|
|
|
|
Dictionary<Type, Type> viewViewModelBinding = _viewModelViewBinding.ToDictionary(x => x.Value, x => x.Key);
|
|
|
|
|
|
if (viewViewModelBinding.ContainsKey(value.GetType()))
|
2024-02-13 02:59:40 +01:00
|
|
|
|
{
|
2024-02-14 02:07:22 +01:00
|
|
|
|
return viewViewModelBinding[value.GetType()];
|
2024-02-13 02:59:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|