Skip to content

Commit

Permalink
Diagnose network connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
ProJend committed Oct 7, 2023
1 parent 53223a0 commit 8228ce7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 26 deletions.
16 changes: 10 additions & 6 deletions TrueLove.UWP/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.QueryStringDotNET;
using Microsoft.Toolkit.Uwp.Connectivity;
using System;
using TrueLove.Lib.Helpers;
using TrueLove.Lib.Models.Enum;
Expand Down Expand Up @@ -188,11 +189,14 @@ private void CollapseStatusBar()

private async void InitialCommentData()
{
var localFolder = ApplicationData.Current.LocalFolder;
var file = await localFolder.CreateFileAsync("OfflineData.txt",
CreationCollisionOption.ReplaceExisting);
var _src = await new ReviewWeb().GetSourceCodeAsync($"https://avicii.com/page/11", false);
await FileIO.AppendTextAsync(file, _src);
if (NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable)
{
var localFolder = ApplicationData.Current.LocalFolder;
var file = await localFolder.CreateFileAsync("OfflineData.txt",
CreationCollisionOption.ReplaceExisting);
var _src = await new ReviewWeb().GetSourceCodeAsync($"https://avicii.com/page/11", false);
await FileIO.AppendTextAsync(file, _src);
}
}
}
}
}
3 changes: 3 additions & 0 deletions TrueLove.UWP/TrueLove.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Connectivity">
<Version>4.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
<Version>4.0.0</Version>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion TrueLove.UWP/Views/CommentsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
FontFamily="Segoe MDL2 Assets"
FontSize="40"
Glyph="&#xF384;" />
<TextBlock Style="{ThemeResource SubtitleTextBlockStyle}">Offline</TextBlock>
<TextBlock Style="{ThemeResource SubtitleTextBlockStyle}">Offline Data</TextBlock>
</StackPanel>
<ProgressRing
x:Name="progressRing"
Expand Down
34 changes: 23 additions & 11 deletions TrueLove.UWP/Views/CommentsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TrueLove.Lib.Models.Code;
using Microsoft.Toolkit.Uwp.Connectivity;
using TrueLove.Lib.Models.Code;
using TrueLove.Lib.Spider;
using Windows.Storage;
using Windows.UI.Core;
Expand All @@ -19,6 +20,7 @@ public CommentsPage()
this.InitializeComponent();
Window.Current.Activated += OnWindowActivated; // 订阅窗口活动事件
GetSourceCode();

}

async void GetSourceCode()
Expand All @@ -36,6 +38,7 @@ async void GetSourceCode()

private void Refresh_Click(object sender, RoutedEventArgs e)
{
_pageNumber = 0;
RefreshButton.IsEnabled = false;
commentDataCollection.Clear();
Scroller.ChangeView(null, 0, null);
Expand Down Expand Up @@ -95,20 +98,29 @@ private void Scroller_ViewChanged(object sender, ScrollViewerViewChangedEventArg

private async void DataLoad()
{
progressRing.IsActive = true;
var refineData = new RefineData();
refineData.UpdateComment(_src, commentDataCollection);

progressRing.IsActive = false;
_pageNumber++;
var reviewWeb = new ReviewWeb();
_src = await reviewWeb.GetSourceCodeAsync($"https://avicii.com/page/{_pageNumber}", false);

if (_pageNumber != null)
{
progressRing.IsActive = true;
var refineData = new RefineData();
refineData.UpdateComment(_src, commentDataCollection);
progressRing.IsActive = false;
}
if (NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable)
{
_pageNumber++;
var reviewWeb = new ReviewWeb();
_src = await reviewWeb.GetSourceCodeAsync($"https://avicii.com/page/{_pageNumber}", false);
}
else
{
_pageNumber = null;
NetworkState.Visibility = Visibility.Visible;
}
RefreshButton.IsEnabled = true;
}

CommentDataCollection commentDataCollection = new CommentDataCollection();
double _pageNumber;
double? _pageNumber = 0;
string _src;

// 滚动条位置变量
Expand Down
3 changes: 1 addition & 2 deletions TrueLove.UWP/Views/ImagesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@
x:Name="progressRing"
Grid.ColumnSpan="2"
Width="50"
Height="50"
IsActive="True" />
Height="50" />
<Button
Grid.Column="0"
HorizontalAlignment="Center"
Expand Down
16 changes: 10 additions & 6 deletions TrueLove.UWP/Views/ImagesPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using Microsoft.Toolkit.Uwp.Connectivity;
using System.Collections.ObjectModel;
using TrueLove.Lib.Spider;
using Windows.UI.Core;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -76,11 +77,14 @@ private async void DataLoad()
progressRing.IsActive = true;
RefreshButton.IsEnabled = false;

_pageNumber++;
var reviewWeb = new ReviewWeb();
var src = await reviewWeb.GetSourceCodeAsync($"https://avicii.com/images/page/{_pageNumber}", false);
var refineData = new RefineData();
refineData.UpdateImage(src, imageCollection);
if (NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable)
{
_pageNumber++;
var reviewWeb = new ReviewWeb();
var src = await reviewWeb.GetSourceCodeAsync($"https://avicii.com/images/page/{_pageNumber}", false);
var refineData = new RefineData();
refineData.UpdateImage(src, imageCollection);
}

progressRing.IsActive = false;
RefreshButton.IsEnabled = true;
Expand Down

0 comments on commit 8228ce7

Please sign in to comment.