metered connection warnings added
This commit is contained in:
@@ -7,6 +7,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.Tasks;
|
||||
using VDownload.Services.UI.Dialogs;
|
||||
using VDownload.Services.UI.StringResources;
|
||||
using VDownload.Services.Utility.Network;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
@@ -16,6 +19,10 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
protected readonly IDownloadTaskManager _tasksManager;
|
||||
|
||||
protected readonly INetworkService _networkService;
|
||||
protected readonly IDialogsService _dialogsService;
|
||||
protected readonly IStringResourcesService _stringResourcesService;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -33,11 +40,15 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public HomeDownloadsViewModel(IDownloadTaskManager tasksManager)
|
||||
public HomeDownloadsViewModel(IDownloadTaskManager tasksManager, INetworkService networkService, IDialogsService dialogsService, IStringResourcesService stringResourcesService)
|
||||
{
|
||||
_tasksManager = tasksManager;
|
||||
_tasksManager.TaskCollectionChanged += Tasks_CollectionChanged;
|
||||
|
||||
_networkService = networkService;
|
||||
_dialogsService = dialogsService;
|
||||
_stringResourcesService = stringResourcesService;
|
||||
|
||||
_taskListIsEmpty = _tasksManager.Tasks.Count == 0;
|
||||
}
|
||||
|
||||
@@ -59,7 +70,19 @@ namespace VDownload.Core.ViewModels.Home
|
||||
];
|
||||
if (idleStatuses.Contains(task.Status))
|
||||
{
|
||||
task.Enqueue();
|
||||
bool continueEnqueue = true;
|
||||
if (_networkService.IsMetered)
|
||||
{
|
||||
string title = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogTitle");
|
||||
string message = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogMessage");
|
||||
DialogResultYesNo result = await _dialogsService.ShowYesNo(title, message);
|
||||
continueEnqueue = result == DialogResultYesNo.Yes;
|
||||
}
|
||||
|
||||
if (continueEnqueue)
|
||||
{
|
||||
task.Enqueue();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -17,6 +17,9 @@ 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 VDownload.Services.Utility.Network;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
@@ -29,6 +32,9 @@ namespace VDownload.Core.ViewModels.Home
|
||||
protected readonly ISettingsService _settingsService;
|
||||
protected readonly IStoragePickerService _storagePickerService;
|
||||
protected readonly IFilenameService _filenameService;
|
||||
protected readonly INetworkService _networkService;
|
||||
protected readonly IDialogsService _dialogsService;
|
||||
protected readonly IStringResourcesService _stringResourcesService;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -174,12 +180,15 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public HomePlaylistViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService)
|
||||
public HomePlaylistViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, INetworkService networkService, IDialogsService dialogsService, IStringResourcesService stringResourcesService)
|
||||
{
|
||||
_tasksManager = tasksManager;
|
||||
_settingsService = settingsService;
|
||||
_storagePickerService = storagePickerService;
|
||||
_filenameService = filenameService;
|
||||
_networkService = networkService;
|
||||
_dialogsService = dialogsService;
|
||||
_stringResourcesService = stringResourcesService;
|
||||
|
||||
_removedVideos = new List<VideoViewModel>();
|
||||
|
||||
@@ -271,10 +280,10 @@ namespace VDownload.Core.ViewModels.Home
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void CreateTasksAndDownload() => CreateTasks(true);
|
||||
public async Task CreateTasksAndDownload() => await CreateTasks(true);
|
||||
|
||||
[RelayCommand]
|
||||
public void CreateTasks() => CreateTasks(false);
|
||||
public async Task CreateTasks() => await CreateTasks(false);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -282,8 +291,16 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected void CreateTasks(bool download)
|
||||
protected async Task CreateTasks(bool download)
|
||||
{
|
||||
if (download && _networkService.IsMetered)
|
||||
{
|
||||
string title = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogTitle");
|
||||
string message = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogMessage");
|
||||
DialogResultYesNo result = await _dialogsService.ShowYesNo(title, message);
|
||||
download = result == DialogResultYesNo.Yes;
|
||||
}
|
||||
|
||||
IEnumerable<VideoViewModel> videos = Videos.Cast<ObservableKeyValuePair<VideoViewModel, bool>>()
|
||||
.Where(x => x.Value)
|
||||
.Select(x => x.Key);
|
||||
|
||||
@@ -10,8 +10,11 @@ using System.Threading.Tasks;
|
||||
using VDownload.Core.Tasks;
|
||||
using VDownload.Models;
|
||||
using VDownload.Services.Data.Settings;
|
||||
using VDownload.Services.UI.Dialogs;
|
||||
using VDownload.Services.UI.StoragePicker;
|
||||
using VDownload.Services.UI.StringResources;
|
||||
using VDownload.Services.Utility.Filename;
|
||||
using VDownload.Services.Utility.Network;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
@@ -24,6 +27,9 @@ namespace VDownload.Core.ViewModels.Home
|
||||
protected readonly ISettingsService _settingsService;
|
||||
protected readonly IStoragePickerService _storagePickerService;
|
||||
protected readonly IFilenameService _filenameService;
|
||||
protected readonly INetworkService _networkService;
|
||||
protected readonly IDialogsService _dialogsService;
|
||||
protected readonly IStringResourcesService _stringResourcesService;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -91,12 +97,15 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public HomeVideoViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService)
|
||||
public HomeVideoViewModel(IDownloadTaskManager tasksManager, ISettingsService settingsService, IStoragePickerService storagePickerService, IFilenameService filenameService, INetworkService networkService, IDialogsService dialogsService, IStringResourcesService stringResourcesService)
|
||||
{
|
||||
_tasksManager = tasksManager;
|
||||
_settingsService = settingsService;
|
||||
_storagePickerService = storagePickerService;
|
||||
_filenameService = filenameService;
|
||||
_networkService = networkService;
|
||||
_dialogsService = dialogsService;
|
||||
_stringResourcesService = stringResourcesService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -141,19 +150,10 @@ namespace VDownload.Core.ViewModels.Home
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void CreateTask()
|
||||
{
|
||||
_tasksManager.AddTask(_video, BuildDownloadOptions());
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
public async Task CreateTask() => await CreateTask(false);
|
||||
|
||||
[RelayCommand]
|
||||
public void CreateTaskAndDownload()
|
||||
{
|
||||
DownloadTask task = _tasksManager.AddTask(_video, BuildDownloadOptions());
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
task.Enqueue();
|
||||
}
|
||||
public async Task CreateTaskAndDownload() => await CreateTask(true);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -161,6 +161,24 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected async Task CreateTask(bool download)
|
||||
{
|
||||
if (download && _networkService.IsMetered)
|
||||
{
|
||||
string title = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogTitle");
|
||||
string message = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogMessage");
|
||||
DialogResultYesNo result = await _dialogsService.ShowYesNo(title, message);
|
||||
download = result == DialogResultYesNo.Yes;
|
||||
}
|
||||
|
||||
DownloadTask task = _tasksManager.AddTask(_video, BuildDownloadOptions());
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
if (download)
|
||||
{
|
||||
task.Enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
protected VideoDownloadOptions BuildDownloadOptions()
|
||||
{
|
||||
return new VideoDownloadOptions(Duration)
|
||||
|
||||
@@ -9,9 +9,12 @@ using VDownload.Core.Tasks;
|
||||
using VDownload.Models;
|
||||
using VDownload.Services.Data.Configuration;
|
||||
using VDownload.Services.Data.Settings;
|
||||
using VDownload.Services.UI.Dialogs;
|
||||
using VDownload.Services.UI.StringResources;
|
||||
using VDownload.Services.Utility.Network;
|
||||
using VDownload.Sources;
|
||||
using VDownload.Sources.Common;
|
||||
using VDownload.Sources.Twitch.Configuration.Models;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
@@ -49,6 +52,8 @@ namespace VDownload.Core.ViewModels.Home
|
||||
protected readonly ISettingsService _settingsService;
|
||||
protected readonly IStringResourcesService _stringResourcesService;
|
||||
protected readonly ISearchService _searchService;
|
||||
protected readonly INetworkService _networkService;
|
||||
protected readonly IDialogsService _dialogsService;
|
||||
|
||||
protected readonly IDownloadTaskManager _downloadTaskManager;
|
||||
|
||||
@@ -108,12 +113,14 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, IDownloadTaskManager downloadTaskManager, HomeVideoViewModel videoViewModel, HomePlaylistViewModel playlistViewModel)
|
||||
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, INetworkService networkService, IDialogsService dialogsService, IDownloadTaskManager downloadTaskManager, HomeVideoViewModel videoViewModel, HomePlaylistViewModel playlistViewModel)
|
||||
{
|
||||
_configurationService = configurationService;
|
||||
_settingsService = settingsService;
|
||||
_stringResourcesService = stringResourcesService;
|
||||
_searchService = searchService;
|
||||
_networkService = networkService;
|
||||
_dialogsService = dialogsService;
|
||||
|
||||
_downloadTaskManager = downloadTaskManager;
|
||||
|
||||
@@ -258,8 +265,19 @@ namespace VDownload.Core.ViewModels.Home
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Download()
|
||||
public async Task Download()
|
||||
{
|
||||
if (_downloadTaskManager.Tasks.Count > 0 && _networkService.IsMetered)
|
||||
{
|
||||
string title = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogTitle");
|
||||
string message = _stringResourcesService.CommonResources.Get("StartAtMeteredConnectionDialogMessage");
|
||||
DialogResultYesNo result = await _dialogsService.ShowYesNo(title, message);
|
||||
if (result == DialogResultYesNo.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DownloadTask task in _downloadTaskManager.Tasks)
|
||||
{
|
||||
task.Enqueue();
|
||||
|
||||
Reference in New Issue
Block a user