Remove unnecessary inheritance to OverlayView

This commit is contained in:
Salman Ahmed 2020-12-18 02:51:19 +03:00
parent 5e4f667cff
commit 9c22753f3f
2 changed files with 19 additions and 18 deletions

View File

@ -20,7 +20,7 @@ public class TestSceneFriendDisplay : OsuTestScene
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
private TestFriendDisplay display;
private FriendDisplay display;
[SetUp]
public void Setup() => Schedule(() =>
@ -28,7 +28,7 @@ public void Setup() => Schedule(() =>
Child = new BasicScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = display = new TestFriendDisplay()
Child = display = new FriendDisplay()
};
});
@ -41,7 +41,7 @@ public void TestOffline()
[Test]
public void TestOnline()
{
AddStep("Fetch online", () => display?.Fetch());
// No need to do anything, fetch is performed automatically.
}
private List<User> getUsers() => new List<User>
@ -76,10 +76,5 @@ public void TestOnline()
LastVisit = DateTimeOffset.Now
}
};
private class TestFriendDisplay : FriendDisplay
{
public void Fetch() => PerformFetch();
}
}
}

View File

@ -5,16 +5,18 @@
using System.Linq;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Users;
using osuTK;
namespace osu.Game.Overlays.Dashboard.Friends
{
public class FriendDisplay : OverlayView<List<User>>
public class FriendDisplay : CompositeDrawable
{
private List<User> users = new List<User>();
@ -39,8 +41,16 @@ public List<User> Users
private Container itemsPlaceholder;
private LoadingLayer loading;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
private readonly IBindableList<User> apiFriends = new BindableList<User>();
public FriendDisplay()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider colourProvider, IAPIProvider api)
{
InternalChild = new FillFlowContainer
{
@ -130,6 +140,9 @@ private void load(OverlayColourProvider colourProvider)
background.Colour = colourProvider.Background4;
controlBackground.Colour = colourProvider.Background5;
apiFriends.BindTo(api.Friends);
apiFriends.BindCollectionChanged((_, __) => Schedule(() => Users = apiFriends.ToList()), true);
}
protected override void LoadComplete()
@ -141,13 +154,6 @@ protected override void LoadComplete()
userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels());
}
protected override void PerformFetch()
{
base.PerformFetch();
Users = API.Friends.ToList();
}
private void recreatePanels()
{
if (!users.Any())