返回提交历史
Modified
XFENewsApplication.Core/Models/NewsSource.cs
+3
-3
Modified
XFENewsApplication.Test/Program.cs
+15
-15
Modified
XFENewsApplication/App.xaml.cs
+1
-0
Added
XFENewsApplication/ViewModels/HotSearchViewPageViewModel.cs
+6
-0
Modified
XFENewsApplication/ViewModels/NewsViewPageViewModel.cs
+97
-17
Added
XFENewsApplication/Views/HotSearchViewPage.xaml
+14
-0
Added
XFENewsApplication/Views/HotSearchViewPage.xaml.cs
+12
-0
Modified
XFENewsApplication/Views/NewsViewPage.xaml
+45
-4
Modified
XFENewsApplication/Views/NewsViewPage.xaml.cs
+1
-12
Modified
XFENewsApplication/XFENewsApplication.csproj
+6
-0
XFEstudio/XFENewsApplication
完善图片预览分享查看等机制
f8f9af5
代码差异
10 个文件
+200
-51
@@ -2,12 +2,12 @@
2
2
3
3
public class NewsSource
4
4
{
5
public required string Title { get; set; }
6
public required string Url { get; set; }
5
public string Title { get; set; } = string.Empty;
6
public string Url { get; set; } = string.Empty;
7
7
public string? ID { get; set; }
8
8
public string? Authors { get; set; }
9
9
public string? PublishTime { get; set; }
10
10
public string? Abstract { get; set; }
11
11
public string? ImageUrl { get; set; }
12
public required string Source { get; set; }
12
public string Source { get; set; } = string.Empty;
13
13
}
@@ -1,21 +1,21 @@
1
using HtmlAgilityPack;
1
using XFEExtension.NetCore.XFETransform.JsonConverter;
2
2
3
3
class Program
4
4
{
5
[SMTest("""
6
<p>1、《夏日之恋》</p><p>小说改编,小镇压抑女孩和富家女,拍的又清新又燥热,结尾sadie和河边很厉害,人家只是假日消遣过家家,你却死去活来以为真,古早的艾米莉布朗特。清澈,简洁,真实,晃动的镜头。也许因为是英音—— 中文的字幕错误多的一塌糊涂,全不得要领,一定要下载英文的字幕,不然会直接给电影拉低两颗星。 结尾的反转残酷也现实。</p><div><img data-reference=\"image\" data-document-id=\"cms/api/amp/image/AA1AXNbb\"></div><p>2、《火车上的女孩》</p><p>两位金发的女演员令人脸盲症发作,有点分不清楚,导演故作玄虚的剪辑更让人观影难度增加。结尾草率匆忙。不知道是否忠于原著,应该多点铺垫和人物行为逻辑。三个女演员非常捧。缺点是既忠于原著又不得不修改,因为原著的文学性加分,在电影上反而容易减分,不能直接用文学悬疑手法,电影应该增加悬疑度。线索也有点乱。总之看在主角表演不错。</p><div><img data-reference=\"image\" data-document-id=\"cms/api/amp/image/AA1AXPFO\"></div><p>3、《寂静之地》</p><p>很不错的一部影片,全片没几句台词,在寂静中烘托出了恐怖的氛围,全程紧张氛围满满,在恐怖的氛围下影片塑造的一家人同甘共苦的亲情也是让人感觉温暖,丈夫和妻子带着耳机翩翩起舞,父亲为女儿制作声音放大器耳麦等等,最后为了拯救孩子,父亲打着手语表达爱意都让人泪奔。</p><div><img data-reference=\"image\" data-document-id=\"cms/api/amp/image/AA1AXPFY\"></div><p>4、《明日边缘》</p><p>很有游戏感,循环死亡刷经验,打掉大boss获得自主读档的能力。“人”味的一面是主角的成长和爱情,但说真的,这种题材里的爱情线实在是千篇一律。动作戏好看,虽然是很老套的剧情,但是爆米花你能要求什么,不过汤姆 克鲁斯确实,这种硬汉很帅,结局的温情戏感觉没烘托出来,不过也算是好看的。</p><div><img data-reference=\"image\" data-document-id=\"cms/api/amp/image/AA1AXPG3\"></div><p>5、《边境杀手》</p><p>节奏把控很好,一直让人摸不透又悬着心。镜头很讲究,最后一场“地道战”在美丽的夕阳下,黑色的人影慢慢没入漆黑的大地,很棒!整体给人一种总有你想不到的黑暗隐藏在日常生活的表象下的感觉,就好像片头的尸体都藏在墙里。一定的留白给了人感慨和喘息的空间。</p><div><img data-reference=\"image\" data-document-id=\"cms/api/amp/image/AA1AXS3L\"></div><p>艾米莉·布朗特主演的5部电影,每部都值得细细品味!</p>
7
""")]
8
public static void TestMethod(string html)
5
//[SMTest]
6
public static string TestMethod()
9
7
{
10
var doc = new HtmlDocument();
11
doc.LoadHtml(html);
12
foreach (var node in doc.DocumentNode.Descendants())
13
{
14
if (node.Name == "img")
15
Console.WriteLine($"图片:{node.GetAttributeValue("data-document-id", string.Empty)}");
16
if (node.HasChildNodes)
17
continue;
18
Console.WriteLine(node.InnerText);
19
}
8
return Path.GetExtension("adwada.png");
9
}
10
11
[SMTest("attitude")]
12
public static async Task<List<string>> TestBaiduTranslate(string word)
13
{
14
using var client = new HttpClient();
15
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0");
16
var result = await client.PostAsync("https://fanyi.baidu.com/sug", new StringContent($"kw={word}"));
17
result.EnsureSuccessStatusCode();
18
QueryableJsonNode jsonNode = await result.Content.ReadAsStringAsync();
19
return [.. jsonNode["data"]["package:list", "k", "v"].PackageInListObject().Select(wordInfo => wordInfo["v"].ToString())];
20
20
}
21
21
}
@@ -21,6 +21,7 @@ public partial class App : Application
21
21
AppThemeHelper.Theme = SystemProfile.Theme;
22
22
PageManager.RegisterPage(typeof(AppShellPage));
23
23
PageManager.RegisterPage(typeof(NewsViewPage));
24
PageManager.RegisterPage(typeof(HotSearchViewPage));
24
25
PageManager.RegisterPage(typeof(SettingPage));
25
26
UnhandledException += App_UnhandledException;
26
27
}
@@ -0,0 +1,6 @@
1
namespace XFENewsApplication.ViewModels;
2
3
public partial class HotSearchViewPageViewModel : ViewModelBase
4
{
5
6
}
@@ -1,11 +1,13 @@
1
1
using CommunityToolkit.Mvvm.ComponentModel;
2
2
using CommunityToolkit.Mvvm.Input;
3
3
using Microsoft.UI.Text;
4
using Microsoft.UI.Xaml.Media;
5
4
using Microsoft.UI.Xaml.Media.Imaging;
6
5
using System.Collections.ObjectModel;
7
6
using System.Diagnostics;
8
7
using Windows.ApplicationModel.DataTransfer;
8
using Windows.Storage.Pickers;
9
using Windows.Storage.Streams;
10
using WinRT.Interop;
9
11
using XFEExtension.NetCore.StringExtension;
10
12
using XFEExtension.NetCore.WinUIHelper.Interface.Services;
11
13
using XFEExtension.NetCore.WinUIHelper.Utilities;
@@ -316,25 +318,23 @@ public partial class NewsViewPageViewModel : ViewModelBase
316
318
void Share()
317
319
{
318
320
var dataTransferManager = DataTransferManagerHelper.GetForWindow();
319
dataTransferManager.DataRequested += DataTransferManager_DataRequested;
320
DataTransferManagerHelper.ShowShareUIForWindow(WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow));
321
}
322
323
private void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
324
{
325
if (args.Request is DataRequest dataRequest)
321
dataTransferManager.DataRequested += (sender, args) =>
326
322
{
327
if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource)
328
{
329
dataRequest.Data.Properties.Title = newsSource.Title;
330
dataRequest.Data.Properties.Description = newsSource.Abstract;
331
dataRequest.Data.SetWebLink(new Uri(newsSource.Url));
332
}
333
else
323
if (args.Request is DataRequest dataRequest)
334
324
{
335
dataRequest.FailWithDisplayText("没有选中任何新闻");
325
if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource)
326
{
327
dataRequest.Data.Properties.Title = newsSource.Title;
328
dataRequest.Data.Properties.Description = newsSource.Abstract;
329
dataRequest.Data.SetWebLink(new Uri(newsSource.Url));
330
}
331
else
332
{
333
dataRequest.FailWithDisplayText("没有选中任何新闻");
334
}
336
335
}
337
}
336
};
337
DataTransferManagerHelper.ShowShareUIForWindow(WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow));
338
338
}
339
339
340
340
[RelayCommand]
@@ -363,4 +363,84 @@ public partial class NewsViewPageViewModel : ViewModelBase
363
363
}
364
364
}
365
365
}
366
367
[RelayCommand]
368
async Task ViewPicture(string imageUrl)
369
{
370
PreviewImageUrl = imageUrl;
371
if (await DialogService.ShowDialog("previewImageContentDialog") == ContentDialogResult.Primary)
372
{
373
await SavePicture(imageUrl);
374
}
375
}
376
377
[RelayCommand]
378
async Task SavePicture(string imageUrl)
379
{
380
var imageName = imageUrl.Split('/').Last();
381
var imageType = Path.HasExtension(imageName) ? Path.GetExtension(imageName) : ".png";
382
var savePicker = new FileSavePicker
383
{
384
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
385
DefaultFileExtension = imageType,
386
FileTypeChoices =
387
{
388
{ "PNG格式", new List<string> { ".png" } },
389
{ "JPG格式", new List<string> { ".jpg" } },
390
{ $"原格式-{imageType}", new List<string> { imageType } }
391
},
392
SuggestedFileName = $"{Path.GetFileNameWithoutExtension(imageName)}.png"
393
};
394
InitializeWithWindow.Initialize(savePicker, WindowNative.GetWindowHandle(App.MainWindow));
395
var file = await savePicker.PickSaveFileAsync();
396
if (file is not null)
397
{
398
using var client = new HttpClient();
399
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0");
400
var imageBytes = await client.GetByteArrayAsync(imageUrl);
401
using var stream = await file.OpenStreamForWriteAsync();
402
await stream.WriteAsync(imageBytes);
403
stream.Close();
404
MessageService?.ShowMessage($"已保存至:{file.Path}", "保存成功", null, InfoBarSeverity.Success, 5, true, "前往", (_, _) =>
405
{
406
Process.Start("explorer.exe", $"/select,\"{file.Path}\"");
407
});
408
}
409
}
410
411
[RelayCommand]
412
void SharePicture(string imageUrl)
413
{
414
var dataTransferManager = DataTransferManagerHelper.GetForWindow();
415
dataTransferManager.DataRequested += (sender, args) =>
416
{
417
if (args.Request is DataRequest dataRequest)
418
{
419
if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource)
420
{
421
dataRequest.Data.Properties.Title = newsSource.Title;
422
dataRequest.Data.Properties.Description = newsSource.Abstract;
423
dataRequest.Data.SetBitmap(RandomAccessStreamReference.CreateFromUri(new Uri(imageUrl)));
424
}
425
else
426
{
427
dataRequest.FailWithDisplayText("没有选中任何图片");
428
}
429
}
430
};
431
DataTransferManagerHelper.ShowShareUIForWindow(WindowNative.GetWindowHandle(App.MainWindow));
432
}
433
434
[RelayCommand]
435
static void ViewPictureInBrowser(string imageUrl)
436
{
437
if (imageUrl.IsNullOrEmpty())
438
return;
439
var uri = new Uri(imageUrl);
440
var processStartInfo = new ProcessStartInfo(uri.AbsoluteUri)
441
{
442
UseShellExecute = true
443
};
444
Process.Start(processStartInfo);
445
}
366
446
}
@@ -0,0 +1,14 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<Page
3
x:Class="XFENewsApplication.Views.HotSearchViewPage"
4
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6
xmlns:local="using:XFENewsApplication.Views"
7
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9
mc:Ignorable="d">
10
11
<Grid>
12
13
</Grid>
14
</Page>
@@ -0,0 +1,12 @@
1
namespace XFENewsApplication.Views;
2
3
/// <summary>
4
/// 热搜页面
5
/// </summary>
6
public sealed partial class HotSearchViewPage : Page
7
{
8
public HotSearchViewPage()
9
{
10
this.InitializeComponent();
11
}
12
}
@@ -8,15 +8,25 @@
8
8
xmlns:model="using:XFENewsApplication.Models"
9
9
xmlns:converter="using:XFEExtension.NetCore.WinUIHelper.Utilities.Converter"
10
10
xmlns:innerconverter="using:XFENewsApplication.Utilities.Converter"
11
xmlns:viewmodel="using:XFENewsApplication.ViewModels"
11
12
xmlns:selector="using:XFENewsApplication.Utilities.Selector"
12
13
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
13
14
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
14
15
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
15
16
mc:Ignorable="d">
17
<Page.Tag>
18
<StackPanel>
19
<Button x:Name="saveImageButton" Command="{x:Bind ViewModel.SavePictureCommand}"/>
20
<Button x:Name="previewImageButton" Command="{x:Bind ViewModel.ViewPictureCommand}"/>
21
<Button x:Name="shareImageButton" Command="{x:Bind ViewModel.SharePictureCommand}"/>
22
<Button x:Name="previewImageInBrowserButton" Command="{x:Bind ViewModel.ViewPictureInBrowserCommand}"/>
23
</StackPanel>
24
</Page.Tag>
16
25
<Page.Resources>
17
26
<converter:URLImageConverter x:Key="URLImageConverter"/>
18
27
<converter:StringFormatConverter x:Key="StringFormatConverter"/>
19
28
<innerconverter:StringEmptyVisibilityConverter x:Key="StringEmptyVisibilityConverter"/>
29
<viewmodel:NewsViewPageViewModel x:Key="ViewModel"/>
20
30
<DataTemplate x:Key="TextDataTemplate" x:DataType="model:TextArticlePart">
21
31
<TextBlock Margin="0,10" Text="{x:Bind Content}" FontSize="{x:Bind FontSize}" FontWeight="{x:Bind FontWeight}" TextWrapping="Wrap" IsTextSelectionEnabled="True"/>
22
32
</DataTemplate>
@@ -58,11 +68,26 @@
58
68
<Border Margin="1" CornerRadius="8" Background="{ThemeResource FocusStrokeColorOuterBrush}"/>
59
69
<Image MaxWidth="950" MaxHeight="500" Margin="10" Source="{Binding ElementName=imageFlipView, Path=SelectedItem, Converter={StaticResource URLImageConverter}}"/>
60
70
<Border MaxWidth="950" MaxHeight="500" CornerRadius="8" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}">
61
<FlipView x:Name="imageFlipView" ItemsSource="{x:Bind Images}" IsTapEnabled="True" Tapped="imageFlipView_Tapped">
71
<FlipView x:Name="imageFlipView" ItemsSource="{x:Bind Images}">
62
72
<FlipView.ItemTemplate>
63
73
<DataTemplate x:DataType="model:FlipImage">
64
74
<Grid>
65
<Image Source="{x:Bind ImageUrl, Converter={StaticResource URLImageConverter}}"/>
75
<Image Source="{x:Bind ImageUrl, Converter={StaticResource URLImageConverter}}">
76
<Image.ContextFlyout>
77
<CommandBarFlyout>
78
<AppBarButton Icon="BrowsePhotos" Label="查看图片" Command="{Binding ElementName=previewImageButton, Path=Command}" CommandParameter="{x:Bind ImageUrl}"/>
79
<AppBarButton Icon="Share" Label="分享图片" Command="{Binding ElementName=shareImageButton, Path=Command}" CommandParameter="{x:Bind ImageUrl}"/>
80
<AppBarButton Label="在浏览器中打开" Command="{Binding ElementName=previewImageInBrowserButton, Path=Command}" CommandParameter="{x:Bind ImageUrl}">
81
<AppBarButton.Icon>
82
<FontIcon Glyph=""/>
83
</AppBarButton.Icon>
84
</AppBarButton>
85
<CommandBarFlyout.SecondaryCommands>
86
<AppBarButton Icon="Save" Label="另存为" Command="{Binding ElementName=saveImageButton, Path=Command}" CommandParameter="{x:Bind ImageUrl}"/>
87
</CommandBarFlyout.SecondaryCommands>
88
</CommandBarFlyout>
89
</Image.ContextFlyout>
90
</Image>
66
91
<Border x:Name="infomationBorder" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}" PointerEntered="Border_PointerEntered" PointerExited="Border_PointerExited" VerticalAlignment="Bottom" Padding="10">
67
92
<Border.OpacityTransition>
68
93
<ScalarTransition/>
@@ -85,6 +110,20 @@
85
110
<Border Margin="1" CornerRadius="8" Background="{ThemeResource FocusStrokeColorOuterBrush}"/>
86
111
<Image MaxWidth="950" MaxHeight="950" Margin="10" Source="{x:Bind Content, Converter={StaticResource URLImageConverter}}"/>
87
112
<Border CornerRadius="8" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}">
113
<Border.ContextFlyout>
114
<CommandBarFlyout>
115
<AppBarButton Icon="BrowsePhotos" Label="查看图片" Command="{Binding ElementName=previewImageButton, Path=Command}" CommandParameter="{x:Bind Content}"/>
116
<AppBarButton Icon="Share" Label="分享图片" Command="{Binding ElementName=shareImageButton, Path=Command}" CommandParameter="{x:Bind Content}"/>
117
<AppBarButton Label="在浏览器中打开" Command="{Binding ElementName=previewImageInBrowserButton, Path=Command}" CommandParameter="{x:Bind Content}">
118
<AppBarButton.Icon>
119
<FontIcon Glyph=""/>
120
</AppBarButton.Icon>
121
</AppBarButton>
122
<CommandBarFlyout.SecondaryCommands>
123
<AppBarButton Icon="Save" Label="另存为" Command="{Binding ElementName=saveImageButton, Path=Command}" CommandParameter="{x:Bind Content}"/>
124
</CommandBarFlyout.SecondaryCommands>
125
</CommandBarFlyout>
126
</Border.ContextFlyout>
88
127
<StackPanel Orientation="Vertical" Spacing="10">
89
128
<Image Margin="10,10,10,0" MaxWidth="950" MaxHeight="950" Source="{x:Bind Content, Converter={StaticResource URLImageConverter}}"/>
90
129
<StackPanel Margin="2,0" Orientation="Horizontal" Spacing="10" Visibility="{x:Bind From, Converter={StaticResource StringEmptyVisibilityConverter}}">
@@ -104,8 +143,10 @@
104
143
<ColumnDefinition Width="Auto"/>
105
144
<ColumnDefinition/>
106
145
</Grid.ColumnDefinitions>
107
<ContentDialog x:Name="previewImageContentDialog" PrimaryButtonText="保存" SecondaryButtonText="取消">
108
<Image Source="{x:Bind ViewModel.PreviewImageUrl, Mode=OneWay, Converter={StaticResource URLImageConverter}}"/>
146
<ContentDialog x:Name="previewImageContentDialog" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PrimaryButtonText="保存" SecondaryButtonText="取消" DefaultButton="Secondary">
147
<ScrollViewer ZoomMode="Enabled" HorizontalScrollBarVisibility="Auto">
148
<Image Source="{x:Bind ViewModel.PreviewImageUrl, Mode=OneWay, Converter={StaticResource URLImageConverter}}" Stretch="Fill"/>
149
</ScrollViewer>
109
150
</ContentDialog>
110
151
<Border x:Name="sideBar" MinWidth="300" MaxWidth="800" Width="{x:Bind ViewModel.SideBarWidth, Mode=TwoWay}">
111
152
<Grid>
@@ -1,6 +1,4 @@
1
using Microsoft.UI.Xaml.Media;
2
using Microsoft.UI.Xaml.Navigation;
3
using XFENewsApplication.Models;
1
using Microsoft.UI.Xaml.Navigation;
4
2
5
3
namespace XFENewsApplication.Views;
6
4
@@ -48,13 +46,4 @@ public sealed partial class NewsViewPage : Page
48
46
if (sender is Border border)
49
47
border.Opacity = 1;
50
48
}
51
52
private void imageFlipView_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e)
53
{
54
if (e.OriginalSource is FrameworkElement image && image.DataContext is FlipImage imageSource)
55
{
56
ViewModel.PreviewImageUrl = imageSource.ImageUrl;
57
ViewModel.DialogService.ShowDialog("previewImageContentDialog");
58
}
59
}
60
49
}
@@ -18,6 +18,7 @@
18
18
<ItemGroup>
19
19
<None Remove="Assets\news.ico" />
20
20
<None Remove="Views\AppShellPage.xaml" />
21
<None Remove="Views\HotSearchViewPage.xaml" />
21
22
<None Remove="Views\NewsViewPage.xaml" />
22
23
<None Remove="Views\SettingPage.xaml" />
23
24
</ItemGroup>
@@ -70,6 +71,11 @@
70
71
<ItemGroup>
71
72
<ProjectReference Include="..\XFENewsApplication.Core\XFENewsApplication.Core.csproj" />
72
73
</ItemGroup>
74
<ItemGroup>
75
<Page Update="Views\HotSearchViewPage.xaml">
76
<Generator>MSBuild:Compile</Generator>
77
</Page>
78
</ItemGroup>
73
79
<ItemGroup>
74
80
<Page Update="Views\SettingPage.xaml">
75
81
<Generator>MSBuild:Compile</Generator>