This commit is contained in:
2024-02-28 01:22:13 +01:00
Unverified
parent e3ec5c3a48
commit 74eb899e31
51 changed files with 562 additions and 608 deletions

View File

@@ -0,0 +1,75 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Models;
using VDownload.Sources.Twitch.Configuration.Models;
namespace VDownload.Core.ViewModels.Home
{
public partial class HomePlaylistViewModel : ObservableObject
{
#region SERVICES
#endregion
#region FIELDS
#endregion
#region PROPERTIES
[ObservableProperty]
protected string _name;
#endregion
#region CONSTRUCTORS
public HomePlaylistViewModel()
{
}
#endregion
#region PUBLIC METHODS
public async Task LoadPlaylist(Playlist playlist)
{
Name = playlist.Name;
}
#endregion
#region COMMANDS
#endregion
#region EVENTS
public event EventHandler CloseRequested;
#endregion
}
}

View File

@@ -87,14 +87,6 @@ namespace VDownload.Core.ViewModels.Home
#region EVENTS
public event EventHandler TaskAdded;
#endregion
#region CONSTRUCTORS
public HomeVideoViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService)
@@ -110,7 +102,7 @@ namespace VDownload.Core.ViewModels.Home
#region PUBLIC METHODS
public async void LoadVideo(Video video)
public async Task LoadVideo(Video video)
{
await _settingsService.Load();
@@ -125,13 +117,13 @@ namespace VDownload.Core.ViewModels.Home
Streams = [.. video.Streams];
SelectedStream = Streams[0];
MediaType = _settingsService.Data.Common.DefaultTaskSettings.MediaType;
MediaType = _settingsService.Data.Common.Tasks.DefaultMediaType;
TrimStart = TimeSpan.Zero;
TrimEnd = Duration;
DirectoryPath = _settingsService.Data.Common.DefaultTaskSettings.OutputDirectory;
DirectoryPath = _settingsService.Data.Common.Tasks.DefaultOutputDirectory;
Filename = Title.Length > 50 ? Title.Substring(0, 50) : Title;
VideoExtension = _settingsService.Data.Common.DefaultTaskSettings.VideoExtension;
AudioExtension = _settingsService.Data.Common.DefaultTaskSettings.AudioExtension;
VideoExtension = _settingsService.Data.Common.Tasks.DefaultVideoExtension;
AudioExtension = _settingsService.Data.Common.Tasks.DefaultAudioExtension;
}
@@ -149,14 +141,14 @@ namespace VDownload.Core.ViewModels.Home
public void CreateTask()
{
_tasksManager.AddTask(_video, BuildDownloadOptions());
TaskAdded?.Invoke(this, EventArgs.Empty);
CloseRequested?.Invoke(this, EventArgs.Empty);
}
[RelayCommand]
public void CreateTaskAndDownload()
{
DownloadTask task = _tasksManager.AddTask(_video, BuildDownloadOptions());
TaskAdded?.Invoke(this, EventArgs.Empty);
CloseRequested?.Invoke(this, EventArgs.Empty);
task.Enqueue();
}
@@ -181,5 +173,13 @@ namespace VDownload.Core.ViewModels.Home
}
#endregion
#region EVENTS
public event EventHandler CloseRequested;
#endregion
}
}

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Core.Tasks;
using VDownload.Models;
using VDownload.Services.Data.Configuration;
using VDownload.Services.Data.Settings;
@@ -42,7 +43,10 @@ namespace VDownload.Core.ViewModels.Home
protected readonly IStringResourcesService _stringResourcesService;
protected readonly ISearchService _searchService;
protected readonly IDownloadTaskManager _downloadTaskManager;
protected readonly HomeVideoViewModel _videoViewModel;
protected readonly HomePlaylistViewModel _playlistViewModel;
#endregion
@@ -52,6 +56,7 @@ namespace VDownload.Core.ViewModels.Home
protected readonly Type _downloadsView = typeof(HomeDownloadsViewModel);
protected readonly Type _videoView = typeof(HomeVideoViewModel);
protected readonly Type _playlistView = typeof(HomePlaylistViewModel);
#endregion
@@ -96,15 +101,20 @@ namespace VDownload.Core.ViewModels.Home
#region CONSTRUCTORS
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, HomeVideoViewModel videoViewModel)
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, IDownloadTaskManager downloadTaskManager, HomeVideoViewModel videoViewModel, HomePlaylistViewModel playlistViewModel)
{
_configurationService = configurationService;
_settingsService = settingsService;
_stringResourcesService = stringResourcesService;
_searchService = searchService;
_downloadTaskManager = downloadTaskManager;
_videoViewModel = videoViewModel;
_videoViewModel.TaskAdded += VideoViewModel_TaskAdded;
_videoViewModel.CloseRequested += BackToDownload_EventHandler;
_playlistViewModel = playlistViewModel;
_playlistViewModel.CloseRequested += BackToDownload_EventHandler;
}
#endregion
@@ -195,7 +205,7 @@ namespace VDownload.Core.ViewModels.Home
return;
}
_videoViewModel.LoadVideo(video);
await _videoViewModel.LoadVideo(video);
MainContent = _videoView;
@@ -224,6 +234,10 @@ namespace VDownload.Core.ViewModels.Home
return;
}
await _playlistViewModel.LoadPlaylist(playlist);
MainContent = _playlistView;
OptionBarSearchNotPending = true;
OptionBarLoading = false;
OptionBarMessage = null;
@@ -232,7 +246,10 @@ namespace VDownload.Core.ViewModels.Home
[RelayCommand]
public void Download()
{
foreach (DownloadTask task in _downloadTaskManager.Tasks)
{
task.Enqueue();
}
}
#endregion
@@ -241,7 +258,7 @@ namespace VDownload.Core.ViewModels.Home
#region PRIVATE METHODS
private async void VideoViewModel_TaskAdded(object sender, EventArgs e) => await Navigation();
private async void BackToDownload_EventHandler(object sender, EventArgs e) => await Navigation();
#endregion
}