using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using VDownload.Core.Tasks; using VDownload.Core.ViewModels.Home.Helpers; using VDownload.Models; using VDownload.Services.Data.Settings; using VDownload.Services.UI.StoragePicker; using VDownload.Sources.Twitch.Configuration.Models; using SimpleToolkit.MVVM; using System.Text.RegularExpressions; using VDownload.Services.Utility.Filename; using VDownload.Services.UI.Dialogs; using VDownload.Services.UI.StringResources; using CommunityToolkit.WinUI.Helpers; using VDownload.Services.Data.Application; namespace VDownload.Core.ViewModels.Home { public partial class HomeVideoCollectionViewModel : ObservableObject { #region SERVICES protected readonly IDownloadTaskManager _tasksManager; protected readonly ISettingsService _settingsService; protected readonly IStoragePickerService _storagePickerService; protected readonly IFilenameService _filenameService; protected readonly IDialogsService _dialogsService; protected readonly IStringResourcesService _stringResourcesService; protected readonly IApplicationDataService _applicationDataService; #endregion #region FIELDS protected VideoCollection _collection; protected List _removedVideos; #endregion #region PROPERTIES [ObservableProperty] protected string _name; [ObservableProperty] protected ObservableDictionary _videos; [ObservableProperty] protected int _removedCount; [ObservableProperty] protected int _hiddenCount; [ObservableProperty] protected bool _isSomethingHidden; public string TitleFilter { get => _titleFilter; set { SetProperty(ref _titleFilter, value, nameof(TitleFilter)); UpdateFilter(); } } protected string _titleFilter; public string AuthorFilter { get => _authorFilter; set { SetProperty(ref _authorFilter, value, nameof(AuthorFilter)); UpdateFilter(); } } protected string _authorFilter; public long MinViewsFilter { get => _minViewsFilter; set { SetProperty(ref _minViewsFilter, value, nameof(MinViewsFilter)); UpdateFilter(); } } protected long _minViewsFilter; public long MaxViewsFilter { get => _maxViewsFilter; set { SetProperty(ref _maxViewsFilter, value, nameof(MaxViewsFilter)); UpdateFilter(); } } protected long _maxViewsFilter; [ObservableProperty] protected long _minViews; [ObservableProperty] protected long _maxViews; public DateTimeOffset MinDateFilter { get => _minDateFilter; set { SetProperty(ref _minDateFilter, value, nameof(MinDateFilter)); UpdateFilter(); } } protected DateTimeOffset _minDateFilter; public DateTimeOffset MaxDateFilter { get => _maxDateFilter; set { SetProperty(ref _maxDateFilter, value, nameof(MaxDateFilter)); UpdateFilter(); } } protected DateTimeOffset _maxDateFilter; [ObservableProperty] protected DateTimeOffset _minDate; [ObservableProperty] protected DateTimeOffset _maxDate; public TimeSpan MinDurationFilter { get => _minDurationFilter; set { SetProperty(ref _minDurationFilter, value, nameof(MinDurationFilter)); UpdateFilter(); } } protected TimeSpan _minDurationFilter; public TimeSpan MaxDurationFilter { get => _maxDurationFilter; set { SetProperty(ref _maxDurationFilter, value, nameof(MaxDurationFilter)); UpdateFilter(); } } protected TimeSpan _maxDurationFilter; [ObservableProperty] protected TimeSpan _minDuration; [ObservableProperty] protected TimeSpan _maxDuration; #endregion #region CONSTRUCTORS public HomeVideoCollectionViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, IDialogsService dialogsService, IStringResourcesService stringResourcesService, IApplicationDataService applicationDataService) { _tasksManager = tasksManager; _settingsService = settingsService; _storagePickerService = storagePickerService; _filenameService = filenameService; _dialogsService = dialogsService; _stringResourcesService = stringResourcesService; _applicationDataService = applicationDataService; _removedVideos = new List(); _videos = new ObservableDictionary(); } #endregion #region PUBLIC METHODS public void LoadCollection(VideoCollection collection) { _collection = collection; ParallelQuery