Skip to content

Commit

Permalink
修改缓存策略,缓减内存占用
Browse files Browse the repository at this point in the history
  • Loading branch information
ProJend committed Oct 28, 2024
1 parent 729d28e commit d801c26
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 196 deletions.
18 changes: 9 additions & 9 deletions src/BiliLite.UWP/Controls/Settings/UISettingsControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using BiliLite.Extensions;
using BiliLite.Extensions;
using BiliLite.Models.Common;
using BiliLite.Models.Common.Home;
using BiliLite.Services;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Toolkit.Uwp.UI;
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

Expand All @@ -18,7 +18,7 @@ public sealed partial class UISettingsControl : UserControl
{
public UISettingsControl()
{
this.InitializeComponent();
this.InitializeComponent();
LoadUI();
}
private void LoadUI()
Expand Down Expand Up @@ -87,7 +87,7 @@ private void LoadUI()
swHomeCache.Toggled += new RoutedEventHandler((obj, args) =>
{
SettingService.SetValue(SettingConstants.UI.CACHE_HOME, swHomeCache.IsOn);

Notify.ShowMessageToast("重启生效");
});
});

Expand Down
5 changes: 0 additions & 5 deletions src/BiliLite.UWP/NoTabMainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ private void NavigationHelper_NavigateToPageEvent(object sender, NavigationInfo
{
//PushTitle(e.title);
frame.Navigate(e.page, e.parameters);
(frame.Content as Page).NavigationCacheMode = NavigationCacheMode.Required;
}
else
{
Expand Down Expand Up @@ -316,10 +315,6 @@ public async void GoBack()
{
var frame = this.Children.Last() as MyFrame;

if (frame.Content is Page page)
{
page.NavigationCacheMode = NavigationCacheMode.Disabled;
}
if (frame.CanGoBack)
{
frame.GoBack();
Expand Down
1 change: 0 additions & 1 deletion src/BiliLite.UWP/Pages/Bangumi/AnimeIndexPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public AnimeIndexPage()
{
this.InitializeComponent();
Title = "剧集索引";
this.NavigationCacheMode = NavigationCacheMode.Enabled;
seasonIndexVM = new SeasonIndexVM();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
Expand Down
3 changes: 1 addition & 2 deletions src/BiliLite.UWP/Pages/Bangumi/SeasonRankPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public SeasonRankPage()
{
this.InitializeComponent();
Title = "热门榜单";
this.NavigationCacheMode = NavigationCacheMode.Enabled;
seasonRankVM = new SeasonRankVM();
}

Expand All @@ -30,7 +29,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.New)
{
seasonRankVM.LoadRankRegion((int)e.Parameter);
seasonRankVM.LoadRankRegion((int)e.Parameter);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/BiliLite.UWP/Pages/BasePage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Threading.Tasks;
using BiliLite.Controls;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using BiliLite.Controls;
using BiliLite.Models.Common;
using BiliLite.Services;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

Expand All @@ -13,13 +11,13 @@ public class BasePage : Page
public string Title { get; set; }
public BasePage()
{
this.NavigationCacheMode = (SettingService.GetValue<int>(SettingConstants.UI.DISPLAY_MODE, 0) == 1) ? Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled : Windows.UI.Xaml.Navigation.NavigationCacheMode.Disabled;

}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back || e.SourcePageType == typeof(BlankPage))
{
this.NavigationCacheMode = NavigationCacheMode.Disabled;

}
else
{
Expand Down
9 changes: 0 additions & 9 deletions src/BiliLite.UWP/Pages/Home/ChannelPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BiliLite.Extensions;
using BiliLite.Models.Common;
using BiliLite.Services;
using System;
using Windows.UI.Popups;
Expand All @@ -18,14 +17,6 @@ public sealed partial class ChannelPage : Page
public ChannelPage()
{
this.InitializeComponent();
if (SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true))
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
else
{
this.NavigationCacheMode = NavigationCacheMode.Disabled;
}
web.NewWindowRequested += webView_NewWindowRequested;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
Expand Down
11 changes: 5 additions & 6 deletions src/BiliLite.UWP/Pages/Home/DynamicPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Threading.Tasks;
using BiliLite.Extensions;
using BiliLite.Extensions;
using BiliLite.Models.Common;
using BiliLite.Models.Common.Dynamic;
using BiliLite.Services;
using BiliLite.ViewModels.Home;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using BiliLite.Models.Common.Dynamic;
using BiliLite.ViewModels.Home;
using Microsoft.Extensions.DependencyInjection;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

Expand All @@ -27,7 +27,6 @@ public DynamicPage()
m_viewModel = App.ServiceProvider.GetService<DynamicPageViewModel>();
m_viewModel.DynamicItemDataTemplateSelector.Resource = this.Resources;
this.DataContext = m_viewModel;
this.NavigationCacheMode = SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true) ? NavigationCacheMode.Enabled : NavigationCacheMode.Disabled;
}

protected override async void OnNavigatedTo(NavigationEventArgs e)
Expand Down
9 changes: 0 additions & 9 deletions src/BiliLite.UWP/Pages/Home/HotPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ public HotPage()
this.InitializeComponent();
hotVM = new HotVM();
this.DataContext = hotVM;
if (SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true))
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
else
{
this.NavigationCacheMode = NavigationCacheMode.Disabled;
}

}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
Expand Down
10 changes: 1 addition & 9 deletions src/BiliLite.UWP/Pages/Home/LivePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@ namespace BiliLite.Pages.Home
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class LivePage : Page,IRefreshablePage
public sealed partial class LivePage : Page, IRefreshablePage
{
private Modules.LiveVM liveVM;
public LivePage()
{
this.InitializeComponent();
liveVM = new Modules.LiveVM();
if (SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true))
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
else
{
this.NavigationCacheMode = NavigationCacheMode.Disabled;
}

}
protected async override void OnNavigatedTo(NavigationEventArgs e)
Expand Down
8 changes: 0 additions & 8 deletions src/BiliLite.UWP/Pages/Home/MoviePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public MoviePage()
{
this.InitializeComponent();
cinemaVM = new Modules.CinemaVM();
if (SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true))
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
else
{
this.NavigationCacheMode = NavigationCacheMode.Disabled;
}
MessageCenter.LoginedEvent += MessageCenter_LoginedEvent;
MessageCenter.LogoutedEvent += MessageCenter_LogoutedEvent;
}
Expand Down
19 changes: 9 additions & 10 deletions src/BiliLite.UWP/Pages/Home/RecommendPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using BiliLite.Extensions;
using BiliLite.Models.Common;
using BiliLite.Models.Common.Recommend;
using BiliLite.Modules.User;
using BiliLite.Services;
using BiliLite.ViewModels.Home;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -10,9 +13,6 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using BiliLite.Models.Common.Recommend;
using BiliLite.ViewModels.Home;
using Microsoft.Extensions.DependencyInjection;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

