Files
VDownload/VDownload.Core/VDownload.Core.ViewModels/BaseViewModel.cs

123 lines
3.9 KiB
C#
Raw Normal View History

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Core.ViewModels.Authentication;
using VDownload.Core.ViewModels.Home;
using VDownload.Core.ViewModels.Settings;
using VDownload.Services.UI.DictionaryResources;
2024-02-28 01:22:13 +01:00
using SimpleToolkit.UI.Models;
2024-03-05 17:01:00 +01:00
using VDownload.Core.ViewModels.About;
2024-03-08 20:48:31 +01:00
using VDownload.Core.ViewModels.Subscriptions;
2024-03-15 12:54:21 +01:00
using VDownload.Core.Strings;
namespace VDownload.Core.ViewModels
{
public partial class BaseViewModel : ObservableObject
{
#region SERVICES
protected readonly IDictionaryResourcesService _dictionaryResourcesService;
#endregion
#region FIELDS
protected readonly Type _settingsViewModel = typeof(SettingsViewModel);
#endregion
#region PROPERTIES
[ObservableProperty]
private Type _currentViewModel;
[ObservableProperty]
private NavigationViewItem _selectedItem;
public ReadOnlyObservableCollection<NavigationViewItem> Items { get; protected set; }
public ReadOnlyObservableCollection<NavigationViewItem> FooterItems { get; protected set; }
#endregion
#region CONSTRUCTORS
2024-03-15 12:54:21 +01:00
public BaseViewModel(IDictionaryResourcesService dictionaryResourcesService)
{
_dictionaryResourcesService = dictionaryResourcesService;
Items = new ReadOnlyObservableCollection<NavigationViewItem>
(
new ObservableCollection<NavigationViewItem>
{
new NavigationViewItem()
{
2024-03-15 12:54:21 +01:00
Name = StringResourcesManager.BaseView.Get("HomeNavigationViewItem"),
IconSource = _dictionaryResourcesService.Get<string>("ImageBaseViewHome"),
ViewModel = typeof(HomeViewModel),
2024-03-08 20:48:31 +01:00
},
new NavigationViewItem()
{
2024-03-15 12:54:21 +01:00
Name = StringResourcesManager.BaseView.Get("SubscriptionsNavigationViewItem"),
2024-03-08 20:48:31 +01:00
IconSource = _dictionaryResourcesService.Get<string>("ImageBaseViewSubscriptions"),
ViewModel = typeof(SubscriptionsViewModel),
},
}
);
FooterItems = new ReadOnlyObservableCollection<NavigationViewItem>
(
new ObservableCollection<NavigationViewItem>
{
new NavigationViewItem()
2024-03-05 17:01:00 +01:00
{
2024-03-15 12:54:21 +01:00
Name = StringResourcesManager.BaseView.Get("AboutNavigationViewItem"),
2024-03-05 17:01:00 +01:00
IconSource = _dictionaryResourcesService.Get<string>("ImageBaseViewAbout"),
ViewModel = typeof(AboutViewModel),
},
new NavigationViewItem()
{
2024-03-15 12:54:21 +01:00
Name = StringResourcesManager.BaseView.Get("AuthenticationNavigationViewItem"),
IconSource = _dictionaryResourcesService.Get<string>("ImageBaseViewAuthentication"),
ViewModel = typeof(AuthenticationViewModel),
}
}
);
SelectedItem = Items.First();
CurrentViewModel = SelectedItem.ViewModel;
}
#endregion
#region PUBLIC METHODS
[RelayCommand]
public void Navigate(Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs e)
{
if (e.IsSettingsInvoked)
{
CurrentViewModel = _settingsViewModel;
}
else
{
NavigationViewItem item = e.InvokedItemContainer.DataContext as NavigationViewItem;
CurrentViewModel = item.ViewModel;
}
}
#endregion
}
}