Archived
1
0

Fullscreen and miniview mode fixed; Playlist tab on video page

This commit is contained in:
Michael Gordeev
2018-08-24 00:07:05 +03:00
parent ed29af9463
commit 4639b9c77b
6 changed files with 145 additions and 47 deletions
+9
View File
@@ -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<string> cultures = new List<string>() { "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 { }
+1 -1
View File
@@ -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;
+17 -4
View File
@@ -12,7 +12,20 @@
SizeChanged="Page_SizeChanged">
<Grid Name="grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<NavigationView SelectedItem="toHome" BackRequested="nav_BackRequested" PaneTitle="FoxTube" OpenPaneLength="300" Name="nav" IsPaneOpen="False" SelectionChanged="nav_SelectionChanged">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="641"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="header.FontSize" Value="28"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<NavigationView SelectedItem="toHome" BackRequested="nav_BackRequested" PaneTitle="FoxTube" OpenPaneLength="300" Name="nav" SelectionChanged="nav_SelectionChanged">
<NavigationView.MenuItems>
<NavigationViewItem x:Uid="/Main/home" Icon="Home" Content="Home" Name="toHome"/>
@@ -52,13 +65,13 @@
</NavigationView.AutoSuggestBox>
<NavigationView.Header>
<Grid>
<Grid Margin="10,25,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock FontSize="28" VerticalAlignment="Center" Text="Home" Name="header"/>
<StackPanel Orientation="Horizontal" Grid.Column="1" Margin="10,25,0,-11">
<TextBlock FontSize="24" VerticalAlignment="Center" Text="Home" Name="header"/>
<StackPanel Orientation="Horizontal" Grid.Column="1">
<Button Name="notificationMenu" Click="notificationMenu_Click"
FontFamily="Segoe MDL2 Assets" Content="&#xED0D;"
Width="50" Height="50" Background="Transparent" x:Uid="notifications" ToolTipService.ToolTip="Notifications">
+13 -14
View File
@@ -40,6 +40,7 @@ using FoxTube.Controls;
using FoxTube.Pages;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Windows.ApplicationModel;
using System.Net;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -63,14 +64,6 @@ namespace FoxTube
{
this.InitializeComponent();
if (settings.Values["language"] == null)
{
List<string> cultures = new List<string>() { "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");
}
if (settings.Values["quality"] == null)
settings.Values.Add("quality", 1);
@@ -258,7 +251,6 @@ namespace FoxTube
nav.SelectedItem = toHome;
content.Navigate(typeof(Home));
content.CacheSize = 0;
if (videoPlaceholder.Content != null)
GoToVideo((videoPlaceholder.Content as VideoPage).videoId);
@@ -389,13 +381,18 @@ namespace FoxTube
{
if (on)
{
nav.Margin = new Thickness(-48, -93, 0, 0);
nav.OpenPaneLength = 48;
nav.OpenPaneLength = 0;
nav.CompactPaneLength = 0;
if (nav.DisplayMode == NavigationViewDisplayMode.Minimal)
nav.Margin = new Thickness(0, -80, 0, 0);
else
nav.Margin = new Thickness(0, -91, 0, 0);
}
else
{
nav.Margin = new Thickness(0);
nav.OpenPaneLength = 300;
nav.CompactPaneLength = 48;
}
}
@@ -406,6 +403,7 @@ namespace FoxTube
ApplicationView.GetForCurrentView().ExitFullScreenMode();
Fullscreen(false);
}
(videoPlaceholder.Content as VideoPage).player.pointerCaptured = false;
videoPlaceholder.Content = null;
MaximizeVideo();
@@ -422,12 +420,13 @@ namespace FoxTube
private void search_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if(search.Text.Length > 2)
if (search.Text.Length > 2 && args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load($"http://suggestqueries.google.com/complete/search?ds=yt&output=toolbar&hl={CultureInfo.CurrentUICulture.TwoLetterISOLanguageName}&q={search.Text}");
string reg = (settings.Values["region"] as string).Length > 2 ? (settings.Values["region"] as string).Remove(2) : (settings.Values["region"] as string);
doc.Load($"http://suggestqueries.google.com/complete/search?ds=yt&output=toolbar&hl={reg}&q={WebUtility.UrlEncode(search.Text)}");
List<string> suggestions = new List<string>();
@@ -436,7 +435,7 @@ namespace FoxTube
search.ItemsSource = suggestions;
}
catch (System.Net.WebException)
catch (WebException)
{
search.ItemsSource = new List<string>();
}
+33 -12
View File
@@ -12,6 +12,21 @@
<Grid Name="grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" SizeChanged="grid_SizeChanged">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ratingPanel.(Grid.Row)" Value="0"/>
<Setter Target="ratingPanel.(HorizontalAlignment)" Value="Right"/>
<Setter Target="rating.Width" Value="250"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="400"/>
@@ -22,6 +37,10 @@
<StackPanel Margin="10" Name="descriptionPanel">
<TextBlock IsTextSelectionEnabled="True" Name="title" Text="[Video title]" FontSize="25" TextWrapping="WrapWholeWords" HorizontalTextAlignment="Start"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Padding="0" Background="Transparent" Margin="5" Name="gotoChannel" Click="gotoChannel_Click">
<StackPanel Orientation="Horizontal">
<PersonPicture Name="channelAvatar" Width="90"/>
@@ -32,9 +51,9 @@
</StackPanel>
</StackPanel>
</Button>
<StackPanel HorizontalAlignment="Right">
<StackPanel HorizontalAlignment="Stretch" Name="ratingPanel" Grid.Row="1">
<TextBlock Name="views" Text="[views]" FontSize="24" Foreground="Gray"/>
<ProgressBar Name="rating" Width="250" Background="Green" Foreground="Red"/>
<ProgressBar Name="rating" Background="Green" Foreground="Red"/>
<Grid>
<FontIcon Foreground="Gray"
HorizontalAlignment="Left"
@@ -104,29 +123,31 @@
<pages:CommentsPage/>
</PivotItem>
<PivotItem Header="Playlist" Name="playlist">
<ScrollViewer>
<StackPanel>
<StackPanel Padding="8" Background="WhiteSmoke">
<StackPanel Padding="8" Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}">
<TextBlock Text="Music" FontSize="26" TextWrapping="WrapWholeWords" Name="playlistName"/>
<TextBlock Text="DAGames" Name="playlistChannel"/>
<TextBlock Text="15/155" Name="playlistCounter"/>
</StackPanel>
<ScrollViewer>
<StackPanel Name="playlistList">
<Button HorizontalAlignment="Stretch" Height="75" HorizontalContentAlignment="Stretch" Background="Transparent">
<Grid>
<ListBox Background="Transparent" SelectionChanged="ListBox_SelectionChanged" Name="playlistList">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Tag="{Binding Path=Id}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="15" VerticalAlignment="Center" Margin="0,0,8,0"/>
<Image Grid.Column="1" Source="/Assets/videoThumbSample.png"/>
<TextBlock Grid.Column="2" Margin="8,0,0,0" VerticalAlignment="Center" TextWrapping="WrapWholeWords" Text="Title"/>
<TextBlock Text="{Binding Path=Number}" VerticalAlignment="Center" Margin="0,0,8,0"/>
<Image Grid.Column="1" Source="{Binding Path=Thumbnail}" Height="65"/>
<TextBlock Grid.Column="2" Margin="8,0,0,0" VerticalAlignment="Center" TextWrapping="WrapWholeWords" Text="{Binding Path=Title}"/>
</Grid>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</ScrollViewer>
</StackPanel>
</PivotItem>
</Pivot>
</Grid>
+59 -3
View File
@@ -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;
}
}
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
@@ -116,6 +131,10 @@ namespace FoxTube.Pages
if (ids[1] != null)
{
playlistId = ids[1];
List<VideoPlaylistItem> items = new List<VideoPlaylistItem>();
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);
}
}
}