Skip to content

Commit

Permalink
完成基础的跳转链条
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Feb 28, 2024
1 parent 1e20bd1 commit 8530c6f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 29 deletions.
66 changes: 64 additions & 2 deletions Aria2Fast/Service/Model/MikanModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
Expand Down Expand Up @@ -150,6 +151,22 @@ public class MikanAnimeRss : BaseNotificationModel

public List<MikanAnimeRssItem> Items { get; set; }

public string ShowEpisode
{
get
{
var text = "";
var episode = Episode;
if (!string.IsNullOrEmpty(episode))
{
text += $"最新集数 {episode}";
}

return text;
// text += $" 总{Items.Count}";
}
}

//TODO 当前集数
public string Episode
{
Expand All @@ -167,7 +184,7 @@ public string Episode
public static string ExtractEpisodeNumber(string title)
{
// 正则表达式找出集数, 例如: [01], - 02, 第03集
Regex episodeRegex = new Regex(@"\[\d{2}\]|-\s*\d{2}|\d{2}", RegexOptions.Compiled);
Regex episodeRegex = new Regex(@"\[\d{1,3}\]|-\s*\d{1,3}", RegexOptions.Compiled);

Match match = episodeRegex.Match(title);
if (match.Success)
Expand All @@ -187,12 +204,57 @@ public string UpdateTime
var item = Items.FirstOrDefault();
if (item != null)
{
return item.Updated;

string result = FormatTimeAgo(item.Updated, +8);

return result;
}
return string.Empty;
}
}




public static string FormatTimeAgo(string timeText, int timeZoneOffset)
{
try
{
// 解析时间字符串
DateTime inputTime = DateTime.ParseExact(timeText, "yyyy/MM/dd HH:mm", CultureInfo.InvariantCulture);

// 考虑时区转换到UTC
inputTime = inputTime.AddHours(-timeZoneOffset);

// 获取当前的UTC时间
DateTime utcNow = DateTime.UtcNow;

// 计算差值
TimeSpan difference = utcNow - inputTime;

if (difference.TotalDays >= 1)
{
return timeText;
}
else if (difference.TotalHours >= 1)
{
return $"{Math.Floor(difference.TotalHours)}小时前";
}
else if (difference.TotalMinutes >= 1)
{
return $"{Math.Floor(difference.TotalMinutes)}分钟前";
}
else
{
return "刚刚";
}
}
catch (FormatException)
{
return "";
}
}

public bool IsSubscribed
{
get
Expand Down
3 changes: 3 additions & 0 deletions Aria2Fast/View/AddSubscriptionView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Aria2Fast.Dialogs;
using Aria2Fast.Service;
using Aria2Fast.Service.Model;
using Aria2Fast.Service.Model.SubscriptionModel;
using Aria2Fast.Utils;
using System;
Expand Down Expand Up @@ -175,6 +176,8 @@ await Task.Run(() => {
});

//TODO this.Close();

//MainWindow.Instance.RootNavigation.Navigate(typeof(AddSubscriptionView), (mikanAnimeRss.Url, mikanAnime.Name));
MainWindow.Instance.RootNavigation.GoBack();
}
catch (Exception ex)
Expand Down
9 changes: 5 additions & 4 deletions Aria2Fast/View/AnimeListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
</StackPanel>


<ListView
<ItemsControl
Margin="0,45,0,0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
ItemsSource="{Binding Master.AnimeDays}"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" />
ItemsSource="{Binding Master.AnimeDays}" />



</Grid>
</Page>
7 changes: 5 additions & 2 deletions Aria2Fast/View/AnimeListView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ private async void MikanAnimeDayControl_RssBorderClicked(object sender, RssBorde
//await Task.Delay(50);
//TestN.IsOpen = true;
MainWindow.Instance.RootNavigation.Navigate(typeof(MikanAnimeRssView), animeItem);


//在使用NavigationView的Navigate方法时,如果传递的View的高度大于NavigationView的区域时,


}

}

private async void GetListButton_Click(object sender, RoutedEventArgs e)
Expand Down
2 changes: 2 additions & 0 deletions Aria2Fast/View/MikanAnimeDayControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Margin="10,20,0,0"
FontSize="24"
Text="{Binding Title}" />
<ItemsControl
x:Name="MyListView"
Grid.Row="1"
Margin="-8,0,0,0"
ItemsSource="{Binding Anime}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ItemsControl.ItemsPanel>
Expand Down
47 changes: 27 additions & 20 deletions Aria2Fast/View/MikanAnimeRssView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,21 @@
d:DesignWidth="800"
mc:Ignorable="d">

<Page.Resources>
<DataTemplate x:Key="ItemTemplate">
<Border
Margin="5"
Padding="10"
Background="#EEE"
CornerRadius="6">
<StackPanel>
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
<TextBlock Foreground="Gray" Text="{Binding UpdateTime}" />
<TextBlock Text="{Binding Episode}" />
</StackPanel>
</Border>
</DataTemplate>
</Page.Resources>

<Grid>
<StackPanel
Margin="10,10,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">

<StackPanel>
<StackPanel Orientation="Horizontal">
<Border CornerRadius="6">
<Image
Width="140"
Height="200"
HorizontalAlignment="Left"
RenderOptions.BitmapScalingMode="HighQuality"
Source="{Binding ImageCache}"
Stretch="UniformToFill" HorizontalAlignment="Left">
Stretch="UniformToFill">
<Image.Clip>
<RectangleGeometry
RadiusX="6"
Expand All @@ -51,18 +36,40 @@
</Border>

<TextBlock
Margin="0,5,0,0"
Margin="10,0,0,0"
FontSize="16"
FontWeight="Bold"
Text="{Binding Name}"
TextTrimming="CharacterEllipsis" />
</StackPanel>

<ItemsControl ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Rss}">
<ItemsControl Margin="-5,5,0,0" ItemsSource="{Binding Rss}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border
Margin="5"
Padding="10"
Background="#EEE"
CornerRadius="6"
MouseLeftButtonUp="Border_MouseLeftButtonUp">
<StackPanel>
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
<TextBlock Foreground="Gray" Text="{Binding UpdateTime}" />
<StackPanel Orientation="Horizontal">

<TextBlock Text="{Binding ShowEpisode}" />
</StackPanel>

</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>

</ItemsControl>

</StackPanel>
Expand Down
18 changes: 17 additions & 1 deletion Aria2Fast/View/MikanAnimeRssView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Aria2Fast.Service.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -24,5 +25,20 @@ public MikanAnimeRssView()
{
InitializeComponent();
}

private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var b = sender as Border;

MikanAnime mikanAnime = ((MikanAnime)DataContext);

MikanAnimeRss mikanAnimeRss = (MikanAnimeRss)b.DataContext;




//弹出订阅页面?
MainWindow.Instance.RootNavigation.Navigate(typeof(AddSubscriptionView), (mikanAnimeRss.Url, mikanAnime.Name));
}
}
}

0 comments on commit 8530c6f

Please sign in to comment.