Toast notifications for downloads
This commit is contained in:
@@ -9,7 +9,7 @@ namespace FoxTube.Background
|
|||||||
{
|
{
|
||||||
XmlDocument template = new XmlDocument();
|
XmlDocument template = new XmlDocument();
|
||||||
|
|
||||||
template.LoadXml($@"<toast activationType='foreground' launch='changelog-{version.Replace(".", "-")}'>
|
template.LoadXml($@"<toast activationType='foreground' launch='changelog|{version.Replace(".", "-")}'>
|
||||||
<visual>
|
<visual>
|
||||||
<binding template='ToastGeneric'>
|
<binding template='ToastGeneric'>
|
||||||
<image placement='hero' src='http://foxgame.hol.es/FoxTubeAssets/WhatsNewThumb.png'/>
|
<image placement='hero' src='http://foxgame.hol.es/FoxTubeAssets/WhatsNewThumb.png'/>
|
||||||
@@ -27,7 +27,7 @@ namespace FoxTube.Background
|
|||||||
{
|
{
|
||||||
XmlDocument template = new XmlDocument();
|
XmlDocument template = new XmlDocument();
|
||||||
|
|
||||||
template.LoadXml($@"<toast activationType='foreground' launch='video-{id}'>
|
template.LoadXml($@"<toast activationType='foreground' launch='video|{id}'>
|
||||||
<visual>
|
<visual>
|
||||||
<binding template='ToastGeneric'>
|
<binding template='ToastGeneric'>
|
||||||
<image placement='hero' src='{thumbnail}'/>
|
<image placement='hero' src='{thumbnail}'/>
|
||||||
@@ -50,7 +50,7 @@ namespace FoxTube.Background
|
|||||||
{
|
{
|
||||||
XmlDocument template = new XmlDocument();
|
XmlDocument template = new XmlDocument();
|
||||||
|
|
||||||
template.LoadXml($@"<toast activationType='foreground' launch='inbox-{id}'>
|
template.LoadXml($@"<toast activationType='foreground' launch='inbox|{id}'>
|
||||||
<visual>
|
<visual>
|
||||||
<binding template='ToastGeneric'>
|
<binding template='ToastGeneric'>
|
||||||
<image placement='hero' src='{thumbnail ?? "http://foxgame.hol.es/FoxTubeAssets/AnnouncementThumb.png"}'/>
|
<image placement='hero' src='{thumbnail ?? "http://foxgame.hol.es/FoxTubeAssets/AnnouncementThumb.png"}'/>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Name="progressPanel" Grid.Column="4" Margin="10">
|
<StackPanel Name="progressPanel" Grid.Column="4" Margin="10">
|
||||||
<TextBlock Name="status" Text="Initializing..." HorizontalAlignment="Left"/>
|
<TextBlock Name="status" Text="Initializing..." HorizontalAlignment="Left"/>
|
||||||
<ProgressBar Name="progressBar" Width="200" IsIndeterminate="True" Foreground="Red"/>
|
<ProgressBar Name="progressBar" Width="200" Maximum="1" IsIndeterminate="True" Foreground="Red"/>
|
||||||
<TextBlock Name="perc" Text="--%"/>
|
<TextBlock Name="perc" Text="--%"/>
|
||||||
<Button Content="Cancel" Name="cancel" Click="cancel_Click" HorizontalAlignment="Right"/>
|
<Button Content="Cancel" Name="cancel" Click="cancel_Click" HorizontalAlignment="Right"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ using System.Xml;
|
|||||||
using Windows.UI.Popups;
|
using Windows.UI.Popups;
|
||||||
using Windows.Storage.Pickers;
|
using Windows.Storage.Pickers;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Windows.UI.Notifications;
|
||||||
|
using Microsoft.Toolkit.Uwp.Notifications;
|
||||||
|
|
||||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ namespace FoxTube.Controls
|
|||||||
CancellationTokenSource cts = new CancellationTokenSource();
|
CancellationTokenSource cts = new CancellationTokenSource();
|
||||||
CancellationToken token;
|
CancellationToken token;
|
||||||
Progress<double> progress = new Progress<double>();
|
Progress<double> progress = new Progress<double>();
|
||||||
|
NotificationData data = new NotificationData();
|
||||||
|
|
||||||
public DownloadItem(MediaStreamInfo info, Video meta, string q)
|
public DownloadItem(MediaStreamInfo info, Video meta, string q)
|
||||||
{
|
{
|
||||||
@@ -79,7 +82,41 @@ namespace FoxTube.Controls
|
|||||||
Cancel();
|
Cancel();
|
||||||
Container.File = await folder.CreateFileAsync($"{meta.Snippet.Title.ReplaceInvalidChars('_')}.{info.Container.GetFileExtension()}", CreationCollisionOption.GenerateUniqueName);
|
Container.File = await folder.CreateFileAsync($"{meta.Snippet.Title.ReplaceInvalidChars('_')}.{info.Container.GetFileExtension()}", CreationCollisionOption.GenerateUniqueName);
|
||||||
|
|
||||||
//TO-DO: Create toast
|
ToastContent toastContent = new ToastContent()
|
||||||
|
{
|
||||||
|
Visual = new ToastVisual()
|
||||||
|
{
|
||||||
|
BindingGeneric = new ToastBindingGeneric()
|
||||||
|
{
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new AdaptiveText() { Text = "Downloading a video" },
|
||||||
|
new AdaptiveProgressBar()
|
||||||
|
{
|
||||||
|
Title = meta.Snippet.Title,
|
||||||
|
Status = "Downloading...",
|
||||||
|
Value = new BindableProgressBarValue("value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Actions = new ToastActionsCustom()
|
||||||
|
{
|
||||||
|
Buttons =
|
||||||
|
{
|
||||||
|
new ToastButton("Cancel", $"dcancel|{Container.Id}")
|
||||||
|
{
|
||||||
|
ActivationType = ToastActivationType.Background
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Launch = "download",
|
||||||
|
ActivationType = ToastActivationType.Foreground
|
||||||
|
};
|
||||||
|
|
||||||
|
data.Values["value"] = "0";
|
||||||
|
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastContent.GetXml()) { Tag = $"download|{meta.Id}", Data = data });
|
||||||
|
|
||||||
Container.Channel = meta.Snippet.ChannelTitle;
|
Container.Channel = meta.Snippet.ChannelTitle;
|
||||||
Container.Duration = XmlConvert.ToTimeSpan(meta.ContentDetails.Duration);
|
Container.Duration = XmlConvert.ToTimeSpan(meta.ContentDetails.Duration);
|
||||||
@@ -100,6 +137,8 @@ namespace FoxTube.Controls
|
|||||||
donePanel.Visibility = Visibility.Collapsed;
|
donePanel.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
await client.DownloadMediaStreamAsync(info, await Container.File.OpenStreamForWriteAsync(), progress, token);
|
await client.DownloadMediaStreamAsync(info, await Container.File.OpenStreamForWriteAsync(), progress, token);
|
||||||
|
|
||||||
|
DownloadCompleted();
|
||||||
|
|
||||||
progressPanel.Visibility = Visibility.Collapsed;
|
progressPanel.Visibility = Visibility.Collapsed;
|
||||||
donePanel.Visibility = Visibility.Visible;
|
donePanel.Visibility = Visibility.Visible;
|
||||||
@@ -111,14 +150,30 @@ namespace FoxTube.Controls
|
|||||||
{
|
{
|
||||||
status.Text = "Downloading";
|
status.Text = "Downloading";
|
||||||
progressBar.Value = e;
|
progressBar.Value = e;
|
||||||
perc.Text = $"{(int)e}%";
|
perc.Text = $"{(int)e * 100}%";
|
||||||
|
|
||||||
//TO-DO: Update toast
|
data.Values["value"] = e.ToString();
|
||||||
|
ToastNotificationManager.CreateToastNotifier().Update(data, $"download|{Container.Id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
|
private void DownloadCompleted()
|
||||||
{
|
{
|
||||||
//TO-DO: Update toast
|
Windows.Data.Xml.Dom.XmlDocument template = new Windows.Data.Xml.Dom.XmlDocument();
|
||||||
|
template.LoadXml($@"<toast activationType='background' launch='download|{Container.Id}'>
|
||||||
|
<visual>
|
||||||
|
<binding template='ToastGeneric'>
|
||||||
|
<text>Download complete</text>
|
||||||
|
<text>{Container.Title}</text>
|
||||||
|
</binding>
|
||||||
|
</visual>
|
||||||
|
|
||||||
|
<actions>
|
||||||
|
<action content='Go to original'
|
||||||
|
activationType='foreground'
|
||||||
|
arguments='video|{Container.Id}'/>
|
||||||
|
</actions>
|
||||||
|
</toast>");
|
||||||
|
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(template) { Tag = $"download|{Container.Id}" });
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void open_Click(object sender, RoutedEventArgs e)
|
private async void open_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ using Windows.Storage.Pickers;
|
|||||||
using Windows.System;
|
using Windows.System;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
|
||||||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
|
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
#pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast
|
|
||||||
|
|
||||||
namespace FoxTube.Pages
|
namespace FoxTube.Pages
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,18 @@ namespace FoxTube.Pages
|
|||||||
public Downloads()
|
public Downloads()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
stack.ItemsSource = Methods.MainPage.Agent.items;
|
try
|
||||||
|
{
|
||||||
|
stack.ItemsSource = Methods.MainPage.Agent.items;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnNavigatedFrom(e);
|
||||||
|
stack.ItemsSource = null;
|
||||||
|
stack.Items.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private async void changePath_Click(object sender, RoutedEventArgs e)
|
/*private async void changePath_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace FoxTube
|
|||||||
if (settings.Values["ver"] == null)
|
if (settings.Values["ver"] == null)
|
||||||
settings.Values.Add("ver", $"{ver.Major}.{ver.Minor}");
|
settings.Values.Add("ver", $"{ver.Major}.{ver.Minor}");
|
||||||
|
|
||||||
if((string)settings.Values["ver"] == $"{ver.Major}.{ver.Minor}") //Replace for '!=' !!!
|
if((string)settings.Values["ver"] != $"{ver.Major}.{ver.Minor}") //Replace for '!=' !!!
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user