Expand All @@ -35,7 +35,6 @@ public sealed partial class RecommendPage : Page, IRefreshablePage, IScrollRecov
public RecommendPage()
{
this.InitializeComponent();
this.NavigationCacheMode = SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true) ? NavigationCacheMode.Enabled : NavigationCacheMode.Disabled;
m_viewModel = App.ServiceProvider.GetRequiredService<RecommendPageViewModel>();
this.DataContext = m_viewModel;
}
Expand Down Expand Up @@ -115,11 +114,11 @@ private async void ListMenu_ItemClick(object sender, ItemClickEventArgs e)
switch (threePoint.Type)
{
case "watch_later":
{
var item = (sender as ListView).DataContext as RecommendItemModel;
WatchLaterVM.Instance.AddToWatchlater(item.Param);
return;
}
{
var item = (sender as ListView).DataContext as RecommendItemModel;
WatchLaterVM.Instance.AddToWatchlater(item.Param);
return;
}
case "dislike":
await m_viewModel.Dislike(threePoint.Idx, threePoint, null);
return;
Expand Down Expand Up @@ -155,7 +154,7 @@ private async Task VideoItemClicked(RecommendItemModel data, bool dontGoTo = fal
url = data.AdInfo.CreativeContent.ClickUrl ?? data.AdInfo.CreativeContent.Url;
}
await MessageCenter.HandelUrl(url, dontGoTo);

return;
}
if (data.CardGoto == "new_tunnel")
Expand Down
21 changes: 0 additions & 21 deletions src/BiliLite.UWP/Pages/Home/RegionsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
using BiliLite.Models.Common;
using BiliLite.Modules;
using BiliLite.Modules.Home;
using BiliLite.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
Expand All @@ -31,14 +18,6 @@ public RegionsPage()
{
this.InitializeComponent();
channelVM = new RegionVM();
if (SettingService.GetValue<bool>(SettingConstants.UI.CACHE_HOME, true))
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
else
{
this.NavigationCacheMode = NavigationCacheMode.Disabled;
}
}

