From 90c6aa58361c952102eaa99cb931ef0f18e47f19 Mon Sep 17 00:00:00 2001 From: ProJend Date: Tue, 11 Apr 2023 20:57:31 +0800 Subject: [PATCH] Bump v0.4 --- README.md | 2 +- TrueLove.Lib/Models/Code/CommentItem.cs | 8 ++- TrueLove.UWP/Package.appxmanifest | 6 +- TrueLove.UWP/Spider/RefineData.cs | 81 ++++++++++++++----------- TrueLove.UWP/Views/CommentsPage.xaml.cs | 19 +++--- TrueLove.UWP/Views/ImagesPage.xaml.cs | 6 +- 6 files changed, 65 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 097481e..3636f6b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # True Love ### About This APP -A UWP covering for Avicii website. +A UWP cover for Avicii website. ### About Avicii Tim Bergling (8 September 1989 – 20 April 2018), better known by his stage name Avicii, was a Swedish DJ, remixer, record producer, musician, and songwriter who specialized in audio programming, remixing, and record producing. diff --git a/TrueLove.Lib/Models/Code/CommentItem.cs b/TrueLove.Lib/Models/Code/CommentItem.cs index 7875526..9705789 100644 --- a/TrueLove.Lib/Models/Code/CommentItem.cs +++ b/TrueLove.Lib/Models/Code/CommentItem.cs @@ -1,13 +1,15 @@ -namespace TrueLove.Lib.Models.Code +using System.Collections.ObjectModel; + +namespace TrueLove.Lib.Models.Code { - public class CommentItem + public class CommentItem : ObservableCollection { public string name { get; set; } public string comment { get; set; } public string date { get; set; } } - public class CommentManager + public class UpdateItem { } diff --git a/TrueLove.UWP/Package.appxmanifest b/TrueLove.UWP/Package.appxmanifest index e505ba5..0d5324e 100644 --- a/TrueLove.UWP/Package.appxmanifest +++ b/TrueLove.UWP/Package.appxmanifest @@ -1,9 +1,9 @@  - + - True Love - Tim Bergling Foundtion + True Love ProJend Assets\StoreLogo.png @@ -15,7 +15,7 @@ - + diff --git a/TrueLove.UWP/Spider/RefineData.cs b/TrueLove.UWP/Spider/RefineData.cs index 7c695e6..ca8524d 100644 --- a/TrueLove.UWP/Spider/RefineData.cs +++ b/TrueLove.UWP/Spider/RefineData.cs @@ -1,6 +1,6 @@ using HtmlAgilityPack; using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; using TrueLove.Lib.Models.Code; using Windows.UI.Xaml.Media.Imaging; @@ -8,54 +8,65 @@ namespace TrueLove.UWP.Spider { public class RefineData { - public RefineData() + public ObservableCollection UpdateComment(string src) { - - } - public List RefineComment(string src) - { - var htmlDocument = new HtmlDocument(); - htmlDocument.LoadHtml(src); - List currentList = new List(); - for (int i = 1; i <= 99; i++) + var currentList = new ObservableCollection(); + try { - string namePath = $"//*[@id=\"commentlist\"]/ul/li[{i}]/p[1]/span"; - string comPath = $"//*[@id=\"commentlist\"]/ul/li[{i}]/p[2]"; - string datePath = $"//*[@id=\"commentlist\"]/ul/li[{i}]/p[3]"; + var htmlDocument = new HtmlDocument(); + htmlDocument.LoadHtml(src); + for (int i = 1; i <= 96; i++) + { + string namePath = $"//*[@id=\"commentlist\"]/ul/li[{i}]/p[1]/span"; + string comPath = $"//*[@id=\"commentlist\"]/ul/li[{i}]/p[2]"; + string datePath = $"//*[@id=\"commentlist\"]/ul/li[{i}]/p[3]"; - var nameText = htmlDocument.DocumentNode.SelectSingleNode(namePath).InnerText; - var comText = htmlDocument.DocumentNode.SelectSingleNode(comPath).InnerText; - var dateText = htmlDocument.DocumentNode.SelectSingleNode(datePath).InnerText; - var parsedDate = DateTime.Parse(dateText); + var nameText = htmlDocument.DocumentNode.SelectSingleNode(namePath).InnerText; + var comText = htmlDocument.DocumentNode.SelectSingleNode(comPath).InnerText; + var dateText = htmlDocument.DocumentNode.SelectSingleNode(datePath).InnerText; + var parsedDate = DateTime.Parse(dateText); - if (new[] { nameText, comText, dateText } != null) - { - currentList.Add(new CommentItem + if (new[] { nameText, comText, dateText } != null) { - name = nameText, - comment = comText, - date = parsedDate.ToString("d"), - }); + currentList.Add(new CommentItem + { + name = nameText, + comment = comText, + date = parsedDate.ToString("d"), + }); + } } + return currentList; + } + catch (NullReferenceException) + { + return currentList; } - return currentList; } - public List RefineImage(string src) + public ObservableCollection UpdateImage(string src) { - var htmlDocument = new HtmlDocument(); - htmlDocument.LoadHtml(src); - List currentList = new List(); - for (int i = 1; i <= 50; i++) + var currentList = new ObservableCollection(); + try { - string imagePath = $"//*[@id=\"instagramhashtag\"]/ul/li[{i}]/img"; + var htmlDocument = new HtmlDocument(); + htmlDocument.LoadHtml(src); - var imageNode = htmlDocument.DocumentNode.SelectSingleNode(imagePath); - if (imageNode != null) + for (int i = 1; i <= 50; i++) { - currentList.Add(new BitmapImage(new Uri("https://avicii.com" + imageNode.Attributes["src"].Value))); + string imagePath = $"//*[@id=\"instagramhashtag\"]/ul/li[{i}]/img"; + + var imageNode = htmlDocument.DocumentNode.SelectSingleNode(imagePath); + if (imageNode != null) + { + currentList.Add(new BitmapImage(new Uri("https://avicii.com" + imageNode.Attributes["src"].Value))); + } } + return currentList; + } + catch + { + return currentList; } - return currentList; } } } diff --git a/TrueLove.UWP/Views/CommentsPage.xaml.cs b/TrueLove.UWP/Views/CommentsPage.xaml.cs index 1f0ccb9..e6c02cb 100644 --- a/TrueLove.UWP/Views/CommentsPage.xaml.cs +++ b/TrueLove.UWP/Views/CommentsPage.xaml.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; using TrueLove.Lib.Models.Code; using TrueLove.UWP.Spider; -using Windows.ApplicationModel; using Windows.UI.Core; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -16,15 +14,15 @@ namespace TrueLove.UWP.Views /// public sealed partial class CommentsPage : Page { - private List Comments; + private ObservableCollection Comments; public CommentsPage() { this.InitializeComponent(); Window.Current.Activated += OnWindowActivated; // 订阅窗口活动事件 - var readHTML = new ReviewHTML(Package.Current.InstalledPath + "/Spider/CommentCodeSample.txt"); + var reviewHTML = new ReviewHTML("https://avicii.com", false); var refineData = new RefineData(); - Comments = refineData.RefineComment(readHTML.StrHTML); + Comments = refineData.UpdateComment(reviewHTML.StrHTML); } /// /// 返回顶部按钮。 @@ -62,14 +60,13 @@ private void hapticScrollViewer_ViewChanged(object sender, ScrollViewerViewChang if (backgroundImageFixedHeight == 0) backgroundImageFixedHeight = backgroundSubTitle.ActualHeight; - try + if (backgroundImageFixedHeight - scrlocation <= 0) { - backgroundSubTitle.Height = backgroundImageFixedHeight - scrlocation; + backgroundSubTitle.Height = 0; } - catch (ArgumentException) + else { - // 快速滑动引起的参数修正 - backgroundSubTitle.Height = 0; + backgroundSubTitle.Height = backgroundImageFixedHeight - scrlocation; } } diff --git a/TrueLove.UWP/Views/ImagesPage.xaml.cs b/TrueLove.UWP/Views/ImagesPage.xaml.cs index 798c006..d31e903 100644 --- a/TrueLove.UWP/Views/ImagesPage.xaml.cs +++ b/TrueLove.UWP/Views/ImagesPage.xaml.cs @@ -1,5 +1,4 @@ using TrueLove.UWP.Spider; -using Windows.ApplicationModel; using Windows.UI.Core; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -18,10 +17,9 @@ public ImagesPage() this.InitializeComponent(); Window.Current.Activated += OnWindowActivated; // 订阅窗口活动事件 - //var readHTML = new ReviewHTML("https://avicii.com", false, false); - var readHTML = new ReviewHTML(Package.Current.InstalledPath + "/Spider/ImageCodeSample.txt"); + var reviewHTML = new ReviewHTML("https://avicii.com/images", false); var refineData = new RefineData(); - ImageView.ItemsSource = refineData.RefineImage(readHTML.StrHTML); + ImageView.ItemsSource = refineData.UpdateImage(reviewHTML.StrHTML); } ///