From 0338d8a6260acb3a72a68fa01da6220d0f295617 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Sun, 22 Jul 2018 15:00:47 +0300 Subject: [PATCH] Development 7 --- FoxTube.Background/BackgroundProcessor.cs | 4 +- FoxTube.Background/Notification.cs | 10 +- FoxTube/Classes/SecretsVault.cs | 19 +- FoxTube/Controls/ChannelCard.xaml | 57 +++--- FoxTube/Controls/ChannelCard.xaml.cs | 42 +---- FoxTube/Controls/ChannelCardWide.xaml | 36 ++++ FoxTube/Controls/ChannelCardWide.xaml.cs | 50 +++++ FoxTube/Controls/ShowMore.xaml | 14 ++ FoxTube/Controls/ShowMore.xaml.cs | 44 +++++ FoxTube/Controls/VideoCard.xaml | 29 ++- FoxTube/Controls/VideoCard.xaml.cs | 98 +++++----- FoxTube/Controls/VideoCardWide.xaml.cs | 4 +- FoxTube/FoxTube.csproj | 20 +- FoxTube/Pages/Channel.xaml | 4 +- FoxTube/Pages/Home.xaml | 57 +++--- FoxTube/Pages/Home.xaml.cs | 107 ++++++++--- FoxTube/Pages/LoadingPage.xaml.cs | 9 +- FoxTube/Pages/MainPage.xaml | 6 +- FoxTube/Pages/MainPage.xaml.cs | 87 +++++---- FoxTube/Pages/Search.xaml | 93 ++++++--- FoxTube/Pages/Search.xaml.cs | 218 ++++++++++++++++++++-- FoxTube/Pages/Video.xaml.cs | 6 +- FoxTube/Pages/VideoGrid.xaml | 19 +- FoxTube/Pages/VideoGrid.xaml.cs | 53 +----- 24 files changed, 727 insertions(+), 359 deletions(-) create mode 100644 FoxTube/Controls/ChannelCardWide.xaml create mode 100644 FoxTube/Controls/ChannelCardWide.xaml.cs create mode 100644 FoxTube/Controls/ShowMore.xaml create mode 100644 FoxTube/Controls/ShowMore.xaml.cs diff --git a/FoxTube.Background/BackgroundProcessor.cs b/FoxTube.Background/BackgroundProcessor.cs index f014e58..5d91aa0 100644 --- a/FoxTube.Background/BackgroundProcessor.cs +++ b/FoxTube.Background/BackgroundProcessor.cs @@ -22,7 +22,7 @@ namespace FoxTube.Background { public static event NotificationHandler NotificationRecieved; - public List Notifications = new List(); + List Notifications = new List(); private DateTime lastCheck = DateTime.Now; private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; @@ -124,7 +124,7 @@ namespace FoxTube.Background doc["posts"].FirstChild["content"].InnerText, XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), XmlDateTimeSerializationMode.Unspecified), - (doc["posts"].FirstChild as XmlElement).GetAttribute("image"))); + (doc["posts"].FirstChild as XmlElement).GetAttribute("image"), null)); return doc.InnerXml; } diff --git a/FoxTube.Background/Notification.cs b/FoxTube.Background/Notification.cs index b78e9e7..a2c17b5 100644 --- a/FoxTube.Background/Notification.cs +++ b/FoxTube.Background/Notification.cs @@ -18,25 +18,25 @@ namespace FoxTube.Background Video, Comment, Post, Internal } - public class Notification + public sealed class Notification { public string Channel { get; set; } public string Content { get; set; } - public DateTime TimeStamp { get; set; } + public DateTimeOffset TimeStamp { get; set; } public NotificationType Type { get; set; } public string Avatar { get; set; } public string Thumbnail { get; set; } public string Id { get; set; } public Notification(string type, string id, - string channelName, string content, DateTime date, - string thumbnailUrl, string avatarUrl = "ms-appx:///Assets/Icons/Profile.png") + string channelName, string content, DateTimeOffset date, + string thumbnailUrl, string avatarUrl) { Channel = channelName; Content = content; TimeStamp = date; Type = TypeConversion(type); - Avatar = avatarUrl; + Avatar = avatarUrl == null? "ms-appx:///Assets/Icons/Profile.png" : avatarUrl; Thumbnail = thumbnailUrl; } diff --git a/FoxTube/Classes/SecretsVault.cs b/FoxTube/Classes/SecretsVault.cs index 0c87d88..e2ad26c 100644 --- a/FoxTube/Classes/SecretsVault.cs +++ b/FoxTube/Classes/SecretsVault.cs @@ -31,18 +31,27 @@ namespace FoxTube public static List WatchLater => Methods.MainPage.Vault.later; public static List UserHistory => Methods.MainPage.Vault.history; public static List Subscriptions => Methods.MainPage.Vault.subs; - + public static YouTubeService NoAuthService => new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", ApplicationName = "FoxTube" }); - public static YouTubeService Service => new YouTubeService(new BaseClientService.Initializer() + public static YouTubeService Service { - HttpClientInitializer = Vault.Credential, - ApplicationName = "FoxTube" - }); + get + { + if (IsAuthorized) + return new YouTubeService(new BaseClientService.Initializer() + { + HttpClientInitializer = Vault.Credential, + ApplicationName = "FoxTube" + }); + else + return NoAuthService; + } + } #endregion #region Object containers diff --git a/FoxTube/Controls/ChannelCard.xaml b/FoxTube/Controls/ChannelCard.xaml index 8f6ac65..b247145 100644 --- a/FoxTube/Controls/ChannelCard.xaml +++ b/FoxTube/Controls/ChannelCard.xaml @@ -1,36 +1,45 @@  + VerticalAlignment="Top" + SizeChanged="UserControl_SizeChanged" + d:DesignHeight="290" + d:DesignWidth="384"> - diff --git a/FoxTube/Controls/ChannelCard.xaml.cs b/FoxTube/Controls/ChannelCard.xaml.cs index c169f9e..e14ce94 100644 --- a/FoxTube/Controls/ChannelCard.xaml.cs +++ b/FoxTube/Controls/ChannelCard.xaml.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; @@ -12,54 +11,17 @@ 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.Media.Imaging; using Windows.UI.Xaml.Navigation; -using Google.Apis.Services; -using Google.Apis.YouTube.v3; -using Google.Apis.YouTube.v3.Data; - // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 -namespace FoxTube +namespace FoxTube.Controls { public sealed partial class ChannelCard : UserControl { - string channelId; - public ChannelCard(string id, string live) + public ChannelCard() { this.InitializeComponent(); - Initialize(id, live); - } - - public async void Initialize(string id, string live) - { - YouTubeService ytService = new YouTubeService(new BaseClientService.Initializer() - { - ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", - ApplicationName = this.GetType().ToString() - }); - - ChannelsResource.ListRequest request = ytService.Channels.List("snippet,contentDetails,statistics"); - request.Id = id; - ChannelListResponse response = await request.ExecuteAsync(); - - var item = response.Items[0]; - - channelId = id; - - channelName.Text = item.Snippet.Title; - subscribers.Text = string.Format("{0} subscribers", item.Statistics.SubscriberCount); - videoCount.Text = string.Format("{0} videos", item.Statistics.VideoCount); - - avatar.ProfilePicture = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url)); - if (live == "live") - liveTag.Visibility = Visibility.Visible; - } - - private void Button_Click(object sender, RoutedEventArgs e) - { - Methods.MainPage.GoToChannel(channelId); } } } diff --git a/FoxTube/Controls/ChannelCardWide.xaml b/FoxTube/Controls/ChannelCardWide.xaml new file mode 100644 index 0000000..5327558 --- /dev/null +++ b/FoxTube/Controls/ChannelCardWide.xaml @@ -0,0 +1,36 @@ + + + + diff --git a/FoxTube/Controls/ChannelCardWide.xaml.cs b/FoxTube/Controls/ChannelCardWide.xaml.cs new file mode 100644 index 0000000..312a0b6 --- /dev/null +++ b/FoxTube/Controls/ChannelCardWide.xaml.cs @@ -0,0 +1,50 @@ +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media.Imaging; +using Google.Apis.Services; +using Google.Apis.YouTube.v3; +using Google.Apis.YouTube.v3.Data; + +namespace FoxTube.Controls +{ + public sealed partial class ChannelCardWide : UserControl + { + string channelId; + public ChannelCardWide(string id, string live) + { + this.InitializeComponent(); + Initialize(id, live); + } + + public async void Initialize(string id, string live) + { + YouTubeService ytService = new YouTubeService(new BaseClientService.Initializer() + { + ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", + ApplicationName = this.GetType().ToString() + }); + + ChannelsResource.ListRequest request = ytService.Channels.List("snippet,contentDetails,statistics"); + request.Id = id; + ChannelListResponse response = await request.ExecuteAsync(); + + var item = response.Items[0]; + + channelId = id; + + channelName.Text = item.Snippet.Title; + subscribers.Text = string.Format("{0} subscribers", item.Statistics.SubscriberCount); + videoCount.Text = string.Format("{0} videos", item.Statistics.VideoCount); + + avatar.ProfilePicture = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url)); + if (live == "live") + liveTag.Visibility = Visibility.Visible; + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + Methods.MainPage.GoToChannel(channelId); + } + } +} diff --git a/FoxTube/Controls/ShowMore.xaml b/FoxTube/Controls/ShowMore.xaml new file mode 100644 index 0000000..2c57b25 --- /dev/null +++ b/FoxTube/Controls/ShowMore.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/FoxTube/Controls/ShowMore.xaml.cs b/FoxTube/Controls/ShowMore.xaml.cs new file mode 100644 index 0000000..9f60bb2 --- /dev/null +++ b/FoxTube/Controls/ShowMore.xaml.cs @@ -0,0 +1,44 @@ +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; + +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + +namespace FoxTube.Controls +{ + public delegate void Event(); + + public sealed partial class ShowMore : UserControl + { + public event Event Clicked; + public ShowMore() + { + this.InitializeComponent(); + } + + private void btn_Click(object sender, RoutedEventArgs e) + { + btn.Visibility = Visibility.Collapsed; + bar.Visibility = Visibility.Visible; + Clicked.Invoke(); + } + + public void Complete(bool close = false) + { + bar.Visibility = Visibility.Collapsed; + if (!close) + btn.Visibility = Visibility.Visible; + } + } +} diff --git a/FoxTube/Controls/VideoCard.xaml b/FoxTube/Controls/VideoCard.xaml index b835d83..057d57b 100644 --- a/FoxTube/Controls/VideoCard.xaml +++ b/FoxTube/Controls/VideoCard.xaml @@ -1,8 +1,7 @@  - diff --git a/FoxTube/Controls/VideoCard.xaml.cs b/FoxTube/Controls/VideoCard.xaml.cs index dd1bad1..6310f91 100644 --- a/FoxTube/Controls/VideoCard.xaml.cs +++ b/FoxTube/Controls/VideoCard.xaml.cs @@ -1,36 +1,21 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; -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; - -using Google.Apis.Services; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using Windows.UI.Xaml.Media.Imaging; using System.Xml; using Windows.System; +using Windows.UI.Popups; -// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 - -namespace FoxTube +namespace FoxTube.Controls { public sealed partial class VideoCard : UserControl { public string videoId; Google.Apis.YouTube.v3.Data.Video item; - bool embed = false; + bool embed = true; public VideoCard(string id) { this.InitializeComponent(); @@ -51,58 +36,73 @@ namespace FoxTube VideoListResponse response = await request.ExecuteAsync(); item = response.Items[0]; - videoId = id; title.Text = item.Snippet.Title; - views.Text = string.Format("{0} views", item.Statistics.ViewCount); - - string duration; - if (!string.IsNullOrWhiteSpace(item.ContentDetails.Duration)) - { - TimeSpan ts = XmlConvert.ToTimeSpan(item.ContentDetails.Duration); - duration = string.Format("{0}{1:00}:{2:00} | ", ts.Hours == 0 ? "" : ts.Hours + ":", ts.Minutes, ts.Seconds); - } - else duration = string.Empty; - - info.Text = string.Format("{0}{1} | {2}", duration, Methods.GetAgo(item.Snippet.PublishedAt.Value), (item.LiveStreamingDetails != null && item.LiveStreamingDetails.ConcurrentViewers.HasValue) ? item.LiveStreamingDetails.ConcurrentViewers + " viewers" : item.Statistics.ViewCount + " views"); - thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url)); + channelName.Text = item.Snippet.ChannelTitle; if (item.Snippet.LiveBroadcastContent == "live") { - embed = true; + views.Text = $"{item.LiveStreamingDetails.ConcurrentViewers} viewers"; + if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && item.LiveStreamingDetails.ScheduledEndTime.HasValue) + info.Text = $"{item.LiveStreamingDetails.ScheduledEndTime - item.LiveStreamingDetails.ScheduledStartTime} | {Methods.GetAgo(item.LiveStreamingDetails.ActualStartTime.Value)}"; + else + info.Text = item.LiveStreamingDetails.ActualStartTime.Value.ToString(); liveTag.Visibility = Visibility.Visible; } - else if (item.Snippet.LiveBroadcastContent == "upcoming") + else if(item.Snippet.LiveBroadcastContent == "upcoming") { - embed = true; - TimeSpan span; - if (item.LiveStreamingDetails.ScheduledStartTime != null && (item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now).Value.TotalMilliseconds > 0) - { - span = (TimeSpan)(item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now); - liveContent.Text = "Goes live in " + string.Format("{0}{1:00}:{2:00}:{3:00}", span.Days != 0 ? span.Days + ":" : "", span.Hours, span.Minutes, span.Seconds); - } + views.Text = ""; + if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && item.LiveStreamingDetails.ScheduledEndTime.HasValue) + info.Text = $"{item.LiveStreamingDetails.ScheduledEndTime - item.LiveStreamingDetails.ScheduledStartTime} | {item.LiveStreamingDetails.ScheduledStartTime}"; else - liveContent.Text = "Upcoming"; + info.Text = $"{Methods.GetAgo(item.Snippet.PublishedAt.Value)}"; liveTag.Visibility = Visibility.Visible; + + if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && (item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now).Value.TotalMilliseconds > 0) + liveContent.Text = $"Goes live in {item.LiveStreamingDetails.ScheduledStartTime}"; + else liveContent.Text = "Upcoming"; + } + else + { + views.Text = $"{item.Statistics.ViewCount} views"; + info.Text = $"{XmlConvert.ToTimeSpan(item.ContentDetails.Duration)} | {Methods.GetAgo(item.Snippet.PublishedAt.Value)}"; + embed = false; } - var request1 = ytService.Channels.List("snippet,contentDetails,statistics"); + var request1 = ytService.Channels.List("snippet"); request1.Id = item.Snippet.ChannelId; ChannelListResponse response1 = await request1.ExecuteAsync(); - var item1 = response1.Items[0]; + try + { + avatar.ProfilePicture = new BitmapImage(new Uri(response1.Items[0].Snippet.Thumbnails.Medium.Url)); + thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url)); + } + catch { } - avatar.ProfilePicture = new BitmapImage(new Uri(item1.Snippet.Thumbnails.Medium.Url)); - channelName.Text = item1.Snippet.Title; - - if (SecretsVault.UserHistory.Contains(item.Id)) - watched.Visibility = Visibility.Visible; + foreach(PlaylistItem i in SecretsVault.UserHistory) + if (i.Snippet.ResourceId.VideoId == id) + { + watched.Visibility = Visibility.Visible; + break; + } } private async void Button_Click(object sender, RoutedEventArgs e) { if (embed) - await Launcher.LaunchUriAsync(new Uri(string.Format("https://www.youtube.com/watch?v={0}", videoId))); + { + MessageDialog dialog = new MessageDialog("Unfortunately, at this stage of application development we don't support live steams. This issue will be fixed in the next update. Sorry. Would you like us to open this stream in browser?", "Open in browser"); + + dialog.Commands.Add(new UICommand("Yes", async (command) => + { + await Launcher.LaunchUriAsync(new Uri($"https://www.youtube.com/watch?v={videoId}")); + })); + dialog.Commands.Add(new UICommand("No")); + dialog.DefaultCommandIndex = 0; + dialog.CancelCommandIndex = 1; + await dialog.ShowAsync(); + } else Methods.MainPage.GoToVideo(videoId); } diff --git a/FoxTube/Controls/VideoCardWide.xaml.cs b/FoxTube/Controls/VideoCardWide.xaml.cs index 6842116..96c0c7a 100644 --- a/FoxTube/Controls/VideoCardWide.xaml.cs +++ b/FoxTube/Controls/VideoCardWide.xaml.cs @@ -92,8 +92,8 @@ namespace FoxTube channelName.Text = item1.Snippet.Title; channelSubs.Text = string.Format("{0} subscribers", item1.Statistics.SubscriberCount); - if (SecretsVault.UserHistory.Contains(item.Id)) - watched.Visibility = Visibility.Visible; + //if (SecretsVault.UserHistory.Contains(item.Id)) + //watched.Visibility = Visibility.Visible; } private void channelLink_Click(object sender, RoutedEventArgs e) diff --git a/FoxTube/FoxTube.csproj b/FoxTube/FoxTube.csproj index 5ea3b47..ad4453a 100644 --- a/FoxTube/FoxTube.csproj +++ b/FoxTube/FoxTube.csproj @@ -98,6 +98,9 @@ + + ChannelCard.xaml + CommentCard.xaml @@ -105,14 +108,17 @@ DownloadItem.xaml + + ShowMore.xaml + SuggestionsQueries.xaml Channel.xaml - - ChannelCard.xaml + + ChannelCardWide.xaml CommentsPage.xaml @@ -258,6 +264,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -266,6 +276,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -274,7 +288,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/FoxTube/Pages/Channel.xaml b/FoxTube/Pages/Channel.xaml index 07ed001..1b580e9 100644 --- a/FoxTube/Pages/Channel.xaml +++ b/FoxTube/Pages/Channel.xaml @@ -35,7 +35,7 @@ - + @@ -55,7 +55,7 @@ - + diff --git a/FoxTube/Pages/Home.xaml b/FoxTube/Pages/Home.xaml index 62ceb14..1e7aac2 100644 --- a/FoxTube/Pages/Home.xaml +++ b/FoxTube/Pages/Home.xaml @@ -9,39 +9,36 @@ - - + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + - - + + - - - - - - - + + + + + + diff --git a/FoxTube/Pages/Home.xaml.cs b/FoxTube/Pages/Home.xaml.cs index ec6d20c..fe60f54 100644 --- a/FoxTube/Pages/Home.xaml.cs +++ b/FoxTube/Pages/Home.xaml.cs @@ -17,6 +17,7 @@ using System.Globalization; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using Windows.Storage; +using Windows.UI.Text; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -27,6 +28,9 @@ namespace FoxTube /// public sealed partial class Home : Page { + private bool recLoaded = false; + private bool trendLoaded = false; + private bool subsLoaded = false; public Home() { this.InitializeComponent(); @@ -35,7 +39,6 @@ namespace FoxTube public async void Initialize() { - #region Vairables declaring VideoGrid videoGrid = new VideoGrid(); string reg; @@ -47,58 +50,106 @@ namespace FoxTube { reg = (ApplicationData.Current.LocalSettings.Values["region"] as string).ToUpper(); } - #endregion pivot.Items.Clear(); - grid.RowDefinitions[0].Height = new GridLength(0); - - #region Request-Response - VideosResource.ListRequest request = SecretsVault.NoAuthService.Videos.List("snippet,contentDetails,statistics"); - request.Chart = VideosResource.ListRequest.ChartEnum.MostPopular; - request.RegionCode = reg; + + VideosResource.ListRequest request = SecretsVault.Service.Videos.List("id"); request.MaxResults = 48; - VideoListResponse response = await request.ExecuteAsync(); - #endregion - - foreach (Google.Apis.YouTube.v3.Data.Video vid in response.Items) + if(SecretsVault.IsAuthorized) { - VideoCard vCard = new VideoCard(vid.Id); - videoGrid.AddCards(vCard); + navigation.Visibility = Visibility.Visible; + + for(int k = 0; k < 3; k++) + { + StackPanel stack = new StackPanel(); + stack.Children.Add(new VideoGrid()); + stack.Children.Add(new LoadingPage()); + pivot.Items.Add(new PivotItem() + { + Margin = new Thickness(0, -48, 0, 0), + Content = stack + }); + } + + //Initializing recommended videos loading + recLoaded = true; + (((pivot.Items[0] as PivotItem).Content as StackPanel).Children[1] as LoadingPage).Block(); } - - pivot.Items.Add(new PivotItem() + else { - Margin = new Thickness(0,-48,0,0), - Name = "trending", - Content = videoGrid - }); + Grid g = new Grid(); + StackPanel stack = new StackPanel(); + stack.Children.Add(new VideoGrid()); + stack.Children.Add(new HyperlinkButton() + { - /*if((Parent as MainPage).Logged) - { - grid.RowDefinitions[0].Height = new GridLength(47); - //TO-DO: Add initializing recommended and subscriptions tabs - }*/ + }); + g.Children.Add(stack); + g.Children.Add(new LoadingPage()); + pivot.Items.Add(new PivotItem() + { + Margin = new Thickness(0, -48, 0, 0), + Content = g + }); + + //Initializing recommended videos loading + request.Chart = VideosResource.ListRequest.ChartEnum.MostPopular; + request.RegionCode = reg; + VideoListResponse response = await request.ExecuteAsync(); + + foreach (Google.Apis.YouTube.v3.Data.Video vid in response.Items) + { + VideoCard vCard = new VideoCard(vid.Id); + videoGrid.AddCards(vCard); + } + trendLoaded = true; + } } private void toRecommended_Click(object sender, RoutedEventArgs e) { - + pivot.SelectedIndex = 0; } private void toTrending_Click(object sender, RoutedEventArgs e) { - + if (pivot.Items.Count > 1) + pivot.SelectedIndex = 1; + else + pivot.SelectedIndex = 0; } private void tosubs_Click(object sender, RoutedEventArgs e) { - + pivot.SelectedIndex = 2; } private void refresh_Click(object sender, RoutedEventArgs e) { Initialize(); } + + private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + toRecommended.FontWeight = FontWeights.Normal; + toTrending.FontWeight = FontWeights.Normal; + tosubs.FontWeight = FontWeights.Normal; + + switch(pivot.SelectedIndex) + { + case 2: + tosubs.FontWeight = FontWeights.Bold; + break; + case 1: + toTrending.FontWeight = FontWeights.Bold; + break; + case 0: + if (pivot.Items.Count > 1) + toRecommended.FontWeight = FontWeights.Bold; + else toTrending.FontWeight = FontWeights.Bold; + break; + } + } } } diff --git a/FoxTube/Pages/LoadingPage.xaml.cs b/FoxTube/Pages/LoadingPage.xaml.cs index d600d5f..af33bd4 100644 --- a/FoxTube/Pages/LoadingPage.xaml.cs +++ b/FoxTube/Pages/LoadingPage.xaml.cs @@ -22,7 +22,7 @@ namespace FoxTube /// public sealed partial class LoadingPage : Page { - public event EventHandler RefreshPage; + public event RoutedEventHandler RefreshPage; public LoadingPage() { @@ -54,6 +54,7 @@ namespace FoxTube public void Block() { + Visibility = Visibility.Visible; ring.IsActive = false; trouble.Visibility = Visibility.Collapsed; wifiTrouble.Visibility = Visibility.Collapsed; @@ -86,10 +87,16 @@ namespace FoxTube public void Refresh() { + Visibility = Visibility.Visible; ring.IsActive = true; trouble.Visibility = Visibility.Collapsed; wifiTrouble.Visibility = Visibility.Collapsed; blockIcon.Visibility = Visibility.Collapsed; } + + public void Close() + { + Visibility = Visibility.Collapsed; + } } } diff --git a/FoxTube/Pages/MainPage.xaml b/FoxTube/Pages/MainPage.xaml index d4c69d3..ee81734 100644 --- a/FoxTube/Pages/MainPage.xaml +++ b/FoxTube/Pages/MainPage.xaml @@ -108,6 +108,10 @@ + + + + @@ -211,7 +215,7 @@ - + diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index bfe06a3..3a3d531 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -195,41 +195,44 @@ namespace FoxTube private void HamburgerSelectionChanged(object sender, SelectionChangedEventArgs e) { - if(sender == mainList) + try { - subscriptionsList.SelectedItem = null; - categoriesList.SelectedItem = null; - serviceList.SelectedItem = null; - MainListSelected(); - } - else if (sender == subscriptionsList) - { - mainList.SelectedItem = null; - categoriesList.SelectedItem = null; - serviceList.SelectedItem = null; - SubscriptionSelected(); - } - else if(sender == categoriesList) - { - subscriptionsList.SelectedItem = null; - mainList.SelectedItem = null; - serviceList.SelectedItem = null; - FeaturedSelected(); - } - else if(sender == serviceList) - { - subscriptionsList.SelectedItem = null; - mainList.SelectedItem = null; - categoriesList.SelectedItem = null; - ServiceListSelected(); - } - else - { - mainList.SelectedItem = null; - subscriptionsList.SelectedItem = null; - categoriesList.SelectedItem = null; - serviceList.SelectedItem = null; - } + if (sender == mainList) + { + subscriptionsList.SelectedItem = null; + categoriesList.SelectedItem = null; + serviceList.SelectedItem = null; + MainListSelected(); + } + else if (sender == subscriptionsList) + { + mainList.SelectedItem = null; + categoriesList.SelectedItem = null; + serviceList.SelectedItem = null; + SubscriptionSelected(); + } + else if (sender == categoriesList) + { + subscriptionsList.SelectedItem = null; + mainList.SelectedItem = null; + serviceList.SelectedItem = null; + FeaturedSelected(); + } + else if (sender == serviceList) + { + subscriptionsList.SelectedItem = null; + mainList.SelectedItem = null; + categoriesList.SelectedItem = null; + ServiceListSelected(); + } + else + { + mainList.SelectedItem = null; + subscriptionsList.SelectedItem = null; + categoriesList.SelectedItem = null; + serviceList.SelectedItem = null; + } + } catch { } } void MainListSelected() @@ -372,8 +375,12 @@ namespace FoxTube private void menu_PaneOpened(SplitView sender, object args) { - subsTitle.Visibility = Visibility.Visible; - catTitle.Visibility = Visibility.Visible; + try + { + subsTitle.Visibility = Visibility.Visible; + catTitle.Visibility = Visibility.Visible; + } + catch { } } private async void createAccount_Click(object sender, RoutedEventArgs e) @@ -418,8 +425,10 @@ namespace FoxTube private void searchButton_Click(object sender, RoutedEventArgs e) { - if (searchField.Text != "" || (!(content.Content is Search) && (content.Content as Search).Term != searchField.Text)) + if (!string.IsNullOrWhiteSpace(searchField.Text) || !(content.Content is Search)) content.Navigate(typeof(Search), searchField.Text); + else if (content.Content is Search) + (content.Content as Search).Initialize(searchField.Text); } public void GoToSearch(string keyword) @@ -428,7 +437,7 @@ namespace FoxTube searchButton_Click(this, null); } - private async void StartSearch(string keyword) + /*private async void StartSearch(string keyword) { content.Navigate(typeof(Search)); HamburgerSelectionChanged(null, null); @@ -458,7 +467,7 @@ namespace FoxTube s.ring.IsActive = false; s.content.Visibility = Visibility.Visible; Debug.WriteLine("done"); - } + }*/ private void searchField_KeyUp(object sender, KeyRoutedEventArgs e) { diff --git a/FoxTube/Pages/Search.xaml b/FoxTube/Pages/Search.xaml index cd14a26..10017a4 100644 --- a/FoxTube/Pages/Search.xaml +++ b/FoxTube/Pages/Search.xaml @@ -5,41 +5,76 @@ xmlns:local="using:FoxTube" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:controls="using:FoxTube.Controls" mc:Ignorable="d"> - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +