Add missing realm subscription cleanup

This commit is contained in:
Dean Herbert
2022-07-28 13:50:19 +09:00
parent ad482b8afc
commit da06467891

View File

@ -20,13 +20,15 @@ namespace osu.Game.Collections
/// </summary>
public class DrawableCollectionList : OsuRearrangeableListContainer<Live<BeatmapCollection>>
{
private Scroll scroll = null!;
protected override ScrollContainer<Drawable> CreateScrollContainer() => scroll = new Scroll();
[Resolved]
private RealmAccess realm { get; set; } = null!;
private Scroll scroll = null!;
private IDisposable? realmSubscription;
protected override FillFlowContainer<RearrangeableListItem<Live<BeatmapCollection>>> CreateListFillFlowContainer() => new Flow
{
DragActive = { BindTarget = DragActive }
@ -36,7 +38,7 @@ namespace osu.Game.Collections
{
base.LoadComplete();
realm.RegisterForNotifications(r => r.All<BeatmapCollection>(), collectionsChanged);
realmSubscription = realm.RegisterForNotifications(r => r.All<BeatmapCollection>(), collectionsChanged);
}
private void collectionsChanged(IRealmCollection<BeatmapCollection> collections, ChangeSet? changes, Exception error)
@ -53,6 +55,12 @@ namespace osu.Game.Collections
return new DrawableCollectionListItem(item, true);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
realmSubscription?.Dispose();
}
/// <summary>
/// The scroll container for this <see cref="DrawableCollectionList"/>.
/// Contains the main flow of <see cref="DrawableCollectionListItem"/> and attaches a placeholder item to the end of the list.