Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
WangyuHello committed Apr 11, 2023
1 parent 7ae1a00 commit 4454ed2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
14 changes: 14 additions & 0 deletions HotPotPlayer.Common/Models/BiliBili/SearchRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HotPotPlayer.Models.BiliBili
{
public class SearchRequest
{
public string Keyword { get; set; }
public bool DoSearch { get; set; }
}
}
7 changes: 6 additions & 1 deletion HotPotPlayer/Controls/BilibiliSub/Header.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using HotPotPlayer.Bilibili.Models.Dynamic;
using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel.Design;
using HotPotPlayer.Models.BiliBili;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down Expand Up @@ -167,7 +168,11 @@ public Visibility GetDynamicEntranceVisible(EntranceData d)

private void Search_Tapped(object sender, TappedRoutedEventArgs e)
{
NavigateTo("BilibiliSub.Search", SearchDefault);
NavigateTo("BilibiliSub.Search", new SearchRequest
{
Keyword = SearchDefault,
DoSearch = false
});
}
}
}
12 changes: 9 additions & 3 deletions HotPotPlayer/MainWindow.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ public void NavigateInit()
SelectedPageName = InitPageName;
}

public void NavigateTo(string name, object parameter = null, NavigationTransitionInfo trans = null)
public async void NavigateTo(string name, object parameter = null, NavigationTransitionInfo trans = null)
{
if (MainFrame.CurrentSourcePageType.Name == "BiliVideoPlay")
{
var biliPlay = MainFrame.Content as BiliVideoPlay;
await biliPlay.RequestNavigateFrom();
}
trans ??= new DrillInNavigationTransitionInfo();
MainFrame.Navigate(Type.GetType("HotPotPlayer.Pages." + name), parameter, trans);
SelectedPageName = name;
}

public void NavigateBack(bool force = false)
public async void NavigateBack(bool force = false)
{
if (!MainFrame.CanGoBack)
{
Expand All @@ -76,7 +81,8 @@ public void NavigateBack(bool force = false)
if (MainFrame.CurrentSourcePageType.Name == "BiliVideoPlay")
{
var biliPlay = MainFrame.Content as BiliVideoPlay;
biliPlay.RequestNavigateBack();
await biliPlay.RequestNavigateFrom();
NavigateBack(true);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions HotPotPlayer/Pages/BilibiliSub/BiliVideoPlay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@
<FontIcon Grid.Column="9" FontFamily="{ThemeResource SegoeIcons}" Margin="12,0,0,0" Glyph="&#xE18B;" Foreground="Gray" FontSize="16"/>
<TextBlock Grid.Column="10" VerticalAlignment="Center" Margin="6,0" Text="{x:Bind OnLineCount}" Foreground="Gray" FontFamily="{ThemeResource MiSansRegular}" />

<ListView Grid.Column="11" ItemsSource="{x:Bind Tags}" Height="28" Margin="12,0,0,0" Style="{StaticResource HorizontalListViewStyle}" ItemTemplate="{StaticResource TagTemplate}" ItemContainerStyle="{StaticResource TransparentListContainerCompactHPaddingStyle}"/>
<ListView Grid.Column="11" ItemsSource="{x:Bind Tags}" Height="28" Margin="12,0,0,0" Style="{StaticResource HorizontalListViewStyle}" ItemTemplate="{StaticResource TagTemplate}" ItemContainerStyle="{StaticResource TransparentListContainerCompactHPaddingStyle}" ItemClick="TagClick"/>
</Grid>
<ScrollViewer Grid.Row="3" MaxHeight="58">
<ScrollViewer Grid.Row="3" MaxHeight="58" MinHeight="26">
<TextBlock Text="{x:Bind Video.VideoDEsc}" IsTextSelectionEnabled="True" FontFamily="{ThemeResource MiSansRegular}" TextWrapping="Wrap" />
</ScrollViewer>
<ListView x:Name="RelatedList" Grid.Row="4" Margin="-36,2,-28,0" Padding="36,0,28,0" Height="220" ItemsSource="{x:Bind RelatedVideos}" Style="{StaticResource HorizontalListViewStyle}" ItemContainerStyle="{StaticResource GeneralListContainerCompactPaddingStyle}" ItemTemplate="{StaticResource BiliVideoCardViewTemplate2}" ItemClick="RelateVideoClick">
Expand Down
13 changes: 11 additions & 2 deletions HotPotPlayer/Pages/BilibiliSub/BiliVideoPlay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public async void StartPlay(object para, string targetCid = null, bool immediate
//await BiliBiliService.API.GetVideoWeb(bvid);
}

public async void RequestNavigateBack()
public async Task RequestNavigateFrom()
{
if (VideoPlayer.CurrentTime == TimeSpan.Zero && VideoPlayer.CurrentPlayingDuration.HasValue)
{
Expand All @@ -204,7 +204,6 @@ public async void RequestNavigateBack()
{
await Task.Run(() => StopPlay());
}
App.NavigateBack(true);
}

public void StopPlay()
Expand Down Expand Up @@ -477,5 +476,15 @@ string GetString(int v)
{
return v.ToHumanString();
}

private void TagClick(object sender, ItemClickEventArgs e)
{
var v = e.ClickedItem as Tag;
NavigateTo("BilibiliSub.Search", new SearchRequest
{
Keyword = v.Name,
DoSearch = true
});
}
}
}
19 changes: 15 additions & 4 deletions HotPotPlayer/Pages/BilibiliSub/Search.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using HotPotPlayer.Bilibili.Models.HomeVideo;
using HotPotPlayer.Bilibili.Models.Search;
using HotPotPlayer.Models.BiliBili;
using HotPotPlayer.Services;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand All @@ -17,6 +18,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;

Expand All @@ -41,17 +43,26 @@ public Search()
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var defa = e.Parameter as string;
SearchBox.Text = defa;
var req = e.Parameter as SearchRequest;
SearchBox.Text = req.Keyword;
if (req.DoSearch)
{
await DoSearch(req.Keyword);
}
}

private async void Search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
private async Task DoSearch(string keyword)
{
var search = await BiliBiliService.API.SearchAsync(sender.Text);
var search = await BiliBiliService.API.SearchAsync(keyword);
var video = search.Data.Result.FirstOrDefault(r => r.ResultType == "video");
VideoResult = video.Data;
}

private async void Search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
await DoSearch(sender.Text);
}

private void SearchVideoClick(object sender, ItemClickEventArgs e)
{
var v = e.ClickedItem as SearchResultData;
Expand Down

0 comments on commit 4454ed2

Please sign in to comment.