From e6547b06be7c922d36e4f7ce39166aae458356ab Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Wed, 1 Aug 2018 21:40:25 +0300 Subject: [PATCH] Playlist sharing --- FoxTube/Pages/Channel.xaml | 5 ++-- FoxTube/Pages/PlaylistPage.xaml | 1 + FoxTube/Pages/PlaylistPage.xaml.cs | 48 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/FoxTube/Pages/Channel.xaml b/FoxTube/Pages/Channel.xaml index 1b580e9..c8df887 100644 --- a/FoxTube/Pages/Channel.xaml +++ b/FoxTube/Pages/Channel.xaml @@ -135,10 +135,11 @@ - + + - + diff --git a/FoxTube/Pages/PlaylistPage.xaml b/FoxTube/Pages/PlaylistPage.xaml index 42b88a4..22929f5 100644 --- a/FoxTube/Pages/PlaylistPage.xaml +++ b/FoxTube/Pages/PlaylistPage.xaml @@ -71,6 +71,7 @@ + diff --git a/FoxTube/Pages/PlaylistPage.xaml.cs b/FoxTube/Pages/PlaylistPage.xaml.cs index 349387a..02e3fe7 100644 --- a/FoxTube/Pages/PlaylistPage.xaml.cs +++ b/FoxTube/Pages/PlaylistPage.xaml.cs @@ -6,8 +6,12 @@ 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; @@ -39,6 +43,7 @@ namespace FoxTube.Pages loading = grid.Children[2] as LoadingPage; list = ((grid.Children[0] as ScrollViewer).Content as Grid).Children[1] as VideoGrid; loading.RefreshPage += refresh_Click; + DataTransferManager.GetForCurrentView().DataRequested += new TypedEventHandler(Share); } protected override void OnNavigatedTo(NavigationEventArgs e) @@ -121,5 +126,48 @@ namespace FoxTube.Pages { Initialize(playlistId); } + + private void share_Click(object sender, RoutedEventArgs e) + { + DataTransferManager.ShowShareUI(); + } + + private async 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("Bold Text"); + + // 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(); + } + } } }