diff --git a/FoxTube/Channel.xaml b/FoxTube/Channel.xaml index e70757d..07ed001 100644 --- a/FoxTube/Channel.xaml +++ b/FoxTube/Channel.xaml @@ -58,11 +58,13 @@ - + - + + + diff --git a/FoxTube/Channel.xaml.cs b/FoxTube/Channel.xaml.cs index 09f6785..3e3b011 100644 --- a/FoxTube/Channel.xaml.cs +++ b/FoxTube/Channel.xaml.cs @@ -18,6 +18,7 @@ using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Text; +using Windows.Storage; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -28,6 +29,7 @@ namespace FoxTube /// public sealed partial class Channel : Page { + ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; public string channelId; public Google.Apis.YouTube.v3.Data.Channel item; VideoGrid videoGrid = new VideoGrid(); @@ -76,7 +78,7 @@ namespace FoxTube videos.Children.Add(videoGrid); - foreach(Google.Apis.YouTube.v3.Data.SearchResult vid in response2.Items) + foreach(SearchResult vid in response2.Items) { VideoCard vCard = new VideoCard(vid.Id.VideoId); videoGrid.AddCards(vCard); @@ -103,6 +105,7 @@ namespace FoxTube searchListRequest.Q = searchField.Text; searchListRequest.ChannelId = channelId; searchListRequest.MaxResults = 25; + searchListRequest.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"]; var response = await searchListRequest.ExecuteAsync(); @@ -168,5 +171,10 @@ namespace FoxTube else if (content.SelectedIndex == 2) toAbout.FontWeight = FontWeights.Bold; } + + private void showMorePlaylists_Click(object sender, RoutedEventArgs e) + { + + } } } diff --git a/FoxTube/Home.xaml b/FoxTube/Home.xaml index 0356e42..62ceb14 100644 --- a/FoxTube/Home.xaml +++ b/FoxTube/Home.xaml @@ -7,40 +7,40 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> - + - + - + - + - + - - + + - + - + - + diff --git a/FoxTube/Home.xaml.cs b/FoxTube/Home.xaml.cs index a68a23c..e391871 100644 --- a/FoxTube/Home.xaml.cs +++ b/FoxTube/Home.xaml.cs @@ -12,6 +12,11 @@ using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using System.Globalization; + +using Google.Apis.YouTube.v3; +using Google.Apis.YouTube.v3.Data; +using Windows.Storage; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -25,6 +30,66 @@ namespace FoxTube public Home() { this.InitializeComponent(); + Initialize(); + } + + public async void Initialize() + { + #region Vairables declaring + VideoGrid videoGrid = new VideoGrid(); + string reg = (ApplicationData.Current.LocalSettings.Values["region"] as string).ToUpper().Remove(0, 3); + #endregion + + pivot.Items.Clear(); + grid.RowDefinitions[0].Height = new GridLength(0); + + #region Request-Response + VideosResource.ListRequest request = SecretsVault.YoutubeService.Videos.List("snippet,contentDetails,statistics"); + request.Chart = VideosResource.ListRequest.ChartEnum.MostPopular; + request.RegionCode = reg; + request.MaxResults = 48; + + VideoListResponse response = await request.ExecuteAsync(); + #endregion + + foreach (Google.Apis.YouTube.v3.Data.Video vid in response.Items) + { + VideoCard vCard = new VideoCard(vid.Id); + videoGrid.AddCards(vCard); + } + + pivot.Items.Add(new PivotItem() + { + Margin = new Thickness(0,-48,0,0), + Name = "trending", + Content = videoGrid + }); + + /*if((Parent as MainPage).Logged) + { + grid.RowDefinitions[0].Height = new GridLength(47); + //TO-DO: Add initializing recommended and subscriptions tabs + }*/ + } + + private void toRecommended_Click(object sender, RoutedEventArgs e) + { + + } + + private void toTrending_Click(object sender, RoutedEventArgs e) + { + + } + + private void tosubs_Click(object sender, RoutedEventArgs e) + { + + } + + private void refresh_Click(object sender, RoutedEventArgs e) + { + Initialize(); } } } diff --git a/FoxTube/MainPage.xaml.cs b/FoxTube/MainPage.xaml.cs index c681b08..544ca2d 100644 --- a/FoxTube/MainPage.xaml.cs +++ b/FoxTube/MainPage.xaml.cs @@ -86,7 +86,9 @@ namespace FoxTube settings.Values.Add("volume", 100); if (settings.Values["region"] == null) - settings.Values.Add("region", CultureInfo.CurrentCulture); + settings.Values.Add("region", CultureInfo.CurrentCulture.Name); + if (settings.Values["safeSearch"] == null) + settings.Values.Add("safeSearch", 0); content.Navigate(typeof(Home)); } @@ -507,7 +509,9 @@ namespace FoxTube var searchListRequest = ytService.Search.List("snippet"); searchListRequest.Q = keyword; + searchListRequest.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"]; searchListRequest.MaxResults = 25; + searchListRequest.RelevanceLanguage = settings.Values["region"].ToString().Remove(2).ToLower(); var response = await searchListRequest.ExecuteAsync(); diff --git a/FoxTube/SecretsVault.cs b/FoxTube/SecretsVault.cs index e7c2b65..15eb4e9 100644 --- a/FoxTube/SecretsVault.cs +++ b/FoxTube/SecretsVault.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.YouTube.v3; +using Google.Apis.Auth.OAuth2.Flows; namespace FoxTube { @@ -39,7 +40,7 @@ namespace FoxTube { return new YouTubeService(new BaseClientService.Initializer() { - ApiKey = SecretsVault.YoutubeApi, + ApiKey = YoutubeApi, ApplicationName = "FoxTube" }); } @@ -49,6 +50,7 @@ namespace FoxTube { get { + //new UserCredential(new AuthorizationCodeFlow(new AuthorizationCodeFlow.Initializer("", "")), "userId", new Google.Apis.Auth.OAuth2.Responses.TokenResponse() { } ) return new ClientSecrets() { ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com", @@ -56,5 +58,43 @@ namespace FoxTube }; } } + + #region User credentials + private List credentials = new List(); //Test variable simulating actual credentials storage + + public void AddAccount() + { + + + credentials.Add( + new UserCredential( + new AuthorizationCodeFlow( + new AuthorizationCodeFlow.Initializer("https://accounts.google.com/o/oauth2/v2/auth", "https://www.googleapis.com/oauth2/v4/token")), + "", + new Google.Apis.Auth.OAuth2.Responses.TokenResponse() + { + AccessToken = "done", + ExpiresInSeconds = 1, + IdToken = "done", + TokenType = "done", + RefreshToken = "done", + Scope = "youtube" + })); + } + + public void DeleteAccount(int index) + { + credentials.RemoveAt(index); + } + + public UserCredential RetrieveAccount(int index) + { + return credentials[index]; + } + #endregion + + #region Authorization service functions + + #endregion } } diff --git a/FoxTube/Settings.xaml b/FoxTube/Settings.xaml index 8fcb883..224ace8 100644 --- a/FoxTube/Settings.xaml +++ b/FoxTube/Settings.xaml @@ -17,7 +17,7 @@ - + @@ -26,9 +26,11 @@ - - - + + + + + diff --git a/FoxTube/Settings.xaml.cs b/FoxTube/Settings.xaml.cs index b4f6a86..b877a07 100644 --- a/FoxTube/Settings.xaml.cs +++ b/FoxTube/Settings.xaml.cs @@ -48,8 +48,14 @@ namespace FoxTube mobileWarning.IsOn = (bool)settings.Values["moblieWarning"]; autoplay.IsOn = (bool)settings.Values["videoAutoplay"]; + safeSearch.SelectedIndex = (int)settings.Values["safeSearch"]; + foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures)) + { region.Items.Add(culture.DisplayName); + if (culture.Name == (string)settings.Values["region"]) + region.SelectedIndex = region.Items.Count - 1; + } } private void language_SelectionChanged(object sender, SelectionChangedEventArgs e) @@ -135,7 +141,12 @@ namespace FoxTube private void region_SelectionChanged(object sender, SelectionChangedEventArgs e) { - settings.Values["region"] = CultureInfo.GetCultures(CultureTypes.AllCultures)[region.SelectedIndex]; + settings.Values["region"] = CultureInfo.GetCultures(CultureTypes.AllCultures)[region.SelectedIndex].Name; + } + + private void safeSearch_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + settings.Values["safeSearch"] = safeSearch.SelectedIndex; } } }