Skip to content

Commit

Permalink
refine #1334
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Feb 5, 2024
1 parent 678ec19 commit 95024e4
Show file tree
Hide file tree
Showing 10 changed files with 991 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

namespace Snap.Hutao.Control.Collection.AdvancedCollectionView;

/// <summary>
/// A collection view implementation that supports filtering, grouping, sorting and incremental loading
/// </summary>
internal partial class AdvancedCollectionView
{
/// <summary>
/// Stops refreshing until it is disposed
/// </summary>
/// <returns>An disposable object</returns>
public IDisposable DeferRefresh()
{
return new NotificationDeferrer(this);
}

/// <summary>
/// Notification deferrer helper class
/// </summary>
#pragma warning disable CA1063 // Implement IDisposable Correctly
public class NotificationDeferrer : IDisposable
#pragma warning restore CA1063 // Implement IDisposable Correctly
{
private readonly AdvancedCollectionView _acvs;
private readonly object _currentItem;

/// <summary>
/// Initializes a new instance of the <see cref="NotificationDeferrer"/> class.
/// </summary>
/// <param name="acvs">Source ACVS</param>
public NotificationDeferrer(AdvancedCollectionView acvs)
{
_acvs = acvs;
_currentItem = _acvs.CurrentItem;
_acvs._deferCounter++;
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <filterpriority>2</filterpriority>
#pragma warning disable CA1063 // Implement IDisposable Correctly
public void Dispose()
#pragma warning restore CA1063 // Implement IDisposable Correctly
{
_acvs.MoveCurrentTo(_currentItem);
_acvs._deferCounter--;
_acvs.Refresh();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Microsoft.UI.Xaml.Data;
using Windows.Foundation.Collections;

namespace Snap.Hutao.Control.Collection.AdvancedCollectionView;

/// <summary>
/// A collection view implementation that supports filtering, grouping, sorting and incremental loading
/// </summary>
internal partial class AdvancedCollectionView
{
/// <summary>
/// Currently selected item changing event
/// </summary>
/// <param name="e">event args</param>
private void OnCurrentChanging(CurrentChangingEventArgs e)
{
if (_deferCounter > 0)
{
return;
}

CurrentChanging?.Invoke(this, e);
}

/// <summary>
/// Currently selected item changed event
/// </summary>
/// <param name="e">event args</param>
private void OnCurrentChanged(object e)
{
if (_deferCounter > 0)
{
return;
}

CurrentChanged?.Invoke(this, e);

// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(nameof(CurrentItem));
}

/// <summary>
/// Vector changed event
/// </summary>
/// <param name="e">event args</param>
private void OnVectorChanged(IVectorChangedEventArgs e)
{
if (_deferCounter > 0)
{
return;
}

VectorChanged?.Invoke(this, e);

// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(nameof(Count));
}
}
Loading

0 comments on commit 95024e4

Please sign in to comment.