Archived
1
0

Playlist sharing

This commit is contained in:
Michael Gordeev
2018-08-01 21:40:25 +03:00
parent 2614a7d88d
commit e6547b06be
3 changed files with 52 additions and 2 deletions
+3 -2
View File
@@ -135,10 +135,11 @@
</Pivot>
</ScrollViewer>
<CommandBar Grid.Row="1" VerticalAlignment="Bottom" Name="commandBar">
<AppBarButton Icon="Favorite" Label="Add to bookmarks"/>
<AppBarButton Icon="Globe" Label="Open in browser" Name="inBrowser"/>
<AppBarButton Icon="Favorite" Label="Add to bookmarks" Visibility="Collapsed"/>
<AppBarButton Icon="Refresh" Label="Refresh"/>
<AppBarButton Icon="Share" Label="Share"/>
<AppBarButton Icon="Flag" Label="Report this channel"/>
<AppBarButton Icon="Flag" Label="Report this channel" Visibility="Collapsed"/>
</CommandBar>
</Grid>
</Page>
+1
View File
@@ -71,6 +71,7 @@
</AppBarButton.Flyout>
</AppBarButton>
<AppBarButton Icon="Refresh" Label="Refresh" Name="refresh" Click="refresh_Click"/>
<AppBarButton Icon="Share" Label="Share" Name="share" Click="share_Click"/>
</CommandBar>
<foxtube:LoadingPage Grid.RowSpan="2" Visibility="Collapsed"/>
+48
View File
@@ -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<DataTransferManager, DataRequestedEventArgs>(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("<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();
}
}
}
}