Skip to content

Commit

Permalink
Merge branch 'dev' into PR-932
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Dec 14, 2024
2 parents 175d62a + 7a20b61 commit a349ce3
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 256 deletions.
497 changes: 246 additions & 251 deletions .github/workflows/release.yml

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions scripts/setNative.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
param (
[string]$csprojPath
)

# Check if the input file exists
if (-not (Test-Path $csprojPath)) {
Write-Error "File not found: $csprojPath"
exit 1
}

# Read the content of the csproj file with UTF-8 encoding
$csprojContent = Get-Content -Path $csprojPath -Raw -Encoding UTF8

# Define the target PropertyGroup condition
# Use backticks to escape the $ character
$targetCondition = "'`$(Configuration)|`$(Platform)' == 'Release|x64'"

# Find the PropertyGroup with the target condition
$propertyGroupRegex = [regex]::Escape("<PropertyGroup Condition=`"$targetCondition`">") + ".*?" + [regex]::Escape("</PropertyGroup>")
$propertyGroupMatch = [regex]::Match($csprojContent, $propertyGroupRegex, [Text.RegularExpressions.RegexOptions]::Singleline)

if ($propertyGroupMatch.Success) {
# Extract the PropertyGroup content
$propertyGroupContent = $propertyGroupMatch.Value

# Check if UseDotNetNativeToolchain exists in the PropertyGroup
$useDotNetNativeToolchainRegex = [regex]::Escape("<UseDotNetNativeToolchain>") + ".*?" + [regex]::Escape("</UseDotNetNativeToolchain>")
$useDotNetNativeToolchainMatch = [regex]::Match($propertyGroupContent, $useDotNetNativeToolchainRegex)

if ($useDotNetNativeToolchainMatch.Success) {
# Replace the value of UseDotNetNativeToolchain with true
$updatedPropertyGroupContent = $propertyGroupContent -replace $useDotNetNativeToolchainRegex, "<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>"
} else {
# If UseDotNetNativeToolchain doesn't exist, add it
$updatedPropertyGroupContent = $propertyGroupContent -replace "</PropertyGroup>", "<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain></PropertyGroup>"
}

# Replace the original PropertyGroup with the updated one
$csprojContent = $csprojContent -replace [regex]::Escape($propertyGroupContent), $updatedPropertyGroupContent

# Write the updated content back to the file with UTF-8 encoding
Set-Content -Path $csprojPath -Value $csprojContent -Encoding UTF8

Write-Host "Updated UseDotNetNativeToolchain to true in the PropertyGroup with condition '$targetCondition'."
} else {
Write-Warning "PropertyGroup with condition '$targetCondition' not found in the csproj file."
}
7 changes: 7 additions & 0 deletions src/BiliLite.UWP/Models/Common/ComboBoxItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ public class ComboBoxItemData

public int Value { get; set; }
}

public class ComboBoxItemData<T>
{
public string Text { get; set; }

public T Value { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/BiliLite.UWP/Models/Common/Enumerates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,13 @@ public enum IndexSeasonType
TV = 5,
Variety = 7
}

public enum DownloadedSortMode
{
Default,
TimeDesc,
TimeAsc,
TitleDesc,
TitleAsc,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void Danmu(LiveRoomViewModel viewModel, object message)
}
}

if (viewModel.Messages.Count >= viewModel.CleanCount) viewModel.Messages.RemoveAt(0);
viewModel.CheckClearMessages();
viewModel.Messages.Add(m);
AddNewDanmu?.Invoke(null, m);
}
Expand Down Expand Up @@ -137,6 +137,7 @@ private void InteractWord(LiveRoomViewModel viewModel, object message)
msg.ShowMedal = info.ShowMedal;
}

viewModel.CheckClearMessages();
viewModel.Messages.Add(msg);
}

Expand Down
13 changes: 13 additions & 0 deletions src/BiliLite.UWP/Pages/DownloadPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
<Run Text="{x:Bind m_viewModel.LoadingDownloadedPercent,Mode=OneWay}"></Run>
%
</TextBlock>

<ComboBox SelectedIndex="0" MinWidth="100"
x:Name="CbSortMode"
SelectedValuePath="Value"
DisplayMemberPath="Text"
Margin="8 12"
SelectionChanged="SortOptions_OnSelectionChanged"
Visibility="{x:Bind m_viewModel.LoadingDownloaded,Mode=OneWay,Converter={StaticResource display}}"
ItemsSource="{x:Bind m_sortOptions}">
</ComboBox>

<Button Visibility="{x:Bind m_viewModel.IsSearching,Mode=OneWay}"
Click="BtnClearSearch_OnClick">清除搜索</Button>
<AutoSuggestBox x:Name="SearchBox"
MinWidth="200"
FontSize="12"
Expand Down
20 changes: 20 additions & 0 deletions src/BiliLite.UWP/Pages/DownloadPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public sealed partial class DownloadPage : BasePage, IRefreshablePage
private static readonly ILogger logger = GlobalLogger.FromCurrentType();
private readonly DownloadPageViewModel m_viewModel;
private readonly DownloadService m_downloadService;
private readonly ComboBoxItemData<DownloadedSortMode>[] m_sortOptions = new ComboBoxItemData<DownloadedSortMode>[]
{
new() { Text = "默认", Value = DownloadedSortMode.Default },
new() { Text = "时间倒序", Value = DownloadedSortMode.TimeDesc },
new() { Text = "时间顺序", Value = DownloadedSortMode.TimeAsc },
new() { Text = "标题顺序", Value = DownloadedSortMode.TitleAsc },
new() { Text = "标题倒序", Value = DownloadedSortMode.TitleDesc },
};

public DownloadPage()
{
Expand All @@ -46,6 +54,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

public async Task Refresh()
{
CbSortMode.SelectedIndex = 0;
m_downloadService.RefreshDownloaded();
}

Expand Down Expand Up @@ -350,5 +359,16 @@ private void BtnResumeSubItem_OnClick(object sender, RoutedEventArgs e)
m_downloadService.ResumeItem(item);
}
}

private void BtnClearSearch_OnClick(object sender, RoutedEventArgs e)
{
m_downloadService.SearchDownloaded("");
DownloadPivot.SelectedIndex = 1;
}

private void SortOptions_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
m_downloadService.SetDownloadedSortMode((DownloadedSortMode)CbSortMode.SelectedValue);
}
}
}
1 change: 1 addition & 0 deletions src/BiliLite.UWP/Pages/VideoDetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<MenuFlyout x:Name="ShareMenu">
<MenuFlyoutItem Click="btnShareCopyUrl_Click" Icon="Copy" Text="复制链接"/>
<MenuFlyoutItem Click="btnShareCopy_Click" Icon="Copy" Text="复制标题链接"/>
<MenuFlyoutItem Click="BtnCopyAvId_OnClick" Icon="Copy" Text="复制Av号"/>
<MenuFlyoutItem Click="btnShare_Click" Icon="Share" Text="分享到..."/>
</MenuFlyout>
</Page.Resources>
Expand Down
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/Pages/VideoDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,5 +746,10 @@ private void Pivot_OnPreviewKeyDown(object sender, KeyRoutedEventArgs e)
e.OriginalSource.GetType() != typeof(TextBox))
e.Handled = true;
}

private void BtnCopyAvId_OnClick(object sender, RoutedEventArgs e)
{
("av" + m_viewModel.VideoInfo.Aid).SetClipboard();
}
}
}
41 changes: 37 additions & 4 deletions src/BiliLite.UWP/Services/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ private async Task LoadDownloadFromIndex()
m_downloadPageViewModel.DownloadedViewModels = new ObservableCollection<DownloadedItem>(downloadedItems);
}

private IEnumerable<DownloadedItem> QueryDownloaded()
{
var query = m_downloadPageViewModel.Downloadeds.AsEnumerable();

// 提前处理搜索条件
var searchKeyword = m_downloadPageViewModel.SearchKeyword?.ToLower();
if (!string.IsNullOrEmpty(searchKeyword))
{
query = query.Where(x => x.Title.ToLower().Contains(searchKeyword));
}

// 使用 switch 表达式简化排序逻辑
query = m_downloadPageViewModel.DownloadedSortMode switch
{
DownloadedSortMode.TimeDesc => query.OrderByDescending(x => x.UpdateTime),
DownloadedSortMode.TimeAsc => query.OrderBy(x => x.UpdateTime),
DownloadedSortMode.TitleDesc => query.OrderByDescending(x => x.Title),
DownloadedSortMode.TitleAsc => query.OrderBy(x => x.Title),
_ => query // 默认不排序
};

return query;
}

#endregion

#region Public Methods
Expand Down Expand Up @@ -428,8 +452,10 @@ public void RefreshDownloaded()

public void SearchDownloaded(string keyword)
{
var searchResult = m_downloadPageViewModel.Downloadeds
.Where(x => x.Title.ToLower().Contains(keyword.ToLower())).ToList();
m_downloadPageViewModel.SearchKeyword = keyword;
m_downloadPageViewModel.IsSearching = !string.IsNullOrEmpty(keyword);

var searchResult = QueryDownloaded();
m_downloadPageViewModel.DownloadedViewModels.Clear();
m_downloadPageViewModel.DownloadedViewModels.AddRange(searchResult);
}
Expand Down Expand Up @@ -807,9 +833,16 @@ public void ClearIndex()
m_biliLiteDbContext.DownloadedItems.RemoveRange(m_biliLiteDbContext.DownloadedItems);
}

#endregion
public void SetDownloadedSortMode(DownloadedSortMode mode)
{
m_downloadPageViewModel.DownloadedSortMode = mode;
m_downloadPageViewModel.DownloadedViewModels.Clear();

var query = QueryDownloaded();

m_downloadPageViewModel.DownloadedViewModels.AddRange(query);
}

#endregion
}
}
}
9 changes: 9 additions & 0 deletions src/BiliLite.UWP/ViewModels/Download/DownloadPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using Windows.Networking.BackgroundTransfer;
using AutoMapper;
using BiliLite.Models.Common;

namespace BiliLite.ViewModels.Download
{
Expand Down Expand Up @@ -60,6 +61,8 @@ public DownloadPageViewModel(IMapper mapper)
[DoNotNotify]
public List<DownloadedItem> Downloadeds { get; set; }

public bool IsSearching { get; set; }

public bool LoadingDownloaded { get; set; } = true;

public double DiskTotal { get; set; }
Expand All @@ -75,6 +78,12 @@ public DownloadPageViewModel(IMapper mapper)
[DependsOn(nameof(TotalDownloadedCount), nameof(LoadedDownloadedCount))]
public int LoadingDownloadedPercent => (int)((LoadedDownloadedCount * 1f / TotalDownloadedCount * 1f) * 100);

[DoNotNotify]
public DownloadedSortMode DownloadedSortMode { get; set; }

[DoNotNotify]
public string SearchKeyword { get; set; }

#endregion
}
}
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/ViewModels/Live/LiveRoomViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,11 @@ public async Task<bool> JoinRedPocketLottery()

}

public void CheckClearMessages()
{
if (Messages.Count >= CleanCount) Messages.RemoveAt(0);
}

public void Dispose()
{
foreach (var item in LotteryDanmu)
Expand Down

0 comments on commit a349ce3

Please sign in to comment.