Optimization, refactoring, debugging
Related Work Items: #251, #252, #261
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Google.Apis.YouTube.v3;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using Microsoft.AppCenter.Analytics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
@@ -12,11 +14,13 @@ namespace FoxTube.Controls
|
||||
/// <summary>
|
||||
/// Playlist card control
|
||||
/// </summary>
|
||||
public sealed partial class PlaylistCard : Page, IItemCard
|
||||
public sealed partial class PlaylistCard : Page
|
||||
{
|
||||
Playlist item;
|
||||
public string playlistId;
|
||||
|
||||
public bool NeedInitialize { get; set; } = true;
|
||||
|
||||
public PlaylistCard(string id)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -25,34 +29,41 @@ namespace FoxTube.Controls
|
||||
|
||||
public async void Initialize(string id)
|
||||
{
|
||||
PlaylistsResource.ListRequest request = SecretsVault.Service.Playlists.List("snippet,contentDetails");
|
||||
request.Id = id;
|
||||
PlaylistListResponse response = await request.ExecuteAsync();
|
||||
|
||||
item = response.Items[0];
|
||||
playlistId = id;
|
||||
|
||||
title.Text = item.Snippet.Title;
|
||||
channelName.Text = item.Snippet.ChannelTitle;
|
||||
counter.Text = item.ContentDetails.ItemCount.ToString();
|
||||
date.Text = Methods.GetAgo(item.Snippet.PublishedAt.Value);
|
||||
|
||||
ChannelsResource.ListRequest r = SecretsVault.Service.Channels.List("snippet");
|
||||
r.Id = item.Snippet.ChannelId;
|
||||
|
||||
try
|
||||
{
|
||||
thumbnail.Source = new BitmapImage((item.Snippet.Thumbnails.Maxres ?? item.Snippet.Thumbnails.Medium).Url.ToUri());
|
||||
avatar.ProfilePicture = new BitmapImage(new Uri((await r.ExecuteAsync()).Items[0].Snippet.Thumbnails.Medium.Url));
|
||||
} catch { }
|
||||
playlistId = id;
|
||||
PlaylistsResource.ListRequest request = SecretsVault.Service.Playlists.List("snippet,contentDetails");
|
||||
request.Id = playlistId;
|
||||
item = (await request.ExecuteAsync()).Items[0];
|
||||
|
||||
title.Text = item.Snippet.Title;
|
||||
channelName.Text = item.Snippet.ChannelTitle;
|
||||
counter.Text = item.ContentDetails.ItemCount.ToString();
|
||||
date.Text = Methods.GetAgo(item.Snippet.PublishedAt.Value);
|
||||
|
||||
ChannelsResource.ListRequest r = SecretsVault.Service.Channels.List("snippet");
|
||||
r.Id = item.Snippet.ChannelId;
|
||||
|
||||
try { thumbnail.Source = new BitmapImage(item.Snippet.Thumbnails.Medium.Url.ToUri()); }
|
||||
catch { }
|
||||
try { avatar.ProfilePicture = new BitmapImage(new Uri((await r.ExecuteAsync()).Items[0].Snippet.Thumbnails.Medium.Url)); }
|
||||
catch { }
|
||||
|
||||
Opacity = 1;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Visibility = Visibility.Collapsed;
|
||||
Analytics.TrackEvent("PlaylistCard loading failed", new Dictionary<string, string>()
|
||||
{
|
||||
{ "Exception", e.GetType().ToString() },
|
||||
{ "Message", e.Message },
|
||||
{ "Playlist ID", playlistId }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
Height = e.NewSize.Width * 0.75;
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
public void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Methods.MainPage.GoToPlaylist(item.Id);
|
||||
}
|
||||
@@ -73,5 +84,10 @@ namespace FoxTube.Controls
|
||||
{
|
||||
await Launcher.LaunchUriAsync($"https://www.youtube.com/playlist?list={playlistId}".ToUri());
|
||||
}
|
||||
|
||||
private void Thumbnail_ImageOpened(object sender, RoutedEventArgs e)
|
||||
{
|
||||
thumbnail.Opacity = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user