Channel card
This commit is contained in:
@@ -6,15 +6,5 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FoxTube
|
||||
{
|
||||
public delegate void ObjectEventHandler(object sender, ObjectEventArgs args);
|
||||
|
||||
public class ObjectEventArgs
|
||||
{
|
||||
public List<object> Parameters = new List<object>();
|
||||
public ObjectEventArgs(params object[] args)
|
||||
{
|
||||
foreach (object a in args)
|
||||
Parameters.Add(a);
|
||||
}
|
||||
}
|
||||
public delegate void ObjectEventHandler(object sender, params object[] args);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Google.Apis.Auth.OAuth2;
|
||||
using Google.Apis.Auth.OAuth2.Flows;
|
||||
using Google.Apis.Services;
|
||||
@@ -15,6 +15,9 @@ namespace FoxTube
|
||||
public class SecretsVault
|
||||
{
|
||||
#region Static Information
|
||||
public static event EventHandler AuthorizationStateChanged;
|
||||
public static event ObjectEventHandler SubscriptionsChanged;
|
||||
|
||||
public static NetworkCredential EmailCredential => new NetworkCredential("youwillneverknowthisadress@gmail.com", "thisisthepassword12345");
|
||||
public static ClientSecrets Secrets => new ClientSecrets()
|
||||
{
|
||||
@@ -52,6 +55,46 @@ namespace FoxTube
|
||||
return NoAuthService;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> Subscribe(string id)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
return false;
|
||||
|
||||
var request = Service.Subscriptions.Insert(new Subscription()
|
||||
{
|
||||
Snippet = new SubscriptionSnippet()
|
||||
{
|
||||
ChannelId = id
|
||||
}
|
||||
}, "snippet");
|
||||
|
||||
Subscription s = await request.ExecuteAsync();
|
||||
Subscriptions.Add(s);
|
||||
SubscriptionsChanged.Invoke(null, "add", s);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<bool> Unsubscibe(string id)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
return false;
|
||||
|
||||
Subscription s = null;
|
||||
foreach(Subscription i in Subscriptions)
|
||||
if (i.Snippet.ChannelId == id)
|
||||
{
|
||||
s = i;
|
||||
break;
|
||||
}
|
||||
if (s == null)
|
||||
return false;
|
||||
SubscriptionsChanged.Invoke(null, "remove", Subscriptions.IndexOf(s));
|
||||
await Service.Subscriptions.Delete(s.Id).ExecuteAsync(); //???
|
||||
|
||||
Subscriptions.Remove(s);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Object containers
|
||||
@@ -62,7 +105,6 @@ namespace FoxTube
|
||||
public List<PlaylistItem> later = new List<PlaylistItem>();
|
||||
public Google.Apis.YouTube.v3.Data.Channel channel;
|
||||
public UserCredential Credential;
|
||||
public event EventHandler AuthorizationStateChanged;
|
||||
private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||
|
||||
public async void Authorize()
|
||||
|
||||
@@ -17,28 +17,39 @@
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Image Name="thumbnail" Source="/Assets/ChannelCoverTemplate.png" Stretch="Fill"/>
|
||||
<StackPanel Name="liveTag" Margin="5" Background="Red" BorderBrush="White" BorderThickness="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Padding="5,2,5,3" Orientation="Horizontal" Visibility="Visible">
|
||||
<Image Name="cover" Source="/Assets/ChannelCoverTemplate.png" Stretch="Fill"/>
|
||||
<StackPanel Name="liveTag" Margin="5" Background="Red" BorderBrush="White" BorderThickness="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Padding="5,2,5,3" Orientation="Horizontal" Visibility="Collapsed">
|
||||
<TextBlock Text=" " VerticalAlignment="Center" Foreground="White" FontSize="12" FontFamily="Segoe MDL2 Assets" FontWeight="Black"/>
|
||||
<TextBlock Name="liveContent" Text="LIVE" VerticalAlignment="Center" Foreground="White" FontSize="12" FontWeight="Bold"/>
|
||||
<TextBlock Text="LIVE" VerticalAlignment="Center" Foreground="White" FontSize="12" FontWeight="Bold"/>
|
||||
</StackPanel>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Ellipse Grid.Column="0" Height="80" Width="80" Margin="0,-45,0,0" VerticalAlignment="Bottom" Fill="WhiteSmoke"/>
|
||||
<Ellipse Height="80" Width="80" Margin="0,-45,0,0" VerticalAlignment="Bottom" Fill="WhiteSmoke"/>
|
||||
<PersonPicture Name="avatar" Grid.Column="0" Height="74" Margin="3,-45,3,3" VerticalAlignment="Bottom" BorderBrush="White" BorderThickness="10"/>
|
||||
|
||||
<TextBlock Name="channelName" Grid.Column="1" Text="Markiplier"/>
|
||||
<TextBlock Grid.Column="1" Name="views" Text="[Views]" HorizontalAlignment="Right" Foreground="Gray" Margin="0,2,2,0" FontSize="12"/>
|
||||
<TextBlock Name="title" Grid.Column="1" Text="[Channel name]" Margin="5" TextWrapping="WrapWholeWords" MaxLines="2"/>
|
||||
<StackPanel Grid.Column="2" Margin="5">
|
||||
<TextBlock Name="subs" Text="[Subscribers counter]" Foreground="Gray"/>
|
||||
<TextBlock Name="uploads" Text="[Uploads counter]" Foreground="Gray"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1" Name="title" Text="[Title]" TextWrapping="WrapWholeWords" Margin="5" MaxLines="2" Foreground="Gray"/>
|
||||
<TextBlock Grid.Row="1" Name="description" Text="[Descrription]" TextWrapping="WrapWholeWords" Margin="5" MaxLines="5" Foreground="Gray"/>
|
||||
<Grid Visibility="Collapsed" Grid.Row="1" VerticalAlignment="Bottom" Margin="10" Name="subscriptionPane">
|
||||
<ToggleButton Click="subscribe_Click" Name="subscribe" HorizontalAlignment="Stretch" Height="50" Background="Red" Foreground="White" FontSize="18" FontWeight="SemiBold" Content="Subscirbe" Margin="0,0,50,0"/>
|
||||
<ToggleButton Name="notify" Height="50" Width="50" FontFamily="Segoe MDL2 Assets" FontSize="18" FontWeight="SemiBold" Content="" Foreground="White" Background="Red" HorizontalAlignment="Right"/>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1" 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>
|
||||
</Grid>
|
||||
</Button>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Google.Apis.YouTube.v3;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -11,6 +13,7 @@ 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;
|
||||
|
||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||
@@ -19,9 +22,76 @@ namespace FoxTube.Controls
|
||||
{
|
||||
public sealed partial class ChannelCard : UserControl
|
||||
{
|
||||
public ChannelCard()
|
||||
string channelId;
|
||||
Google.Apis.YouTube.v3.Data.Channel item;
|
||||
|
||||
public ChannelCard(string id, string live = "null")
|
||||
{
|
||||
this.InitializeComponent();
|
||||
Initialize(id, live);
|
||||
}
|
||||
|
||||
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
Height = e.NewSize.Width * 0.75;
|
||||
}
|
||||
|
||||
public async void Initialize(string id, string live)
|
||||
{
|
||||
ChannelsResource.ListRequest request = SecretsVault.NoAuthService.Channels.List("snippet,contentDetails,statistics,liveStreamingDetails");
|
||||
request.Id = id;
|
||||
ChannelListResponse response = await request.ExecuteAsync();
|
||||
|
||||
item = response.Items[0];
|
||||
channelId = id;
|
||||
|
||||
title.Text = item.Snippet.Title;
|
||||
description.Text = item.Snippet.Description;
|
||||
|
||||
subs.Text = $"{item.Statistics.SubscriberCount} subscribers";
|
||||
uploads.Text = $"{item.Statistics.VideoCount} videos";
|
||||
|
||||
if (live == "live")
|
||||
liveTag.Visibility = Visibility.Visible;
|
||||
|
||||
if(SecretsVault.IsAuthorized)
|
||||
{
|
||||
foreach(Subscription s in SecretsVault.Subscriptions)
|
||||
{
|
||||
if(s.Snippet.ChannelId == id)
|
||||
subscribe.IsChecked = true;
|
||||
}
|
||||
subscriptionPane.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
avatar.ProfilePicture = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
|
||||
cover.Source = new BitmapImage(new Uri(item.BrandingSettings.Image.BannerImageUrl));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Methods.MainPage.GoToChannel(channelId);
|
||||
}
|
||||
|
||||
private void Hyperlink_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
|
||||
{
|
||||
SecretsVault.Vault.Authorize();
|
||||
}
|
||||
|
||||
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (subscribe.IsChecked.Value)
|
||||
{
|
||||
if (!await SecretsVault.Subscribe(channelId))
|
||||
subscribe.IsChecked = false;
|
||||
}
|
||||
else
|
||||
if (!await SecretsVault.Unsubscibe(channelId))
|
||||
subscribe.IsChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user