Skip to content

Commit

Permalink
下载列表支持默认显示订阅中的名称
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Apr 14, 2023
1 parent 59c03a3 commit c2d12bf
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 10 deletions.
5 changes: 5 additions & 0 deletions WkyFast/Service/Model/DownloadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WkyApiSharp.Service.Model.BtCheck;
using WkyApiSharp.Service.Model.CreateTaskResult;

namespace WkyFast.Service.Model
{
Expand All @@ -21,5 +23,8 @@ public class WkyDownloadResult
public int DuplicateAddTaskCount { get; set; }


public WkyApiCreateTaskResultModel Result { get; set; }


}
}
6 changes: 6 additions & 0 deletions WkyFast/Service/Model/SubscriptionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace WkyFast.Service.Model.SubscriptionModel
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using WkyApiSharp.Service.Model;
using WkyApiSharp.Service.Model.BtCheck;
using WkyApiSharp.Service.Model.CreateTaskResult;

public partial class SubscriptionModel : BaseNotificationModel
{
Expand Down Expand Up @@ -104,6 +106,10 @@ public partial class SubscriptionSubTaskModel : BaseNotificationModel

[JsonProperty("Time")]
public DateTime Time { get; set; }

[JsonProperty("Result")]
public WkyApiCreateTaskResultModel Result { get; set; }

}

public partial class SubscriptionModel
Expand Down
63 changes: 63 additions & 0 deletions WkyFast/Service/Model/TaskModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,76 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace WkyFast.Service.Model
{


public class TaskModel : BaseNotificationModel
{
//获取展示用的名字

public bool FromSubscription
{
get
{
return SubscriptionManager.Instance.TaskUrlToSubscriptionName.ContainsKey(Data.Url);
}

}

public string ShowName {
get
{
if (FromSubscription)
{
if (SubscriptionManager.Instance.TaskUrlToSubscriptionName.ContainsKey(Data.Url))
{
var name = (string)SubscriptionManager.Instance.TaskUrlToSubscriptionName[Data.Url];
if (!string.IsNullOrWhiteSpace(name))
{
return name;
}
}
return Data.Name;

}
else
{
return Data.Name;
}


}
}

public string SubscriptionName
{
get
{
if (FromSubscription)
{
if (SubscriptionManager.Instance.TaskUrlToSubscriptionName.ContainsKey(Data.Name))
{
var name = (string)SubscriptionManager.Instance.TaskUrlToSubscriptionName[Data.Name];
if (!string.IsNullOrWhiteSpace(name))
{
return name;
}
}
return Data.Name;

}
else
{
return Data.Name;
}


}
}

public WkyApiSharp.Service.Model.RemoteDownloadList.Task Data { get; set; }
}
}
47 changes: 45 additions & 2 deletions WkyFast/Service/SubscriptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using WkyFast.Service.Model.SubscriptionModel;
using System.Text.RegularExpressions;
using WkyApiSharp.Service.Model;
using System.Collections;

