Archived
1
0

Sharing fixed

Related Work Items: #214
This commit is contained in:
Michael Gordeev
2018-12-24 17:51:22 +03:00
parent efb07fda10
commit e172890c4b
4 changed files with 49 additions and 146 deletions
+7 -58
View File
@@ -1,44 +1,25 @@
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;
using Windows.UI;
using System.Diagnostics;
// 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.
/// Channel page
/// </summary>
public sealed partial class ChannelPage : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
public string channelId;
public Channel item;
@@ -299,45 +280,13 @@ namespace FoxTube.Pages
DataTransferManager.ShowShareUI();
}
private async void Share(DataTransferManager sender, DataRequestedEventArgs args)
private 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();
}
Methods.Share(args,
item.Snippet.Thumbnails.Medium.Url,
item.Snippet.Title,
string.IsNullOrWhiteSpace(item.Snippet.CustomUrl) ? $"https://www.youtube.com/channel/{item.Id}" : $"https://www.youtube.com/user/{item.Snippet.CustomUrl}",
"channel");
}
}
}
+8 -51
View File
@@ -2,32 +2,18 @@
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.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.System;
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 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.
/// Playlist page
/// </summary>
public sealed partial class PlaylistPage : Page
{
@@ -39,7 +25,7 @@ namespace FoxTube.Pages
public PlaylistPage()
{
this.InitializeComponent();
InitializeComponent();
loading = grid.Children[2] as LoadingPage;
list = ((grid.Children[0] as ScrollViewer).Content as Grid).Children[1] as VideoGrid;
loading.RefreshPage += refresh_Click;
@@ -137,42 +123,13 @@ namespace FoxTube.Pages
DataTransferManager.ShowShareUI();
}
private async void Share(DataTransferManager sender, DataRequestedEventArgs args)
private void Share(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
request.Data.Properties.Title = item.Snippet.Title;
request.Data.Properties.Description = "Sharing a playlist";
// Handle errors
//request.FailWithDisplayText("Something unexpected could happen.");
// Plain text
request.Data.SetText(item.Snippet.Title + "\n" + "#YouTube #FoxTube #SharedWithFoxTube");
// Uniform Resource Identifiers (URIs)
request.Data.SetWebLink(new Uri($"https://www.youtube.com/playlist?list={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();
}
Methods.Share(args,
item.Snippet.Thumbnails.Medium.Url,
item.Snippet.Title,
$"https://www.youtube.com/playlist?list={item.Id}",
"playlist");
}
}
}
+7 -37
View File
@@ -13,8 +13,6 @@ using Windows.UI.Xaml.Media.Imaging;
using System.Diagnostics;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.ApplicationModel;
using Windows.Storage.Streams;
using Windows.UI;
using FoxTube.Controls;
using YoutubeExplode.Models.MediaStreams;
@@ -61,7 +59,7 @@ namespace FoxTube.Pages
public VideoPage()
{
this.InitializeComponent();
InitializeComponent();
loading = grid.Children[3] as LoadingPage;
loading.RefreshPage += refresh_Click;
player = mainContent.Children[0] as VideoPlayer;
@@ -367,43 +365,15 @@ namespace FoxTube.Pages
}
}
private async void Share(DataTransferManager sender, DataRequestedEventArgs args)
private void Share(DataTransferManager sender, DataRequestedEventArgs args)
{
player.Pause();
DataRequest request = args.Request;
request.Data.Properties.Title = item.Snippet.Title;
request.Data.Properties.Description = "Sharing a video";
// Handle errors
//request.FailWithDisplayText("Something unexpected could happen.");
// Plain text
request.Data.SetText(item.Snippet.Title + "\n" + "#YouTube #FoxTube #SharedWithFoxTube");
// Uniform Resource Identifiers (URIs)
request.Data.SetWebLink(new Uri(string.Format("https://www.youtube.com/watch?v={0}", videoId)));
// 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();
}
Methods.Share(args,
item.Snippet.Thumbnails.Medium.Url,
item.Snippet.Title,
$"https://www.youtube.com/watch?v={videoId}",
"video");
}
private void share_Click(object sender, RoutedEventArgs e)