-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
991 additions
and
20 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...utao/Snap.Hutao/Control/Collection/AdvancedCollectionView/AdvancedCollectionView.Defer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...tao/Snap.Hutao/Control/Collection/AdvancedCollectionView/AdvancedCollectionView.Events.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.