namespace WkyFast.Service
{
Expand Down Expand Up @@ -57,6 +58,7 @@ public static SubscriptionManager Instance

public ObservableCollection<SubscriptionModel> SubscriptionModel { get; set; } = new ObservableCollection<SubscriptionModel>();

public Hashtable TaskUrlToSubscriptionName { get; set; } = new Hashtable();

public SubscriptionManager()
{
Expand Down Expand Up @@ -192,6 +194,29 @@ private int GetMatchTaskCount(IEnumerable<SyndicationItem> Items, SubscriptionMo

}


public string GetSubscriptionName(string downloadName)
{
foreach (var sub in SubscriptionModel)
{
foreach (var model in sub.AlreadyAddedDownloadModel)
{
if (model.Result != null && model.Result.Tasks.Count() > 0)
{
foreach (var task in model.Result.Tasks)
{
if (task.Name == downloadName)
{
return model.Name;
}
}

}
}
}
return "";
}

/// <summary>
/// 通过网络获取订阅地址的Title
/// </summary>
Expand Down Expand Up @@ -307,14 +332,21 @@ private void CheckSubscription()

var addResult = WkyApiManager.Instance.DownloadBtFileUrl(downloadUrl, subscription.Device, savePath).Result;

var taskUrl = addResult?.Result?.Tasks?.FirstOrDefault()?.Url;
if (!string.IsNullOrWhiteSpace(taskUrl))
{
TaskUrlToSubscriptionName[taskUrl] = subject;
}


if (addResult.SuccessCount > 0)
{
subscription.AlreadyAddedDownloadModel.Add(new SubscriptionSubTaskModel() { Name = subject, Url = downloadUrl, Time = DateTime.Now} );
subscription.AlreadyAddedDownloadModel.Add(new SubscriptionSubTaskModel() { Name = subject, Url = downloadUrl, Time = DateTime.Now, Result = addResult.Result } );
EasyLogManager.Logger.Info($"添加成功");
}
else if (addResult.DuplicateAddTaskCount > 0)
{
subscription.AlreadyAddedDownloadModel.Add(new SubscriptionSubTaskModel() { Name = subject, Url = downloadUrl, Time = DateTime.Now });
subscription.AlreadyAddedDownloadModel.Add(new SubscriptionSubTaskModel() { Name = subject, Url = downloadUrl, Time = DateTime.Now, Result = addResult.Result });
EasyLogManager.Logger.Info($"成功,任务已经存在,不再重复添加");
}
else
Expand Down Expand Up @@ -371,6 +403,17 @@ public void Load()
foreach (SubscriptionModel item in subscriptionModel)
{
SubscriptionModel.Add(item);

//加载名称表
foreach (var m in item.AlreadyAddedDownloadModel)
{
var taskUrl = m.Result?.Tasks?.FirstOrDefault()?.Url;
if (!string.IsNullOrWhiteSpace(taskUrl))
{
TaskUrlToSubscriptionName[taskUrl] = m.Name;
}

}
}
}

Expand Down
1 change: 1 addition & 0 deletions WkyFast/Service/WkyApiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public async Task<WkyDownloadResult> DownloadBtFileUrl(string url, WkyDevice dev
var result = await _api?.CreateTaskWithBtCheck(wkyDevice.Device.Peerid, path, bcCheck);
if (result.Rtn == 0)
{
downloadResult.Result = result;
downloadResult.AllTaskCount = result.Tasks.Length;
foreach (var item in result.Tasks)
{
Expand Down
20 changes: 20 additions & 0 deletions WkyFast/View/Contver/DownloadSizeContver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,24 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
}
}


[ValueConversion(typeof(bool), typeof(Visibility))]
public class BoolVisibilityConverter : IValueConverter
{

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || (bool)value == false )
{
return Visibility.Collapsed;
}
return Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

}
29 changes: 27 additions & 2 deletions WkyFast/View/View/TaskListCellControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<converter:DownloadSpeedVisibilityConverter x:Key="DownloadSpeedVisibilityConverter"/>
<converter:DownloadStatusBrushContver x:Key="DownloadStatusBrushContver"/>
<converter:ExistVisibilityConverter x:Key="ExistVisibilityConverter"/>
<converter:BoolVisibilityConverter x:Key="BoolVisibilityConverter"/>



Expand Down Expand Up @@ -61,7 +62,11 @@
</Grid>

<StackPanel Margin="2,2" Grid.Column="0">
<TextBlock Text="{Binding Data.Name}"></TextBlock>
<TextBlock Text="{Binding ShowName}">
<TextBlock.ToolTip>
<TextBlock Text="{Binding Data.Name}" TextWrapping="WrapWithOverflow"></TextBlock>
</TextBlock.ToolTip>
</TextBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Border CornerRadius="4" Height="18" MinWidth="40"
Background="{Binding Data.State, Converter={StaticResource DownloadStatusBrushContver}}">
Expand All @@ -79,7 +84,27 @@
</TextBlock>
</Border>


<Border Margin="5,0,0,0" BorderThickness="1" BorderBrush="#91D5FF" CornerRadius="4" Height="18" MinWidth="40" Background="#E6F7FF" Visibility="{Binding FromSubscription, Converter={StaticResource BoolVisibilityConverter}}">
<!--<Border.Visibility >
<MultiBinding Converter="{StaticResource ExistVisibilityConverter}">
<Binding Path="Data.Exist"/>
<Binding Path="Data.State"/>
</MultiBinding>
</Border.Visibility>-->
<TextBlock Text="订阅" Foreground="#1890FF" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4,0,4,0">
<TextBlock.Style>
<Style TargetType="TextBlock" >
<Setter Property="Foreground" Value="#FFFFFF" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource= {RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True">
<Setter Property="Foreground" Value="#FFFFFF" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>

<Border Margin="5,0,0,0" CornerRadius="4" Height="18" MinWidth="40" Background="#DCDEE2" >
<Border.Visibility>
<MultiBinding Converter="{StaticResource ExistVisibilityConverter}">
Expand Down
6 changes: 0 additions & 6 deletions WkyFast/View/WkySubscriptionListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Border CornerRadius="4" >

<Border.ToolTip >

<ToolTip Background="#00000000" BorderBrush="#00000000" ToolTipService.ShowOnDisabled="True" ToolTipService.HasDropShadow="True">
<ToolTip.Template>
<ControlTemplate TargetType="{x:Type ToolTip}">
<Border Background="White" CornerRadius="5" BorderThickness="1" BorderBrush="#20000000" >
<!-- ToolTip内容 -->
<Border CornerRadius="4" Padding="5,5,5,5" >
<Border.Style>
<Style TargetType="Border" >
Expand All @@ -91,9 +88,6 @@
<TextBlock Text="最近下载"></TextBlock>
<TextBlock Text="{Binding LastSubscriptionContent}" TextWrapping="Wrap"></TextBlock>
</StackPanel>



</Border>
</Border>
</ControlTemplate>
Expand Down
Binary file modified docs/images/wkyfast1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c2d12bf

Please sign in to comment.