From 7effdadf74cf94f7eca38c560e8bd0eb447d892e Mon Sep 17 00:00:00 2001 From: aiqinxuancai Date: Fri, 1 Mar 2024 18:15:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96UI=E5=8A=A0=E8=BD=BD=E6=95=88?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria2Fast/Service/Model/MikanModel.cs | 29 ++++++++---------------- Aria2Fast/Utils/ImageCacheUtils.cs | 18 +++++++-------- Aria2Fast/View/AnimeListView.xaml | 14 ++++++++---- Aria2Fast/View/MikanAnimeDayControl.xaml | 8 +++---- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/Aria2Fast/Service/Model/MikanModel.cs b/Aria2Fast/Service/Model/MikanModel.cs index fcf9697..84e7a50 100644 --- a/Aria2Fast/Service/Model/MikanModel.cs +++ b/Aria2Fast/Service/Model/MikanModel.cs @@ -117,6 +117,9 @@ public class MikanAnimeRss : BaseNotificationModel private List _items { get; set; } + private bool _isUpdateToday; + private int _episode = 0; + private string _updateTime; public List Items { @@ -131,10 +134,15 @@ public List Items { _episode = e; } + + _isUpdateToday = TimeHelper.IsUpdateToday(item.Updated, +8); ; + _updateTime = TimeHelper.FormatTimeAgo(item.Updated, +8); } } } + + public string ShowEpisode { get @@ -147,13 +155,9 @@ public string ShowEpisode } return text; - // text += $" 总{Items.Count}"; } } - - private int _episode = 0; - //TODO 当前集数 public int Episode { @@ -169,15 +173,7 @@ public string UpdateTime { get { - var item = Items.FirstOrDefault(); - if (item != null) - { - - string result = TimeHelper.FormatTimeAgo(item.Updated, +8); - - return result; - } - return string.Empty; + return _updateTime; } } @@ -185,12 +181,7 @@ public bool IsUpdateToday { get { - var item = Items.FirstOrDefault(); - if (item != null) - { - return TimeHelper.IsUpdateToday(item.Updated, +8); ; - } - return false; + return _isUpdateToday; } } diff --git a/Aria2Fast/Utils/ImageCacheUtils.cs b/Aria2Fast/Utils/ImageCacheUtils.cs index fe7aea5..3bc1f83 100644 --- a/Aria2Fast/Utils/ImageCacheUtils.cs +++ b/Aria2Fast/Utils/ImageCacheUtils.cs @@ -35,11 +35,8 @@ await Task.Run(() => { bitmap.UriSource = new Uri(file); bitmap.EndInit(); - // 这一步很重要,它标记了图片的缓存行为,当图片加载完毕后,它会被保留在内存中 bitmap.Freeze(); - //var img = new BitmapImage(new Uri(file)); - //img.CacheOption = BitmapCacheOption.OnLoad; cache.Set(cacheKey, bitmap, new CacheItemPolicy()); Debug.WriteLine($"[缓存]{cacheKey}"); @@ -57,13 +54,14 @@ await Task.Run(() => { /// public static BitmapImage GetImageWithLocalCache(Uri uri) { - //MemoryCache cache = MemoryCache.Default; + MemoryCache cache = MemoryCache.Default; var fileName = Path.GetFileName(uri.LocalPath); - //if (cache.Contains(fileName)) - //{ - // var bmp = (BitmapImage)cache.Get(fileName); - // return bmp; - //} + if (cache.Contains(fileName)) + { + var bmp = (BitmapImage)cache.Get(fileName); + //bmp.Freeze(); + return bmp; + } var dirPath = Path.Combine(Directory.GetCurrentDirectory(), "ImageCached"); if (!Directory.Exists(dirPath)) @@ -94,7 +92,7 @@ public static BitmapImage GetImageWithLocalCache(Uri uri) } img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); - + img.Freeze(); return img; } diff --git a/Aria2Fast/View/AnimeListView.xaml b/Aria2Fast/View/AnimeListView.xaml index 204ba64..206a54d 100644 --- a/Aria2Fast/View/AnimeListView.xaml +++ b/Aria2Fast/View/AnimeListView.xaml @@ -54,9 +54,15 @@ Margin="0,45,0,0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" - ItemsSource="{Binding Master.AnimeDays}" /> - - - + ItemsSource="{Binding Master.AnimeDays, IsAsync=True}"> + + + + + + + + + diff --git a/Aria2Fast/View/MikanAnimeDayControl.xaml b/Aria2Fast/View/MikanAnimeDayControl.xaml index f2cf6f8..6b41cfc 100644 --- a/Aria2Fast/View/MikanAnimeDayControl.xaml +++ b/Aria2Fast/View/MikanAnimeDayControl.xaml @@ -59,7 +59,7 @@ Height="200" Opacity="0" RenderOptions.BitmapScalingMode="HighQuality" - Source="{Binding ImageCache}" + Source="{Binding ImageCache, IsAsync=True}" Stretch="UniformToFill">