Add unread count to `INotificationOverlay` and fix toolbar button DI logic

This commit is contained in:
Dean Herbert 2022-04-19 11:10:11 +09:00
parent 94335c2938
commit 83e89b3e80
4 changed files with 27 additions and 11 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using Moq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -22,6 +23,17 @@ public class TestSceneToolbar : OsuManualInputManagerTestScene
[Resolved]
private IRulesetStore rulesets { get; set; }
private readonly Mock<INotificationOverlay> notifications = new Mock<INotificationOverlay>();
private readonly BindableInt unreadNotificationCount = new BindableInt();
[BackgroundDependencyLoader]
private void load()
{
Dependencies.CacheAs(notifications.Object);
notifications.SetupGet(n => n.UnreadCount).Returns(unreadNotificationCount);
}
[SetUp]
public void SetUp() => Schedule(() =>
{
@ -31,10 +43,6 @@ public void SetUp() => Schedule(() =>
[Test]
public void TestNotificationCounter()
{
ToolbarNotificationButton notificationButton = null;
AddStep("retrieve notification button", () => notificationButton = toolbar.ChildrenOfType<ToolbarNotificationButton>().Single());
setNotifications(1);
setNotifications(2);
setNotifications(3);
@ -43,7 +51,7 @@ public void TestNotificationCounter()
void setNotifications(int count)
=> AddStep($"set notification count to {count}",
() => notificationButton.NotificationCount.Value = count);
() => unreadNotificationCount.Value = count);
}
[TestCase(false)]

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Overlays.Notifications;
namespace osu.Game.Overlays
@ -22,5 +23,10 @@ public interface INotificationOverlay
/// Hide the overlay, if it is currently visible.
/// </summary>
void Hide();
/// <summary>
/// Current number of unread notifications.
/// </summary>
IBindable<int> UnreadCount { get; }
}
}

View File

@ -99,7 +99,9 @@ protected override void LoadComplete()
OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true);
}
public readonly BindableInt UnreadCount = new BindableInt();
public IBindable<int> UnreadCount => unreadCount;
private readonly BindableInt unreadCount = new BindableInt();
private int runningDepth;
@ -180,7 +182,7 @@ private void playDebouncedSample(string sampleName)
private void updateCounts()
{
UnreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
unreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
}
private void markAllRead()

View File

@ -18,7 +18,7 @@ public class ToolbarNotificationButton : ToolbarOverlayToggleButton
{
protected override Anchor TooltipAnchor => Anchor.TopRight;
public BindableInt NotificationCount = new BindableInt();
public IBindable<int> NotificationCount = new BindableInt();
private readonly CountCircle countDisplay;
@ -36,10 +36,10 @@ public ToolbarNotificationButton()
});
}
[BackgroundDependencyLoader(true)]
private void load(NotificationOverlay notificationOverlay)
[BackgroundDependencyLoader]
private void load(INotificationOverlay notificationOverlay)
{
StateContainer = notificationOverlay;
StateContainer = notificationOverlay as NotificationOverlay;
if (notificationOverlay != null)
NotificationCount.BindTo(notificationOverlay.UnreadCount);