From 4639b9c77bcf49820b1d40bcb7b5d540783f7e56 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Fri, 24 Aug 2018 00:07:05 +0300 Subject: [PATCH] Fullscreen and miniview mode fixed; Playlist tab on video page --- FoxTube/App.xaml.cs | 9 ++++ FoxTube/Controls/VideoPlayer.xaml.cs | 2 +- FoxTube/Pages/MainPage.xaml | 21 +++++++-- FoxTube/Pages/MainPage.xaml.cs | 29 ++++++------ FoxTube/Pages/VideoPage.xaml | 69 ++++++++++++++++++---------- FoxTube/Pages/VideoPage.xaml.cs | 62 +++++++++++++++++++++++-- 6 files changed, 145 insertions(+), 47 deletions(-) diff --git a/FoxTube/App.xaml.cs b/FoxTube/App.xaml.cs index 0fb44a2..9cb77e9 100644 --- a/FoxTube/App.xaml.cs +++ b/FoxTube/App.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; @@ -47,6 +48,14 @@ namespace FoxTube } catch { } try { + if (settings.Values["language"] == null) + { + List cultures = new List() { "ua", "ru", "by", "kz", "kg", "md", "lv", "ee" }; + if (cultures.Contains(CultureInfo.InstalledUICulture.ThreeLetterISOLanguageName)) + settings.Values.Add("language", "ru-RU"); + else + settings.Values.Add("language", "en-US"); + } ApplicationLanguages.PrimaryLanguageOverride = (string)settings.Values["language"]; } catch { } diff --git a/FoxTube/Controls/VideoPlayer.xaml.cs b/FoxTube/Controls/VideoPlayer.xaml.cs index 54a95fc..8f5507e 100644 --- a/FoxTube/Controls/VideoPlayer.xaml.cs +++ b/FoxTube/Controls/VideoPlayer.xaml.cs @@ -42,7 +42,7 @@ namespace FoxTube private bool miniView = false; private bool fullScreen = false; - private bool pointerCaptured = false; + public bool pointerCaptured = false; public event ObjectEventHandler SetFullSize; public event ObjectEventHandler NextClicked; diff --git a/FoxTube/Pages/MainPage.xaml b/FoxTube/Pages/MainPage.xaml index d113eb1..8cf4eff 100644 --- a/FoxTube/Pages/MainPage.xaml +++ b/FoxTube/Pages/MainPage.xaml @@ -12,7 +12,20 @@ SizeChanged="Page_SizeChanged"> - + + + + + + + + + + + + + + @@ -52,13 +65,13 @@ - + - - + + - + - + - - - - - - - - - + + + + + + - - + + + + + + + + + + + + + + + + + + diff --git a/FoxTube/Pages/VideoPage.xaml.cs b/FoxTube/Pages/VideoPage.xaml.cs index a71fc0b..9f6594c 100644 --- a/FoxTube/Pages/VideoPage.xaml.cs +++ b/FoxTube/Pages/VideoPage.xaml.cs @@ -39,6 +39,21 @@ namespace FoxTube.Pages { public enum Rating { None, Like, Dislike } + public class VideoPlaylistItem + { + public int Number { get; set; } + public string Thumbnail { get; private set; } = "/Assets/videoThumbSample.png"; + public string Id { get; private set; } + public string Title { get; private set; } + + public VideoPlaylistItem(string image, string title, string id) + { + Thumbnail = image; + Title = title; + Id = id; + } + } + /// /// An empty page that can be used on its own or navigated to within a Frame. /// @@ -116,6 +131,10 @@ namespace FoxTube.Pages if (ids[1] != null) { + playlistId = ids[1]; + List items = new List(); + VideoPlaylistItem selection = null; + PlaylistsResource.ListRequest playlistRequest = SecretsVault.Service.Playlists.List("snippet,contentDetails"); playlistRequest.Id = ids[1]; Playlist playlistItem = (await playlistRequest.ExecuteAsync()).Items[0]; @@ -124,10 +143,40 @@ namespace FoxTube.Pages playlistChannel.Text = playlistItem.Snippet.ChannelTitle; PlaylistItemsResource.ListRequest listRequest = SecretsVault.Service.PlaylistItems.List("snippet"); + listRequest.MaxResults = 50; listRequest.PlaylistId = ids[1]; PlaylistItemListResponse listResponse = await listRequest.ExecuteAsync(); - //Initialize playlist tab + foreach (PlaylistItem i in listResponse.Items) + { + items.Add(new VideoPlaylistItem(i.Snippet.Thumbnails.Medium.Url, i.Snippet.Title, i.Snippet.ResourceId.VideoId)); + if (items.Last().Id == videoId) + selection = items.Last(); + } + + string token = listResponse.NextPageToken; + while(!string.IsNullOrWhiteSpace(token)) + { + listRequest.PageToken = token; + listResponse = await listRequest.ExecuteAsync(); + + foreach (PlaylistItem i in listResponse.Items) + { + items.Add(new VideoPlaylistItem(i.Snippet.Thumbnails.Medium.Url, i.Snippet.Title, i.ContentDetails.VideoId)); + if (items.Last().Id == videoId) + selection = items.Last(); + } + + token = listResponse.NextPageToken; + } + + for (int k = 0; k < items.Count; k++) + items[k].Number = k + 1; + + playlistCounter.Text = $"{items.IndexOf(selection) + 1}/{playlistItem.ContentDetails.ItemCount}"; + + playlistList.ItemsSource = items; + playlistList.SelectedItem = selection; } else pivot.Items.Remove(playlist); @@ -197,9 +246,9 @@ namespace FoxTube.Pages { loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true); } - catch + catch (Exception e) { - loading.Error(); + loading.Error(e.HResult.ToString(), e.Message); } } @@ -303,6 +352,7 @@ namespace FoxTube.Pages private void grid_SizeChanged(object sender, SizeChangedEventArgs e) { + Debug.WriteLine(e.NewSize.Width); if (e.NewSize.Width > 1000) wide = true; else @@ -456,5 +506,11 @@ namespace FoxTube.Pages break; } } + + private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if ((e.AddedItems[0] as VideoPlaylistItem).Id != videoId) + Methods.MainPage.GoToVideo((e.AddedItems[0] as VideoPlaylistItem).Id, playlistId); + } } }