From daa93ad5f908fcf91cb8283698417f208222f169 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+DineshSolanki@users.noreply.github.com> Date: Fri, 2 Aug 2024 23:11:41 +0530 Subject: [PATCH] Feature: Add option to View all available videos for a media in poster mode instead of default one earlier (#216) * dummy: Add Video selector to HtmlBox control Introduced a new Video model and integrated a ComboBox for video selection in the HtmlBox control. Updated the HtmlBox.cs to handle video selection and loaded videos dynamically. * feature: Add support for displaying multiple videos Introduced a new Videos property in ListItem to handle a collection of videos. Updated SearchResultViewModel to set this property and modified SearchResult and HtmlBox views to bind and display these videos. * fix: Rename and refactor Video model to MediaVideo Renamed `Video` to `MediaVideo` and updated its properties. Adjusted references throughout the project, ensuring consistent naming and functionality improvements. Removed redundant trailer selection logic and optimized video processing in the SearchResultViewModel and HtmlBox components. * refactor: Remove unused method from SearchResultViewModel Removed the SetTrailer method from SearchResultViewModel as it was not being used. Also cleaned up unnecessary using statement in HtmlBox.xaml.cs. --- FoliCon/Models/Data/ListItem.cs | 9 ++- FoliCon/Models/Data/MediaVideo.cs | 3 + .../InvertedTextToVisibilityConverter.cs | 2 +- .../Convertor/TextToVisibilityConverter.cs | 2 +- FoliCon/ViewModels/SearchResultViewModel.cs | 72 +++++++++++-------- FoliCon/Views/HtmlBox.xaml | 12 +++- FoliCon/Views/HtmlBox.xaml.cs | 51 ++++++++++++- FoliCon/Views/SearchResult.xaml | 2 +- 8 files changed, 115 insertions(+), 38 deletions(-) create mode 100644 FoliCon/Models/Data/MediaVideo.cs diff --git a/FoliCon/Models/Data/ListItem.cs b/FoliCon/Models/Data/ListItem.cs index d70bbb68..88c46231 100644 --- a/FoliCon/Models/Data/ListItem.cs +++ b/FoliCon/Models/Data/ListItem.cs @@ -12,6 +12,8 @@ public class ListItem : BindableBase private Uri _trailerLink; private string _id; private MediaType _mediaType = MediaType.Unknown; + + private ICollection _videos; private string _initialPoster; private bool _isInitialSet; @@ -79,7 +81,12 @@ public string TrailerKey get => _trailerKey; set => SetProperty(ref _trailerKey, value); } - + + public ICollection Videos + { + get => _videos; + set => SetProperty(ref _videos, value); + } public string Id { get => _id; diff --git a/FoliCon/Models/Data/MediaVideo.cs b/FoliCon/Models/Data/MediaVideo.cs new file mode 100644 index 00000000..6d0cd2b1 --- /dev/null +++ b/FoliCon/Models/Data/MediaVideo.cs @@ -0,0 +1,3 @@ +namespace FoliCon.Models.Data; + +public record MediaVideo(string Name, string Url); \ No newline at end of file diff --git a/FoliCon/Modules/Convertor/InvertedTextToVisibilityConverter.cs b/FoliCon/Modules/Convertor/InvertedTextToVisibilityConverter.cs index d8d580fe..9aa01b07 100644 --- a/FoliCon/Modules/Convertor/InvertedTextToVisibilityConverter.cs +++ b/FoliCon/Modules/Convertor/InvertedTextToVisibilityConverter.cs @@ -6,7 +6,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn { if (value is string text) { - return text == "Video not available!" ? Visibility.Visible : Visibility.Hidden; + return text is "" or "Video not available!" ? Visibility.Visible : Visibility.Hidden; } return Visibility.Hidden; diff --git a/FoliCon/Modules/Convertor/TextToVisibilityConverter.cs b/FoliCon/Modules/Convertor/TextToVisibilityConverter.cs index a09c52bf..c9cf6e4d 100644 --- a/FoliCon/Modules/Convertor/TextToVisibilityConverter.cs +++ b/FoliCon/Modules/Convertor/TextToVisibilityConverter.cs @@ -5,7 +5,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn { if (value is string text) { - return text == "Video not available!" ? Visibility.Hidden : Visibility.Visible; + return text is "" or "Video not available!" ? Visibility.Hidden : Visibility.Visible; } return Visibility.Hidden; diff --git a/FoliCon/ViewModels/SearchResultViewModel.cs b/FoliCon/ViewModels/SearchResultViewModel.cs index 810471f2..4c2552f3 100644 --- a/FoliCon/ViewModels/SearchResultViewModel.cs +++ b/FoliCon/ViewModels/SearchResultViewModel.cs @@ -6,6 +6,8 @@ namespace FoliCon.ViewModels; public class SearchResultViewModel : BindableBase, IDialogAware { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private const string YoutubeEmbedUrl = "https://www.youtube.com/embed/{0}"; + #region Variables private string _title = Lang.SearchResult; @@ -434,10 +436,9 @@ private async Task GetGameTrailer(string itemId) { return; } - - var key = r.First(v => v.Name == "Trailer"); - SetTrailer(key.VideoId); + SetVideos(r); } + private async Task GetMovieTrailer(string itemId) { @@ -447,15 +448,7 @@ private async Task GetMovieTrailer(string itemId) if (result != null) { - var trailer = ChooseTrailer(result.Results); - if (trailer != null) - { - SetTrailer(trailer.Key); - } - else - { - Logger.Warn("No trailer found for {Title}", ResultListViewData.SelectedItem.Title); - } + SetVideos(result.Results); } } catch (Exception ex) @@ -472,32 +465,51 @@ private async Task GetTvTrailer(string itemId) { return; } + SetVideos(result.Results); + } - var i = ChooseTrailer(result.Results); - - if (i != null) + private static Video ChooseTrailer(IReadOnlyCollection