Archived
1
0

Channel rebuild

This commit is contained in:
Michael Gordeev
2018-08-02 02:39:27 +03:00
parent e6547b06be
commit ee96d7b75e
10 changed files with 531 additions and 435 deletions
-145
View File
@@ -1,145 +0,0 @@
<Page
x:Class="FoxTube.Channel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="47"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="Red" Name="navigationPane" Visibility="Visible">
<StackPanel Orientation="Horizontal" Margin="10,0,10,0">
<HyperlinkButton Name="toVideos" Click="toVideos_Click" Foreground="White" Margin="0,0,10,0">
<TextBlock Text="Videos"/>
</HyperlinkButton>
<HyperlinkButton Foreground="White" Margin="0,0,10,0" Name="toPlaylists" Click="toPlaylists_Click">
<TextBlock Text="Playlists"/>
</HyperlinkButton>
<HyperlinkButton Foreground="White" Margin="0,0,10,0" Name="toAbout" Click="toAbout_Click">
<TextBlock Text="About channel"/>
</HyperlinkButton>
<TextBox Name="searchField" ToolTipService.ToolTip="Search on channel" Margin="4" Width="350" Height="47" Padding="10,10,5,0" PlaceholderText="Search on channel" BorderThickness="0" Background="#7FFFFFFF"/>
<Button Name="searchButton" HorizontalAlignment="Right" Click="searchButton_Click"
Width="39" Height="39" Margin="0" Padding="1"
RelativePanel.AlignRightWithPanel="True"
Background="Transparent"
FontFamily="Segoe MDL2 Assets" Content="&#xE11A;" FontSize="20" FocusVisualSecondaryBrush="#66FFFFFF" FocusVisualPrimaryBrush="White" Foreground="White"/>
</StackPanel>
</Grid>
<ScrollViewer Grid.Row="1" Margin="0,0,0,50">
<Pivot SelectedIndex="0" Name="content" IsHeaderItemsCarouselEnabled="False" SelectionChanged="content_SelectionChanged">
<PivotItem Margin="0,-48,0,0">
<StackPanel Name="videos">
<Image Name="channelCover" Stretch="Uniform" Source="/Assets/ChannelCoverTemplate.png"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions>
<PersonPicture Name="avatar" Grid.Column="0" HorizontalAlignment="Left" Margin="10,-40,0,0" ProfilePicture="Assets/LogoAvatar.png"/>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,0,0,0">
<TextBlock Name="title" FontWeight="SemiBold" FontSize="22" Text="Channel name"/>
<TextBlock Name="subscribers" Foreground="Gray" Text="1,000,000 subscribers"/>
<TextBlock Name="videosCount" Foreground="Gray" Text="563,000 videos"/>
</StackPanel>
<ToggleButton Grid.Column="2" Height="50" Width="250" Background="Red" Foreground="White" FontSize="18" FontWeight="SemiBold" Content="Subscirbe"/>
<ToggleButton Grid.Column="3" Height="50" Width="50" FontFamily="Segoe MDL2 Assets" FontSize="18" FontWeight="SemiBold" Content="" Foreground="White" Background="Red"/>
<!--&#xE781;&#xE93E;&#xEDAC;-->
</Grid>
</StackPanel>
</PivotItem>
<PivotItem Margin="0,-48,0,0" >
<Grid Padding="10">
<ProgressRing Name="playlistRing" Width="100" Height="100" Foreground="Red" IsActive="True"/>
<StackPanel Visibility="Visible" Name="playlistPane">
<TextBlock FontSize="28" Text="Playlists"/>
<StackPanel Name="playlists">
</StackPanel>
<HyperlinkButton Name="showMorePlaylists" Click="showMorePlaylists_Click" Content="Show more" HorizontalAlignment="Center" FontSize="20" Foreground="Red"/>
<ProgressBar Name="showMorePlaylistsProgressBar" IsIndeterminate="True" Foreground="Red" Visibility="Collapsed"/>
</StackPanel>
</Grid>
</PivotItem>
<PivotItem Margin="0,-48,0,0">
<StackPanel Visibility="Visible" Margin="10">
<TextBlock FontSize="28" Text="About this channel"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Margin="10">
<TextBlock FontSize="24" Text="Description"/>
<Line Stroke="Black" Y1="0" Y2="0" StrokeThickness="2" X2="2000"/>
<TextBlock Name="description" Margin="0,10,0,0" TextWrapping="WrapWholeWords" IsTextSelectionEnabled="True"/>
<!--<TextBlock FontSize="24" Text="Links" Margin="0,10,0,0"/>
<Line Stroke="Black" Y1="0" Y2="0" StrokeThickness="2" X2="2000"/>
<StackPanel Name="links">
</StackPanel>-->
</StackPanel>
<StackPanel Grid.Column="1" Margin="10">
<TextBlock FontSize="24" Text="Statistics"/>
<Line Stroke="Black" Y1="0" Y2="0" StrokeThickness="2" X2="2000"/>
<StackPanel Margin="5">
<Grid>
<TextBlock Text="Registration date:"/>
<TextBlock Name="registration" Text="13-May-18" HorizontalAlignment="Right"/>
</Grid>
<Line Stroke="Black" Y1="0" Y2="0" StrokeThickness="2" X2="2000"/>
</StackPanel>
<StackPanel Margin="5">
<Grid>
<TextBlock Text="Views"/>
<TextBlock Name="views" Text="1885510485" HorizontalAlignment="Right"/>
</Grid>
<Line Stroke="Black" Y1="0" Y2="0" StrokeThickness="2" X2="2000"/>
</StackPanel>
<Button Content="Send a message" Margin="5" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</StackPanel>
</PivotItem>
<PivotItem Margin="0,-48,0,0">
<Grid Padding="10">
<ProgressRing Name="searchRing" HorizontalAlignment="Center" VerticalAlignment="Center" IsActive="True" Foreground="Red" Width="100" Height="100"/>
<StackPanel Orientation="Vertical" Margin="10" Visibility="Visible" Name="displaying">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Search results for: " FontSize="28"/>
<TextBlock Name="searchTerm" Text="[searchTerm]" FontSize="28" Margin="10,0,0,0"/>
<TextBlock Text="from" FontSize="28" Margin="10,0,0,0"/>
<TextBlock Name="searchChannel" Text="[channelName]" FontSize="28" Margin="10,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Found:" FontSize="14" Foreground="Gray" Margin="0,-5,0,10"/>
<TextBlock Name="resultsCount" Text="[resultsCount]" FontSize="14" Foreground="Gray" Margin="5,-5,0,10"/>
<TextBlock Text="items" FontSize="14" Foreground="Gray" Margin="5,-5,0,10"/>
</StackPanel>
<HyperlinkButton Content="Show filters &#xE71C;" FontFamily="Default, Segoe MDL2 Assets" FontSize="18" Visibility="Collapsed"/>
<StackPanel Name="resultsList" Orientation="Vertical">
</StackPanel>
</StackPanel>
</Grid>
</PivotItem>
</Pivot>
</ScrollViewer>
<CommandBar Grid.Row="1" VerticalAlignment="Bottom" Name="commandBar">
<AppBarButton Icon="Globe" Label="Open in browser" Name="inBrowser"/>
<AppBarButton Icon="Favorite" Label="Add to bookmarks" Visibility="Collapsed"/>
<AppBarButton Icon="Refresh" Label="Refresh"/>
<AppBarButton Icon="Share" Label="Share"/>
<AppBarButton Icon="Flag" Label="Report this channel" Visibility="Collapsed"/>
</CommandBar>
</Grid>
</Page>
-182
View File
@@ -1,182 +0,0 @@
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;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Text;
using Windows.Storage;
using FoxTube.Controls;
using FoxTube.Pages;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
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();
public Channel()
{
this.InitializeComponent();
}
private void toAbout_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 2;
}
public async void Initialize(string id)
{
channelId = id;
YouTubeService ytService = SecretsVault.NoAuthService;
ChannelsResource.ListRequest request = ytService.Channels.List("snippet,contentDetails,statistics,brandingSettings");
request.Id = id;
ChannelListResponse response = await request.ExecuteAsync();
item = response.Items[0];
title.Text = item.Snippet.Title;
subscribers.Text = item.Statistics.SubscriberCount + " subscribers";
videosCount.Text = item.Statistics.VideoCount + " videos";
channelCover.Source = new BitmapImage(new Uri(item.BrandingSettings.Image.BannerImageUrl));
avatar.ProfilePicture = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
description.Text = item.Snippet.Description;
views.Text = item.Statistics.ViewCount.ToString();
registration.Text = item.Snippet.PublishedAt.ToString();
searchChannel.Text = item.Snippet.Title;
SearchResource.ListRequest request2 = ytService.Search.List("snippet");
request2.ChannelId = id;
request2.Type = "video";
request2.Order = SearchResource.ListRequest.OrderEnum.Date;
request2.MaxResults = 48;
SearchListResponse response2 = await request2.ExecuteAsync();
videos.Children.Add(videoGrid);
foreach(SearchResult vid in response2.Items)
{
VideoCard vCard = new VideoCard(vid.Id.VideoId);
videoGrid.Add(vCard);
}
}
private void toVideos_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 0;
}
private void toPlaylists_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 1;
}
private async void searchButton_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 3;
YouTubeService ytService = SecretsVault.NoAuthService;
var searchListRequest = ytService.Search.List("snippet");
searchListRequest.Q = searchField.Text;
searchListRequest.ChannelId = channelId;
searchListRequest.MaxResults = 25;
searchListRequest.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"];
var response = await searchListRequest.ExecuteAsync();
SetResults(searchField.Text, (int)response.PageInfo.TotalResults);
foreach (SearchResult result in response.Items)
AddItem(result);
searchRing.IsActive = false;
displaying.Visibility = Visibility.Visible;
}
public void SetResults(string keyword, int count)
{
searchTerm.Text = keyword;
resultsCount.Text = count.ToString();
}
public void AddItem(SearchResult result)
{
switch (result.Id.Kind)
{
case "youtube#video":
VideoCardWide vCard = new VideoCardWide(result.Id.VideoId);
resultsList.Children.Add(vCard);
break;
case "youtube#playlist":
PlaylistCardWide pCard = new PlaylistCardWide(result.Id.PlaylistId);
resultsList.Children.Add(pCard);
break;
}
}
private async void content_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
toVideos.FontWeight = FontWeights.Normal;
toPlaylists.FontWeight = FontWeights.Normal;
toAbout.FontWeight = FontWeights.Normal;
if (content.SelectedIndex == 0)
toVideos.FontWeight = FontWeights.Bold;
else if (content.SelectedIndex == 1)
{
toPlaylists.FontWeight = FontWeights.Bold;
if (playlists.Children.Count == 0)
{
YouTubeService ytService = SecretsVault.NoAuthService;
PlaylistsResource.ListRequest request = ytService.Playlists.List("snippet,contentDetails");
request.MaxResults = 25;
request.ChannelId = channelId;
PlaylistListResponse response = await request.ExecuteAsync();
foreach (Playlist playlist in response.Items)
{
PlaylistCardWide playlistCard = new PlaylistCardWide(playlist.Id, true);
playlists.Children.Add(playlistCard);
}
playlistRing.IsActive = false;
playlistPane.Visibility = Visibility.Visible;
}
}
else if (content.SelectedIndex == 2)
toAbout.FontWeight = FontWeights.Bold;
}
private void showMorePlaylists_Click(object sender, RoutedEventArgs e)
{
}
}
}
+132
View File
@@ -0,0 +1,132 @@
<Page
x:Class="FoxTube.Pages.ChannelPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="using:FoxTube.Pages"
xmlns:controls="using:FoxTube.Controls"
mc:Ignorable="d">
<Grid Name="grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Pivot Grid.Row="1" Margin="0,-48,0,0" SelectedIndex="0" Name="content" IsHeaderItemsCarouselEnabled="False" SelectionChanged="content_SelectionChanged">
<Pivot.ItemContainerStyle>
<Style TargetType="PivotItem">
<Setter Property="Margin" Value="0"/>
</Style>
</Pivot.ItemContainerStyle>
<PivotItem>
<ScrollViewer>
<StackPanel Name="videos">
<Image Name="channelCover" Stretch="Uniform" Source="/Assets/ChannelCoverTemplate.png"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<PersonPicture Name="avatar" Grid.Column="0" HorizontalAlignment="Left" Margin="10,-40,0,0" ProfilePicture="/Assets/LogoAvatar.png"/>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,0,0,0">
<TextBlock Name="title" FontWeight="SemiBold" FontSize="22" Text="Channel name"/>
<TextBlock Name="subscribers" Foreground="Gray" Text="1,000,000 subscribers"/>
<TextBlock Name="videosCount" Foreground="Gray" Text="563,000 videos"/>
</StackPanel>
<TextBlock Grid.Column="2" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="50" Margin="10" TextAlignment="Center" Padding="0,16,0,0" Foreground="Gray">
<Hyperlink Click="Hyperlink_Click">Log in</Hyperlink> to manage your subscriptions
</TextBlock>
<Grid Visibility="Visible" Grid.Column="2" VerticalAlignment="Bottom" Margin="10" Name="subscriptionPane" Background="Red">
<ToggleButton Click="subscribe_Click" Name="subscribe" Width="250" Height="50" Background="Red" Foreground="White" FontSize="18" FontWeight="SemiBold" Content="Subscirbe"/>
</Grid>
</Grid>
<pages:VideoGrid/>
<controls:ShowMore Clicked="videoMore_Clicked"/>
</StackPanel>
</ScrollViewer>
</PivotItem>
<PivotItem>
<ScrollViewer>
<Grid Name="playlists">
<StackPanel Margin="10" Visibility="Visible">
<TextBlock FontSize="28" Text="Playlists"/>
<pages:VideoGrid/>
<controls:ShowMore Clicked="showMorePlaylists_Click"/>
</StackPanel>
<local:LoadingPage Visibility="Collapsed"/>
</Grid>
</ScrollViewer>
</PivotItem>
<PivotItem>
<StackPanel Margin="10">
<TextBlock FontSize="28" Text="About this channel"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock FontSize="24" Text="Description"/>
<TextBlock Name="description" Margin="0,10,0,0" TextWrapping="WrapWholeWords" IsTextSelectionEnabled="True"/>
</StackPanel>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Statistics"/>
<TextBlock Text="Registration date:" Grid.Row="1"/>
<TextBlock Grid.Row="1" Grid.Column="2" Name="registration" Text="13-May-18" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="2" Text="Views"/>
<TextBlock Grid.Row="2" Grid.Column="2" Name="views" Text="1885510485" HorizontalAlignment="Right"/>
</Grid>
</Grid>
</StackPanel>
</PivotItem>
</Pivot>
<Grid Background="Red" Name="navigationPane">
<StackPanel Orientation="Horizontal" Margin="10,0,10,0">
<HyperlinkButton Name="toVideos" Click="toVideos_Click" Foreground="White" Margin="0,0,10,0">
<TextBlock Text="Videos"/>
</HyperlinkButton>
<HyperlinkButton Foreground="White" Margin="0,0,10,0" Name="toPlaylists" Click="toPlaylists_Click">
<TextBlock Text="Playlists"/>
</HyperlinkButton>
<HyperlinkButton Foreground="White" Margin="0,0,10,0" Name="toAbout" Click="toAbout_Click">
<TextBlock Text="About channel"/>
</HyperlinkButton>
<TextBox Name="searchField" ToolTipService.ToolTip="Search on channel" Margin="4" Width="350" Height="47" Padding="10,10,5,0" PlaceholderText="Search on channel" BorderThickness="0" Background="#7FFFFFFF"/>
<Button Name="searchButton" HorizontalAlignment="Right" Click="searchButton_Click"
Width="39" Height="39" Margin="0" Padding="1"
RelativePanel.AlignRightWithPanel="True"
Background="Transparent"
FontFamily="Segoe MDL2 Assets" Content="&#xE11A;" FontSize="20" FocusVisualSecondaryBrush="#66FFFFFF" FocusVisualPrimaryBrush="White" Foreground="White"/>
</StackPanel>
</Grid>
<CommandBar Grid.Row="2" VerticalAlignment="Bottom" Name="commandBar">
<AppBarButton Icon="Globe" Label="Open in browser" Name="inBrowser" Click="inBrowser_Click"/>
<AppBarButton Icon="Refresh" Label="Refresh" Name="refresh" Click="refresh_Click"/>
<AppBarButton Icon="Share" Label="Share" Name="share" Click="share_Click"/>
</CommandBar>
<local:LoadingPage Grid.RowSpan="3" Visibility="Collapsed"/>
</Grid>
</Page>
+359
View File
@@ -0,0 +1,359 @@
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;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Text;
using Windows.Storage;
using FoxTube.Controls;
using FoxTube.Pages;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel;
using Windows.Storage.Streams;
using Windows.System;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube.Pages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ChannelPage : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
public string channelId;
public Channel item;
LoadingPage loading, playlistLoading;
VideoGrid videoList, playlistList;
ShowMore videoMore, playlistMore;
SearchResource.ListRequest videoRequest, playlistRequest;
private string videoToken;
private string playlistToken;
private bool playlistLoaded = false;
public ChannelPage()
{
this.InitializeComponent();
loading = grid.Children[3] as LoadingPage;
playlistLoading = playlists.Children[1] as LoadingPage;
videoList = videos.Children[2] as VideoGrid;
playlistList = (playlists.Children[0] as StackPanel).Children[1] as VideoGrid;
videoMore = videos.Children[3] as ShowMore;
playlistMore = (playlists.Children[0] as StackPanel).Children[2] as ShowMore;
loading.RefreshPage += refresh_Click;
DataTransferManager.GetForCurrentView().DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(Share);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter == null)
loading.Error("NullReferenceException", "Unable to initialize search. Search term is not stated.");
else
Initialize(e.Parameter as string);
}
public async void Initialize(string id)
{
content.SelectedIndex = 0;
loading.Refresh();
playlistLoading.Refresh();
try
{
channelId = id;
ChannelsResource.ListRequest request = SecretsVault.Service.Channels.List("snippet,statistics,brandingSettings");
request.Id = id;
if (content.Items.Count == 4)
content.Items.RemoveAt(3);
item = (await request.ExecuteAsync()).Items[0];
title.Text = item.Snippet.Title;
subscribers.Text = $"{item.Statistics.SubscriberCount:0,0} subscribers";
videosCount.Text = $"{item.Statistics.VideoCount:0,0} videos";
try
{
channelCover.Source = new BitmapImage(new Uri(item.BrandingSettings.Image.BannerImageUrl));
avatar.ProfilePicture = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
}
catch { }
description.Text = item.Snippet.Description;
views.Text = $"{item.Statistics.ViewCount:0,0}";
registration.Text = item.Snippet.PublishedAt.ToString();
videoRequest = SecretsVault.Service.Search.List("id");
videoRequest.ChannelId = id;
videoRequest.Type = "video";
videoRequest.Order = SearchResource.ListRequest.OrderEnum.Date;
videoRequest.MaxResults = 48;
SearchListResponse response = await videoRequest.ExecuteAsync();
videoList.Clear();
foreach (SearchResult i in response.Items)
{
VideoCard card = new VideoCard(i.Id.VideoId);
videoList.Add(card);
}
if (!string.IsNullOrWhiteSpace(response.NextPageToken))
videoToken = response.NextPageToken;
else
videoMore.Complete(true);
if (SecretsVault.IsAuthorized)
{
foreach (Subscription s in SecretsVault.Subscriptions)
{
if (s.Snippet.ResourceId.ChannelId == id)
{
subscribe.IsChecked = true;
subscribe.Content = "Subscribed";
}
}
subscriptionPane.Visibility = Visibility.Visible;
}
loading.Close();
}
catch
{
loading.Error();
}
}
async void LoadPlaylist()
{
try
{
playlistLoading.Refresh();
playlistRequest = SecretsVault.Service.Search.List("id");
playlistRequest.ChannelId = channelId;
playlistRequest.Type = "playlist";
playlistRequest.Order = SearchResource.ListRequest.OrderEnum.Date;
playlistRequest.MaxResults = 48;
SearchListResponse response = await playlistRequest.ExecuteAsync();
playlistList.Clear();
foreach (SearchResult i in response.Items)
{
PlaylistCard card = new PlaylistCard(i.Id.PlaylistId);
playlistList.Add(card);
}
if (!string.IsNullOrWhiteSpace(response.NextPageToken))
playlistToken = response.NextPageToken;
else
playlistMore.Complete(true);
playlistLoading.Close();
}
catch
{
playlistLoading.Error();
}
}
private void searchButton_Click(object sender, RoutedEventArgs e)
{
if (content.Items.Count == 4)
(((content.Items[3] as PivotItem).Content as Frame).Content as Search).Initialize(new SearchParameters(item.Id, searchField.Text));
else
{
content.Items.Add(new PivotItem()
{
Content = new Frame()
});
((content.Items[3] as PivotItem).Content as Frame).Navigate(typeof(Search), new SearchParameters(item.Id, searchField.Text));
}
content.SelectedIndex = 3;
}
private void content_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
toVideos.FontWeight = FontWeights.Normal;
toPlaylists.FontWeight = FontWeights.Normal;
toAbout.FontWeight = FontWeights.Normal;
switch (content.SelectedIndex)
{
case 0:
toVideos.FontWeight = FontWeights.Bold;
break;
case 1:
toPlaylists.FontWeight = FontWeights.Bold;
if (!playlistLoaded)
LoadPlaylist();
break;
case 2:
toAbout.FontWeight = FontWeights.Bold;
break;
}
}
private void toVideos_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 0;
}
private void toPlaylists_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 1;
}
private void toAbout_Click(object sender, RoutedEventArgs e)
{
content.SelectedIndex = 2;
}
private async void showMorePlaylists_Click()
{
playlistRequest.PageToken = playlistToken;
SearchListResponse response = await playlistRequest.ExecuteAsync();
foreach (SearchResult i in response.Items)
{
PlaylistCard card = new PlaylistCard(i.Id.PlaylistId);
playlistList.Add(card);
}
if (!string.IsNullOrWhiteSpace(response.NextPageToken))
{
playlistToken = response.NextPageToken;
playlistMore.Complete();
}
else
playlistMore.Complete(true);
}
private async void videoMore_Clicked()
{
videoRequest.PageToken = videoToken;
SearchListResponse response = await videoRequest.ExecuteAsync();
foreach (SearchResult i in response.Items)
{
VideoCard card = new VideoCard(i.Id.VideoId);
videoList.Add(card);
}
if (!string.IsNullOrWhiteSpace(response.NextPageToken))
{
videoToken = response.NextPageToken;
videoMore.Complete();
}
else
videoMore.Complete(true);
}
private async void subscribe_Click(object sender, RoutedEventArgs e)
{
if (subscribe.IsChecked.Value)
{
if (!await SecretsVault.Subscribe(channelId))
subscribe.IsChecked = false;
else
subscribe.Content = "Subscribed";
}
else
{
if (!await SecretsVault.Unsubscibe(channelId))
subscribe.IsChecked = true;
else
subscribe.Content = "Subscribe";
}
}
private void Hyperlink_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
{
SecretsVault.Authorize();
}
private void refresh_Click(object sender, RoutedEventArgs e)
{
Initialize(channelId);
}
private async void inBrowser_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(item.Snippet.CustomUrl))
await Launcher.LaunchUriAsync(new Uri($"https://www.youtube.com/user/{item.Snippet.CustomUrl}"));
else
await Launcher.LaunchUriAsync(new Uri($"https://www.youtube.com/channel/{item.Id}"));
}
private void share_Click(object sender, RoutedEventArgs e)
{
DataTransferManager.ShowShareUI();
}
private async void Share(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
request.Data.Properties.Title = item.Snippet.Title;
request.Data.Properties.Description = "Sharing a channel";
// Handle errors
//request.FailWithDisplayText("Something unexpected could happen.");
// Plain text
request.Data.SetText(item.Snippet.Title + "\n" + "#YouTube #FoxTube #SharedWithFoxTube");
// Uniform Resource Identifiers (URIs)
if(!string.IsNullOrWhiteSpace(item.Snippet.CustomUrl))
request.Data.SetWebLink(new Uri($"https://www.youtube.com/user/{item.Snippet.CustomUrl}"));
else
request.Data.SetWebLink(new Uri($"https://www.youtube.com/channel/{item.Id}"));
// HTML
//request.Data.SetHtmlFormat("<b>Bold Text</b>");
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
StorageFile thumbnailFile = await Package.Current.InstalledLocation.GetFileAsync(item.Snippet.Thumbnails.Medium.Url);
request.Data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromFile(thumbnailFile);
StorageFile imageFile = await Package.Current.InstalledLocation.GetFileAsync(item.Snippet.Thumbnails.Medium.Url);
// Bitmaps
request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile));
}
finally
{
deferral.Complete();
}
}
}
}
-52
View File
@@ -185,58 +185,6 @@
</StackPanel>
</ListBoxItem>
</ListBox>
<ListBox Name="categoriesList" SelectionChanged="FeaturedSelected">
<ListBoxItem IsEnabled="False" Height="17" Padding="0,0,5,0">
<StackPanel Orientation="Horizontal">
<TextBlock Name="catTitle" Text="Featured" FontSize="12" Padding="5,0,5,0"/>
<Line X2="300" Stroke="Gray" VerticalAlignment="Center"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xE189;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="Music"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xE805;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="Sports"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xE7FC;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="Gaming"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xE7BC;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="News"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xE93E;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="Live"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xECAD;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="Spotlight"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource ItemIcon}" Text="&#xF131;"/>
<TextBlock Style="{StaticResource MenuItem}" Text="360° Video"/>
</StackPanel>
</ListBoxItem>
</ListBox>
</StackPanel>
</ScrollViewer>
<ListBox Grid.Row="1" VerticalAlignment="Bottom" Name="serviceList" SelectionChanged="ServiceListSelected">
+2 -46
View File
@@ -225,7 +225,6 @@ namespace FoxTube
return;
subscriptionsList.SelectedItem = null;
categoriesList.SelectedItem = null;
serviceList.SelectedItem = null;
object s = mainList.SelectedItem;
@@ -255,7 +254,6 @@ namespace FoxTube
mainList.SelectedItem = null;
subscriptionsList.SelectedItem = null;
categoriesList.SelectedItem = null;
object s = serviceList.SelectedItem;
@@ -277,49 +275,9 @@ namespace FoxTube
return;
mainList.SelectedItem = null;
categoriesList.SelectedItem = null;
serviceList.SelectedItem = null;
content.Navigate(typeof(Channel), SecretsVault.Subscriptions[subscriptionsList.SelectedIndex - 1].Snippet.ChannelId);
}
catch { }
}
void FeaturedSelected(object sender, SelectionChangedEventArgs e)
{
try
{
if (serviceList.SelectedItem == null)
return;
mainList.SelectedItem = null;
subscriptionsList.SelectedItem = null;
serviceList.SelectedItem = null;
switch (categoriesList.SelectedIndex)
{
case 0:
GoToChannel("UC-9-kyTW8ZkZNDHQJ6FgpwQ");
break;
case 1:
GoToChannel("UCEgdi0XIXXZ-qJOFPf4JSKw");
break;
case 2:
GoToChannel("UCOpNcN46UbXVtpKMrmU4Abg");
break;
case 3:
GoToChannel("UCYfdidRxbB8Qhf0Nx7ioOYw");
break;
case 4:
GoToChannel("UC4R8DWoMoI7CAwX8_LjQHig");
break;
case 5:
GoToChannel("UC8iNz9uwDGfomRnnKKbOhOQ");
break;
case 6:
GoToChannel("UCzuqhhs6NWbgTzMuM09WKDQ");
break;
}
GoToChannel(SecretsVault.Subscriptions[subscriptionsList.SelectedIndex - 1].Snippet.ResourceId.ChannelId);
}
catch { }
}
@@ -343,7 +301,6 @@ namespace FoxTube
private void menu_PaneClosed(SplitView sender, object args)
{
subsTitle.Visibility = Visibility.Collapsed;
catTitle.Visibility = Visibility.Collapsed;
}
private void menu_PaneOpened(SplitView sender, object args)
@@ -351,7 +308,6 @@ namespace FoxTube
try
{
subsTitle.Visibility = Visibility.Visible;
catTitle.Visibility = Visibility.Visible;
}
catch { }
}
@@ -468,7 +424,7 @@ namespace FoxTube
public void GoToChannel(string id)
{
MinimizeVideo();
content.Navigate(typeof(Channel), id);
content.Navigate(typeof(ChannelPage), id);
}
public void GoToVideo(string id)
+3 -5
View File
@@ -53,15 +53,13 @@ namespace FoxTube.Pages
loading.Error("NullReferenceException", "Unable to initialize search. Search term is not stated.");
else
Initialize(e.Parameter as string);
}
public async void Initialize(string id)
{
loading.Refresh();
//try
try
{
playlistId = id;
PlaylistsResource.ListRequest request = SecretsVault.Service.Playlists.List("snippet,contentDetails");
@@ -80,7 +78,7 @@ namespace FoxTube.Pages
thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
ChannelsResource.ListRequest channelRequest = SecretsVault.Service.Channels.List("snippet");
channelRequest.Id = item.Snippet.ChannelId;
Google.Apis.YouTube.v3.Data.Channel channel = (await channelRequest.ExecuteAsync()).Items[0];
Channel channel = (await channelRequest.ExecuteAsync()).Items[0];
avatar.ProfilePicture = new BitmapImage(new Uri(channel.Snippet.Thumbnails.Medium.Url));
}
catch { }
@@ -106,7 +104,7 @@ namespace FoxTube.Pages
loading.Close();
}
//catch
catch
{
loading.Error();
}
+20 -2
View File
@@ -82,10 +82,23 @@ namespace FoxTube
if (e.Parameter == null)
loading.Error("NullReferenceException", "Unable to initialize search. Search term is not stated.");
else
Initialize(e.Parameter as string);
{
if (e.Parameter is string)
Initialize(e.Parameter as string);
else if (e.Parameter is SearchParameters)
Initialize(e.Parameter as SearchParameters);
else
loading.Error("ArgumentException", "Wrong search parameters");
}
}
public async void Initialize(string term, bool forceInitialization = false)
public void Initialize(SearchParameters arg)
{
Initialize(arg.Term, channelId: arg.ChannelId);
}
public async void Initialize(string term, bool forceInitialization = false, string channelId = null)
{
if (term == Term && !forceInitialization)
return;
@@ -95,6 +108,11 @@ namespace FoxTube
{
Term = term;
request = SecretsVault.Service.Search.List("id");
if (!string.IsNullOrWhiteSpace(channelId))
{
request.ChannelId = channelId;
(grid.Children[1] as CommandBar).Visibility = Visibility.Collapsed;
}
request.Q = term;
request.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"];
try