Archived
1
0

Toast notifications for downloads

This commit is contained in:
Michael Gordeev
2018-10-24 21:07:08 +03:00
parent dc8afa2891
commit f545edc6c1
5 changed files with 78 additions and 12 deletions
+1 -1
View File
@@ -45,7 +45,7 @@
</StackPanel>
<StackPanel Name="progressPanel" Grid.Column="4" Margin="10">
<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="--%"/>
<Button Content="Cancel" Name="cancel" Click="cancel_Click" HorizontalAlignment="Right"/>
</StackPanel>
+60 -5
View File
@@ -15,6 +15,8 @@ using System.Xml;
using Windows.UI.Popups;
using Windows.Storage.Pickers;
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
@@ -31,6 +33,7 @@ namespace FoxTube.Controls
CancellationTokenSource cts = new CancellationTokenSource();
CancellationToken token;
Progress<double> progress = new Progress<double>();
NotificationData data = new NotificationData();
public DownloadItem(MediaStreamInfo info, Video meta, string q)
{
@@ -79,7 +82,41 @@ namespace FoxTube.Controls
Cancel();
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.Duration = XmlConvert.ToTimeSpan(meta.ContentDetails.Duration);
@@ -100,6 +137,8 @@ namespace FoxTube.Controls
donePanel.Visibility = Visibility.Collapsed;
await client.DownloadMediaStreamAsync(info, await Container.File.OpenStreamForWriteAsync(), progress, token);
DownloadCompleted();
progressPanel.Visibility = Visibility.Collapsed;
donePanel.Visibility = Visibility.Visible;
@@ -111,14 +150,30 @@ namespace FoxTube.Controls
{
status.Text = "Downloading";
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)
+13 -2
View File
@@ -11,9 +11,9 @@ using Windows.Storage.Pickers;
using Windows.System;
using Windows.UI.Xaml;
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
#pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast
namespace FoxTube.Pages
{
@@ -25,7 +25,18 @@ namespace FoxTube.Pages
public Downloads()
{
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)
+1 -1
View File
@@ -74,7 +74,7 @@ namespace FoxTube
if (settings.Values["ver"] == null)
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
{