Skip to content

Feat: Reuse MediaPreview instance in InfoPane #17313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Files.App/UserControls/FilePreviews/MediaPreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ private void TogglePlaybackAcceleratorInvoked(KeyboardAccelerator sender, Keyboa
{
TogglePlaybackRequestInvoked(sender, null);
}

public async Task UpdateViewModelAsync(MediaPreviewViewModel model)
{
ViewModel = model;
await ViewModel.LoadAsync();
}
}
}
13 changes: 11 additions & 2 deletions src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed partial class InfoPaneViewModel : ObservableObject, IDisposable
private DrivesViewModel drivesViewModel { get; } = Ioc.Default.GetRequiredService<DrivesViewModel>();

private CancellationTokenSource loadCancellationTokenSource;
private MediaPreview? _mediaPreview;

/// <summary>
/// Value indicating if the info pane is on/off
Expand Down Expand Up @@ -273,9 +274,17 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
(FileExtensionHelpers.IsAudioFile(ext) || FileExtensionHelpers.IsVideoFile(ext)))
{
var model = new MediaPreviewViewModel(item);
await model.LoadAsync();

return new MediaPreview(model);
if (_mediaPreview is null)
{
await model.LoadAsync(); // Load only if creating new instance
_mediaPreview = new(model);
}
else
{
await _mediaPreview.UpdateViewModelAsync(model); // Update existing instance
}
return _mediaPreview;
}

if (MarkdownPreviewViewModel.ContainsExtension(ext))
Expand Down
Loading