protected async override void OnNavigatedTo(NavigationEventArgs e)
Expand Down
1 change: 0 additions & 1 deletion src/BiliLite.UWP/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
xmlns:pages="using:BiliLite.Pages.Home"
xmlns:modules="using:BiliLite.Modules" xmlns:converters="using:BiliLite.Converters"
xmlns:home="using:BiliLite.ViewModels.Home"
NavigationCacheMode="Required"
Background="Transparent">
<Page.Resources>
<converters:CountDisplayConvert x:Name="countDisplayConvert"></converters:CountDisplayConvert>
Expand Down
10 changes: 7 additions & 3 deletions src/BiliLite.UWP/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
using BiliLite.Models.Common;
using BiliLite.Modules;
using BiliLite.Services;
using BiliLite.ViewModels.Download;
using BiliLite.ViewModels.Home;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp.Connectivity;
using System;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using BiliLite.ViewModels.Download;
using BiliLite.ViewModels.Home;
using Microsoft.Extensions.DependencyInjection;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

Expand Down Expand Up @@ -38,6 +38,10 @@ public HomePage()
m_downloadPageViewModel = App.ServiceProvider.GetRequiredService<DownloadPageViewModel>();
// m_cookieService = App.ServiceProvider.GetRequiredService<CookieService>();
this.DataContext = m_viewModel;
NavigationCacheMode = SettingService.GetValue(SettingConstants.UI.CACHE_HOME, true)
? NavigationCacheMode.Required
: NavigationCacheMode.Disabled;

}

public async Task Refresh()
Expand Down
3 changes: 1 addition & 2 deletions src/BiliLite.UWP/Pages/Live/LiveAreaDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public LiveAreaDetailPage()
{
this.InitializeComponent();
Title = "分区详情";
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
Expand Down Expand Up @@ -61,7 +60,7 @@ private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
var data = (sender as ToggleButton).DataContext as LiveTagItemModel;
if (data.Select) return;
var select=liveAreaDetailVM.Tags.FirstOrDefault(x => x.Select);
var select = liveAreaDetailVM.Tags.FirstOrDefault(x => x.Select);
select.Select = false;
data.Select = true;
liveAreaDetailVM.SelectTag = data;
Expand Down
15 changes: 1 addition & 14 deletions src/BiliLite.UWP/Pages/Live/LiveAreaPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
using BiliLite.Models.Common;
using BiliLite.Modules.Live;
using BiliLite.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
Expand All @@ -30,13 +18,12 @@ public LiveAreaPage()
{
this.InitializeComponent();
Title = "直播分区";
this.NavigationCacheMode = NavigationCacheMode.Enabled;
liveAreaVM = new LiveAreaVM();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if(e.NavigationMode== NavigationMode.New&& liveAreaVM.Items == null)
if (e.NavigationMode == NavigationMode.New && liveAreaVM.Items == null)
{
await liveAreaVM.GetItems();
}
Expand Down
Loading

0 comments on commit d801c26

Please sign in to comment.