向下载管理页面添加弹窗提示

croire 3 years ago
parent 76c968ac39
commit 568851bfaa

@ -14,6 +14,7 @@ using DownKyi.Views.Settings;
using DownKyi.Views.Toolbox; using DownKyi.Views.Toolbox;
using DownKyi.Views.UserSpace; using DownKyi.Views.UserSpace;
using Prism.Ioc; using Prism.Ioc;
using Prism.Services.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;

@ -299,6 +299,8 @@
<system:String x:Key="Allow">确定</system:String> <system:String x:Key="Allow">确定</system:String>
<system:String x:Key="Cancel">取消</system:String> <system:String x:Key="Cancel">取消</system:String>
<system:String x:Key="ConfirmDelete">您确定要删除吗?</system:String>
<system:String x:Key="SelectDirectory">请选择文件夹</system:String> <system:String x:Key="SelectDirectory">请选择文件夹</system:String>
<!-- ViewDownloadSetter --> <!-- ViewDownloadSetter -->

@ -53,6 +53,10 @@ namespace DownKyi.Services
private ButtonResult ShowMessage(VectorImage image, string type, string message) private ButtonResult ShowMessage(VectorImage image, string type, string message)
{ {
ButtonResult result = ButtonResult.None; ButtonResult result = ButtonResult.None;
if (dialogService == null)
{
return result;
}
DialogParameters param = new DialogParameters DialogParameters param = new DialogParameters
{ {

@ -2,6 +2,7 @@
using DownKyi.Core.BiliApi.Zone; using DownKyi.Core.BiliApi.Zone;
using DownKyi.Models; using DownKyi.Models;
using Prism.Mvvm; using Prism.Mvvm;
using Prism.Services.Dialogs;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
@ -9,6 +10,18 @@ namespace DownKyi.ViewModels.DownloadManager
{ {
public class DownloadBaseItem : BindableBase public class DownloadBaseItem : BindableBase
{ {
public IDialogService DialogService;
public DownloadBaseItem()
{
DialogService = null;
}
public DownloadBaseItem(IDialogService dialogService)
{
DialogService = dialogService;
}
// model数据 // model数据
private DownloadBase downloadBase; private DownloadBase downloadBase;
public DownloadBase DownloadBase public DownloadBase DownloadBase

@ -1,14 +1,20 @@
using DownKyi.Images; using DownKyi.Images;
using DownKyi.Models; using DownKyi.Models;
using DownKyi.Services;
using DownKyi.Utils; using DownKyi.Utils;
using Prism.Commands; using Prism.Commands;
using Prism.Services.Dialogs;
using System.IO; using System.IO;
namespace DownKyi.ViewModels.DownloadManager namespace DownKyi.ViewModels.DownloadManager
{ {
public class DownloadedItem : DownloadBaseItem public class DownloadedItem : DownloadBaseItem
{ {
public DownloadedItem() : base() public DownloadedItem() : this(null)
{
}
public DownloadedItem(IDialogService dialogService) : base(dialogService)
{ {
// 打开文件夹按钮 // 打开文件夹按钮
OpenFolder = ButtonIcon.Instance().Folder; OpenFolder = ButtonIcon.Instance().Folder;
@ -131,6 +137,13 @@ namespace DownKyi.ViewModels.DownloadManager
/// </summary> /// </summary>
private void ExecuteRemoveVideoCommand() private void ExecuteRemoveVideoCommand()
{ {
AlertService alertService = new AlertService(DialogService);
ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
if (result != ButtonResult.OK)
{
return;
}
App.DownloadedList.Remove(this); App.DownloadedList.Remove(this);
} }

@ -1,14 +1,20 @@
using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Images; using DownKyi.Images;
using DownKyi.Models; using DownKyi.Models;
using DownKyi.Services;
using DownKyi.Utils; using DownKyi.Utils;
using Prism.Commands; using Prism.Commands;
using Prism.Services.Dialogs;
namespace DownKyi.ViewModels.DownloadManager namespace DownKyi.ViewModels.DownloadManager
{ {
public class DownloadingItem : DownloadBaseItem public class DownloadingItem : DownloadBaseItem
{ {
public DownloadingItem() : base() public DownloadingItem() : this(null)
{
}
public DownloadingItem(IDialogService dialogService) : base(dialogService)
{ {
// 暂停继续按钮 // 暂停继续按钮
StartOrPause = ButtonIcon.Instance().Pause; StartOrPause = ButtonIcon.Instance().Pause;
@ -211,6 +217,13 @@ namespace DownKyi.ViewModels.DownloadManager
/// </summary> /// </summary>
private void ExecuteDeleteCommand() private void ExecuteDeleteCommand()
{ {
AlertService alertService = new AlertService(DialogService);
ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
if (result != ButtonResult.OK)
{
return;
}
App.DownloadingList.Remove(this); App.DownloadingList.Remove(this);
} }

@ -1,9 +1,14 @@
using DownKyi.Core.Settings; using DownKyi.Core.Settings;
using DownKyi.Services;
using DownKyi.Utils;
using Prism.Commands; using Prism.Commands;
using Prism.Events; using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -31,10 +36,27 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion #endregion
public ViewDownloadFinishedViewModel(IEventAggregator eventAggregator) : base(eventAggregator) public ViewDownloadFinishedViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService)
{ {
// 初始化DownloadedList // 初始化DownloadedList
DownloadedList = App.DownloadedList; DownloadedList = App.DownloadedList;
DownloadedList.CollectionChanged += new NotifyCollectionChangedEventHandler(async (object sender, NotifyCollectionChangedEventArgs e) =>
{
await Task.Run(() =>
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (var item in DownloadedList)
{
if (item != null && item.DialogService == null)
{
item.DialogService = dialogService;
}
}
}
});
});
SetDialogService();
DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort(); DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort();
switch (finishedSort) switch (finishedSort)
@ -95,6 +117,13 @@ namespace DownKyi.ViewModels.DownloadManager
/// </summary> /// </summary>
private async void ExecuteClearAllDownloadedCommand() private async void ExecuteClearAllDownloadedCommand()
{ {
AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
if (result != ButtonResult.OK)
{
return;
}
// 使用Clear()不能触发NotifyCollectionChangedAction.Remove事件 // 使用Clear()不能触发NotifyCollectionChangedAction.Remove事件
// 因此遍历删除 // 因此遍历删除
// DownloadingList中元素被删除后不能继续遍历 // DownloadingList中元素被删除后不能继续遍历
@ -113,5 +142,26 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion #endregion
private async void SetDialogService()
{
await Task.Run(() =>
{
foreach (var item in DownloadedList)
{
if (item != null && item.DialogService == null)
{
item.DialogService = dialogService;
}
}
});
}
public override void OnNavigatedFrom(NavigationContext navigationContext)
{
base.OnNavigatedFrom(navigationContext);
SetDialogService();
}
} }
} }

@ -1,11 +1,15 @@
using DownKyi.Images; using DownKyi.Images;
using DownKyi.Models; using DownKyi.Models;
using DownKyi.Services;
using DownKyi.Utils; using DownKyi.Utils;
using Prism.Commands; using Prism.Commands;
using Prism.Events; using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -26,10 +30,28 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion #endregion
public ViewDownloadingViewModel(IEventAggregator eventAggregator) : base(eventAggregator) public ViewDownloadingViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService)
{ {
// 初始化DownloadingList // 初始化DownloadingList
DownloadingList = App.DownloadingList; DownloadingList = App.DownloadingList;
DownloadingList.CollectionChanged += new NotifyCollectionChangedEventHandler(async (object sender, NotifyCollectionChangedEventArgs e) =>
{
await Task.Run(() =>
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (var item in DownloadingList)
{
if (item != null && item.DialogService == null)
{
item.DialogService = dialogService;
}
}
}
});
});
SetDialogService();
} }
#region 命令申明 #region 命令申明
@ -133,6 +155,13 @@ namespace DownKyi.ViewModels.DownloadManager
/// </summary> /// </summary>
private async void ExecuteDeleteAllDownloadingCommand() private async void ExecuteDeleteAllDownloadingCommand()
{ {
AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
if (result != ButtonResult.OK)
{
return;
}
// 使用Clear()不能触发NotifyCollectionChangedAction.Remove事件 // 使用Clear()不能触发NotifyCollectionChangedAction.Remove事件
// 因此遍历删除 // 因此遍历删除
// DownloadingList中元素被删除后不能继续遍历 // DownloadingList中元素被删除后不能继续遍历
@ -151,5 +180,26 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion #endregion
private async void SetDialogService()
{
await Task.Run(() =>
{
foreach (var item in DownloadingList)
{
if (item != null && item.DialogService == null)
{
item.DialogService = dialogService;
}
}
});
}
public override void OnNavigatedFrom(NavigationContext navigationContext)
{
base.OnNavigatedFrom(navigationContext);
SetDialogService();
}
} }
} }

Loading…
Cancel
Save