Skip to content

Commit

Permalink
Check if download button is still valid
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed Jan 21, 2024
1 parent debb387 commit 4ca49f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Telegram/Controls/FileButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ protected override void OnApplyTemplate()

public double InternalProgress
{
get => (double)GetValue(ProgressProperty);
get => (double)GetValue(InternalProgressProperty);
set
{
try
{
SetValue(ProgressProperty, value);
SetValue(InternalProgressProperty, value);
}
catch (Exception ex)
{
Expand All @@ -89,7 +89,7 @@ public double InternalProgress
}
}

public static readonly DependencyProperty ProgressProperty =
public static readonly DependencyProperty InternalProgressProperty =
DependencyProperty.Register("InternalProgress", typeof(double), typeof(FileButton), new PropertyMetadata(0.0));

#endregion
Expand Down Expand Up @@ -331,17 +331,7 @@ private void SetDownloadGlyphImpl(bool animate)
_shouldEnqueueProgress = true;

var batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
batch.Completed += (s, args) =>
{
if (_state == MessageContentState.Downloading)
{
OnGlyphChanged(Icons.Cancel, Icons.ArrowDownload, true, Strings.AccActionCancelDownload, false);
InternalProgress = _enqueuedProgress;
}
_shouldEnqueueProgress = false;
//_container.Children.RemoveAll();
};
batch.Completed += OnDownloadingCompleted;

var animLeft = compositor.CreateScalarKeyFrameAnimation();
animLeft.InsertKeyFrame(0, 1);
Expand Down Expand Up @@ -375,6 +365,18 @@ private void SetDownloadGlyphImpl(bool animate)
arrowPath.StartAnimation("TrimEnd", animBodyEnd);
}

private void OnDownloadingCompleted(object sender, CompositionBatchCompletedEventArgs args)
{
if (_state == MessageContentState.Downloading && this.IsConnected())
{
OnGlyphChanged(Icons.Cancel, Icons.ArrowDownload, true, Strings.AccActionCancelDownload, false);
InternalProgress = _enqueuedProgress;
}

_shouldEnqueueProgress = false;
//_container.Children.RemoveAll();
}

private CompositionPath GetArrowShape()
{
CanvasGeometry result;
Expand Down
8 changes: 8 additions & 0 deletions Telegram/Controls/FrameworkElementEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ namespace Telegram.Controls
// Name of the file is FrameworkElementEx.cs because supposedly this code should be
// added to all classes inheriting FrameworkElement, but this isn't really possible in C#.

public static class FrameworkElementEx
{
public static bool IsConnected(this FrameworkElement element)
{
return Windows.UI.Xaml.Media.VisualTreeHelper.GetParent(element) != null;
}
}

// TODO: would be great to find a way to have this as a template.

public class ControlEx : Control
Expand Down

0 comments on commit 4ca49f3

Please sign in to comment.