Archived
1
0

Development 7

This commit is contained in:
Michael Gordeev
2018-07-22 15:00:47 +03:00
parent 57c90f4037
commit 0338d8a626
24 changed files with 727 additions and 359 deletions
+49 -49
View File
@@ -1,36 +1,21 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 System.Xml;
using Windows.System;
using Windows.UI.Popups;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace FoxTube
namespace FoxTube.Controls
{
public sealed partial class VideoCard : UserControl
{
public string videoId;
Google.Apis.YouTube.v3.Data.Video item;
bool embed = false;
bool embed = true;
public VideoCard(string id)
{
this.InitializeComponent();
@@ -51,58 +36,73 @@ namespace FoxTube
VideoListResponse response = await request.ExecuteAsync();
item = response.Items[0];
videoId = id;
title.Text = item.Snippet.Title;
views.Text = string.Format("{0} views", item.Statistics.ViewCount);
string duration;
if (!string.IsNullOrWhiteSpace(item.ContentDetails.Duration))
{
TimeSpan ts = XmlConvert.ToTimeSpan(item.ContentDetails.Duration);
duration = string.Format("{0}{1:00}:{2:00} | ", ts.Hours == 0 ? "" : ts.Hours + ":", ts.Minutes, ts.Seconds);
}
else duration = string.Empty;
info.Text = string.Format("{0}{1} | {2}", duration, Methods.GetAgo(item.Snippet.PublishedAt.Value), (item.LiveStreamingDetails != null && item.LiveStreamingDetails.ConcurrentViewers.HasValue) ? item.LiveStreamingDetails.ConcurrentViewers + " viewers" : item.Statistics.ViewCount + " views");
thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
channelName.Text = item.Snippet.ChannelTitle;
if (item.Snippet.LiveBroadcastContent == "live")
{
embed = true;
views.Text = $"{item.LiveStreamingDetails.ConcurrentViewers} viewers";
if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && item.LiveStreamingDetails.ScheduledEndTime.HasValue)
info.Text = $"{item.LiveStreamingDetails.ScheduledEndTime - item.LiveStreamingDetails.ScheduledStartTime} | {Methods.GetAgo(item.LiveStreamingDetails.ActualStartTime.Value)}";
else
info.Text = item.LiveStreamingDetails.ActualStartTime.Value.ToString();
liveTag.Visibility = Visibility.Visible;
}
else if (item.Snippet.LiveBroadcastContent == "upcoming")
else if(item.Snippet.LiveBroadcastContent == "upcoming")
{
embed = true;
TimeSpan span;
if (item.LiveStreamingDetails.ScheduledStartTime != null && (item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now).Value.TotalMilliseconds > 0)
{
span = (TimeSpan)(item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now);
liveContent.Text = "Goes live in " + string.Format("{0}{1:00}:{2:00}:{3:00}", span.Days != 0 ? span.Days + ":" : "", span.Hours, span.Minutes, span.Seconds);
}
views.Text = "";
if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && item.LiveStreamingDetails.ScheduledEndTime.HasValue)
info.Text = $"{item.LiveStreamingDetails.ScheduledEndTime - item.LiveStreamingDetails.ScheduledStartTime} | {item.LiveStreamingDetails.ScheduledStartTime}";
else
liveContent.Text = "Upcoming";
info.Text = $"{Methods.GetAgo(item.Snippet.PublishedAt.Value)}";
liveTag.Visibility = Visibility.Visible;
if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && (item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now).Value.TotalMilliseconds > 0)
liveContent.Text = $"Goes live in {item.LiveStreamingDetails.ScheduledStartTime}";
else liveContent.Text = "Upcoming";
}
else
{
views.Text = $"{item.Statistics.ViewCount} views";
info.Text = $"{XmlConvert.ToTimeSpan(item.ContentDetails.Duration)} | {Methods.GetAgo(item.Snippet.PublishedAt.Value)}";
embed = false;
}
var request1 = ytService.Channels.List("snippet,contentDetails,statistics");
var request1 = ytService.Channels.List("snippet");
request1.Id = item.Snippet.ChannelId;
ChannelListResponse response1 = await request1.ExecuteAsync();
var item1 = response1.Items[0];
try
{
avatar.ProfilePicture = new BitmapImage(new Uri(response1.Items[0].Snippet.Thumbnails.Medium.Url));
thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
}
catch { }
avatar.ProfilePicture = new BitmapImage(new Uri(item1.Snippet.Thumbnails.Medium.Url));
channelName.Text = item1.Snippet.Title;
if (SecretsVault.UserHistory.Contains(item.Id))
watched.Visibility = Visibility.Visible;
foreach(PlaylistItem i in SecretsVault.UserHistory)
if (i.Snippet.ResourceId.VideoId == id)
{
watched.Visibility = Visibility.Visible;
break;
}
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
if (embed)
await Launcher.LaunchUriAsync(new Uri(string.Format("https://www.youtube.com/watch?v={0}", videoId)));
{
MessageDialog dialog = new MessageDialog("Unfortunately, at this stage of application development we don't support live steams. This issue will be fixed in the next update. Sorry. Would you like us to open this stream in browser?", "Open in browser");
dialog.Commands.Add(new UICommand("Yes", async (command) =>
{
await Launcher.LaunchUriAsync(new Uri($"https://www.youtube.com/watch?v={videoId}"));
}));
dialog.Commands.Add(new UICommand("No"));
dialog.DefaultCommandIndex = 0;
dialog.CancelCommandIndex = 1;
await dialog.ShowAsync();
}
else
Methods.MainPage.GoToVideo(videoId);
}