diff --git a/FoxTube/Classes/ObjectEventArgs.cs b/FoxTube/Classes/ObjectEventArgs.cs index eea6edf..db18307 100644 --- a/FoxTube/Classes/ObjectEventArgs.cs +++ b/FoxTube/Classes/ObjectEventArgs.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Google.Apis.YouTube.v3.SearchResource.ListRequest; namespace FoxTube { @@ -10,7 +11,7 @@ namespace FoxTube public delegate void ObjectEventHandler(object sender, params object[] args); - public class SearchParameters + /*public class SearchParameters { public string ChannelId { get; set; } public string Term { get; set; } @@ -20,5 +21,129 @@ namespace FoxTube ChannelId = channelId; Term = term; } + }*/ + + public class SearchParameters + { + public class Filters + { + public static class Enumerations + { + public enum Order { Relevance, Date, Views, Rating, Title } + public enum Type { All, Video, Channel, Playlist } + public enum Date { Any, Hour, Today, Week, Month, Year } + public enum Duration { Any, Long, Medium, Short } + public enum ConversionType { Order, Type, Date, Duration, HD, ThreeD, Captions, LiveEvent, CreativeCommons } + } + + public Enumerations.Order Order { get; set; } = Enumerations.Order.Relevance; + public Enumerations.Date Date { get; set; } = Enumerations.Date.Any; + public Enumerations.Type Type { get; set; } = Enumerations.Type.All; + public Enumerations.Duration Duration { get; set; } = Enumerations.Duration.Any; + public bool HD { get; set; } = false; + public bool Is3D { get; set; } = false; + public bool Captions { get; set; } = false; + public bool LiveEvent { get; set; } = false; + public bool CreativeCommons { get; set; } = false; + + public object GetParameter(Enumerations.ConversionType type) + { + switch(type) + { + case Enumerations.ConversionType.Captions: + if (Captions) + return VideoCaptionEnum.ClosedCaption; + else return null; + case Enumerations.ConversionType.CreativeCommons: + if (CreativeCommons) + return VideoLicenseEnum.CreativeCommon; + else return null; + case Enumerations.ConversionType.Date: + switch(Date) + { + case Enumerations.Date.Any: + return null; + case Enumerations.Date.Hour: + return DateTime.Now.Subtract(TimeSpan.FromHours(1)); + case Enumerations.Date.Today: + return DateTime.Now.Subtract(TimeSpan.FromDays(1)); + case Enumerations.Date.Week: + return DateTime.Now.Subtract(TimeSpan.FromDays(7)); + case Enumerations.Date.Month: + return DateTime.Now.Subtract(TimeSpan.FromDays(31)); + case Enumerations.Date.Year: + return DateTime.Now.Subtract(TimeSpan.FromDays(365)); + } + break; + case Enumerations.ConversionType.Duration: + return (VideoDurationEnum)Duration; + case Enumerations.ConversionType.HD: + if (HD) + return VideoDefinitionEnum.High; + else return null; + case Enumerations.ConversionType.LiveEvent: + if (LiveEvent) + return EventTypeEnum.Live; + else return null; + case Enumerations.ConversionType.Order: + Dictionary d = new Dictionary() + { + { 0, 2 }, + { 1, 0 }, + { 2, 5 }, + { 3, 1 }, + { 4, 3 } + }; + return (OrderEnum)d[(int)Order]; + case Enumerations.ConversionType.ThreeD: + if (Is3D) + return VideoDimensionEnum.Value3d; + else return null; + case Enumerations.ConversionType.Type: + switch(Type) + { + case Enumerations.Type.All: + return "video,channel,playlist"; + case Enumerations.Type.Channel: + return "channel"; + case Enumerations.Type.Playlist: + return "playlist"; + case Enumerations.Type.Video: + return "video"; + } + break; + } + return null; + } + } + + public string Term { get; private set; } + public string Channel { get; private set; } + public Filters Filter { get; private set; } = new Filters(); + + + public SearchParameters(string term) + { + Term = term; + } + + public SearchParameters(string term, Filters filters) + { + Term = term; + Filter = filters; + } + + public SearchParameters(string term, string channelId) + { + Term = term; + Channel = channelId; + } + + public SearchParameters(string term, string channelId, Filters filters) + { + Term = term; + Channel = channelId; + Filter = filters; + } } } diff --git a/FoxTube/Controls/VideoPlayer.xaml b/FoxTube/Controls/VideoPlayer.xaml index 0269e3d..0bfc289 100644 --- a/FoxTube/Controls/VideoPlayer.xaml +++ b/FoxTube/Controls/VideoPlayer.xaml @@ -12,7 +12,8 @@ RequestedTheme="Dark" PointerMoved="UserControl_PointerMoved" PointerExited="UserControl_PointerExited" - PointerEntered="UserControl_PointerEntered"> + PointerEntered="UserControl_PointerEntered" + KeyUp="UserControl_KeyUp"> diff --git a/FoxTube/Controls/VideoPlayer.xaml.cs b/FoxTube/Controls/VideoPlayer.xaml.cs index c9e7829..5cf1e14 100644 --- a/FoxTube/Controls/VideoPlayer.xaml.cs +++ b/FoxTube/Controls/VideoPlayer.xaml.cs @@ -31,6 +31,7 @@ using Windows.ApplicationModel.Core; using Windows.UI; using Windows.Graphics.Display; using Windows.Media.Casting; +using YoutubeExplode.Models.MediaStreams; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 @@ -659,12 +660,14 @@ namespace FoxTube private void fwd30_Click(object sender, RoutedEventArgs e) { - videoSource.Position = elapsed.Add(TimeSpan.FromSeconds(30)); + if(remaining.TotalSeconds >= 30) + videoSource.Position = elapsed.Add(TimeSpan.FromSeconds(30)); } private void back10_Click(object sender, RoutedEventArgs e) { - videoSource.Position = elapsed.Subtract(TimeSpan.FromSeconds(10)); + if (elapsed.TotalSeconds >= 10) + videoSource.Position = elapsed.Subtract(TimeSpan.FromSeconds(10)); } private void UserControl_PointerExited(object sender, PointerRoutedEventArgs e) @@ -800,5 +803,26 @@ namespace FoxTube if (e.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse && !miniView) play_Click(this, null); } + + private void UserControl_KeyUp(object sender, KeyRoutedEventArgs e) + { + switch(e.Key) + { + case Windows.System.VirtualKey.Escape: + case Windows.System.VirtualKey.F11: + if (fullScreen) + fullscreen_Click(this, null); + break; + case Windows.System.VirtualKey.Space: + play_Click(this, null); + break; + case Windows.System.VirtualKey.Left: + back10_Click(this, null); + break; + case Windows.System.VirtualKey.Right: + fwd30_Click(this, null); + break; + } + } } } diff --git a/FoxTube/FoxTube.csproj b/FoxTube/FoxTube.csproj index 014243e..22f5e01 100644 --- a/FoxTube/FoxTube.csproj +++ b/FoxTube/FoxTube.csproj @@ -428,6 +428,9 @@ 4.3.1 + + 4.3.1 + diff --git a/FoxTube/Pages/ChannelPage.xaml.cs b/FoxTube/Pages/ChannelPage.xaml.cs index 20c240e..a419167 100644 --- a/FoxTube/Pages/ChannelPage.xaml.cs +++ b/FoxTube/Pages/ChannelPage.xaml.cs @@ -172,6 +172,7 @@ namespace FoxTube.Pages playlistRequest = SecretsVault.Service.Search.List("id"); playlistRequest.ChannelId = channelId; + playlistRequest.Order = SearchResource.ListRequest.OrderEnum.Date; playlistRequest.Type = "playlist"; playlistRequest.MaxResults = 48; @@ -276,18 +277,21 @@ namespace FoxTube.Pages private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { - if (content.Items.Count == 4) - (((content.Items[3] as PivotItem).Content as Frame).Content as Search).Initialize(new SearchParameters(item.Id, search.Text)); - else + if(search.Text.Length > 2) { - content.Items.Add(new PivotItem() + if (content.Items.Count == 4) + ((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(search.Text, item.Id)); + else { - Content = new Frame() - }); - ((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(item.Id, search.Text)); - } + content.Items.Add(new PivotItem() + { + Content = new Frame() + }); + ((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(search.Text, item.Id)); + } - content.SelectedIndex = 3; + content.SelectedIndex = 3; + } } private void refresh_Click(object sender, RoutedEventArgs e) diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index 64eb096..04d1c81 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -41,6 +41,8 @@ using FoxTube.Pages; using Microsoft.Toolkit.Uwp.UI.Controls; using Windows.ApplicationModel; using System.Net; +using Windows.UI.Popups; +using Windows.Networking.Connectivity; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 @@ -303,18 +305,10 @@ namespace FoxTube SecretsVault.Deauthenticate(); } - public void GoToSearch(string keyword = null) + public void GoToSearch(SearchParameters args) { - if(keyword != null) - search.Text = keyword; - - if (!string.IsNullOrWhiteSpace(search.Text)) - { - if (!(content.Content is Search)) - content.Navigate(typeof(Search), search.Text); - else if ((content.Content as Search).Term != search.Text) - (content.Content as Search).Initialize(search.Text); - } + MinimizeAsInitializer(); + content.Navigate(typeof(Search), args); } public void GoToChannel(string id) @@ -323,8 +317,30 @@ namespace FoxTube content.Navigate(typeof(ChannelPage), id); } - public void GoToVideo(string id, string playlistId = null) + public async void GoToVideo(string id, string playlistId = null) { + var connection = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost(); + if ((bool)settings.Values["moblieWarning"] && (connection.NetworkCostType == NetworkCostType.Fixed || connection.NetworkCostType == NetworkCostType.Variable)) + { + bool cancel = false; + MessageDialog dialog = new MessageDialog("You are on metered connection now. Additional charges may apply. Do you want to continue?") + { + DefaultCommandIndex = 2, + CancelCommandIndex = 1 + }; + dialog.Commands.Add(new UICommand("Yes")); + dialog.Commands.Add(new UICommand("No", (command) => cancel = true)); + dialog.Commands.Add(new UICommand("Add to 'Watch later' playlist", (command) => + { + //TO-DO: Adding video to "Watch later" + cancel = true; + })); + await dialog.ShowAsync(); + + if (cancel) + return; + } + nav.IsPaneOpen = false; videoPlaceholder.Content = null; @@ -421,7 +437,7 @@ namespace FoxTube private void search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { - GoToSearch(); + GoToSearch(new SearchParameters(search.Text)); } private void search_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args) diff --git a/FoxTube/Pages/Search.xaml b/FoxTube/Pages/Search.xaml index 6a19b2f..0ed8d0e 100644 --- a/FoxTube/Pages/Search.xaml +++ b/FoxTube/Pages/Search.xaml @@ -46,9 +46,9 @@ - - + + @@ -65,7 +65,7 @@ -