Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube/Controls/ChannelCard.xaml.cs
T
Michael Gordeev 67dbd2f114 #205: Fixed
2018-10-09 18:16:23 +03:00

109 lines
3.7 KiB
C#

using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
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;
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.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace FoxTube.Controls
{
public sealed partial class ChannelCard : UserControl
{
string channelId;
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,statistics,brandingSettings");
request.Id = id;
ChannelListResponse response = await request.ExecuteAsync();
item = response.Items[0];
channelId = id;
title.Text = item.Snippet.Title;
subs.Text = $"{item.Statistics.SubscriberCount:0,0} subscribers";
uploads.Text = $"{item.Statistics.VideoCount:0,0} videos";
if (live == "live")
liveTag.Visibility = Visibility.Visible;
if(SecretsVault.IsAuthorized)
{
foreach(Subscription s in SecretsVault.Subscriptions)
{
if(s.Snippet.ResourceId.ChannelId == id)
{
subscribe.Background = new SolidColorBrush(Colors.Transparent);
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
subscribe.Content = "Subscribed";
}
}
subscriptionPane.Visibility = Visibility.Visible;
}
try { avatar.ProfilePicture = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url)); }
catch { }
try
{
if (item.BrandingSettings.Image.BannerImageUrl.Contains("default"))
throw new Exception("Default channel cover detected");
cover.Source = new BitmapImage(new Uri(item.BrandingSettings.Image.BannerTvLowImageUrl));
}
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.Authorize();
}
private async void subscribe_Click(object sender, RoutedEventArgs e)
{
if (await SecretsVault.ChangeSubscriptionState(channelId))
{
subscribe.Background = new SolidColorBrush(Colors.Transparent);
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
subscribe.Content = "Subscribed";
}
else
{
subscribe.Background = new SolidColorBrush(Colors.Red);
subscribe.Foreground = new SolidColorBrush(Colors.White);
subscribe.Content = "Subscribe";
}
}
}
}