From 8d30c35104378baee846b75c338313291543c724 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 27 Aug 2019 03:10:58 +0300 Subject: [PATCH 01/17] Implement sorting --- osu.Game/Overlays/SocialOverlay.cs | 65 +++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 4def249200..dc63b0ab9a 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -16,6 +16,7 @@ using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.Social; using osu.Game.Users; using osu.Framework.Threading; +using System; namespace osu.Game.Overlays { @@ -71,7 +72,7 @@ namespace osu.Game.Overlays Filter.Tabs.Current.ValueChanged += _ => queueUpdate(); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue); - Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => queueUpdate(); + Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => onDropdownChanged(); currentQuery.BindTo(Filter.Search.Current); currentQuery.ValueChanged += query => @@ -175,11 +176,71 @@ namespace osu.Game.Overlays private void updateUsers(IEnumerable newUsers) { - Users = newUsers; + var sortDirection = Filter.DisplayStyleControl.Dropdown.Current.Value; + + IEnumerable sortedUsers = newUsers; + + switch (Filter.Tabs.Current.Value) + { + case SocialSortCriteria.Location: + switch (sortDirection) + { + case SortDirection.Ascending: + sortedUsers = newUsers.OrderBy(u => u.Country.FullName); + break; + + case SortDirection.Descending: + sortedUsers = newUsers.OrderByDescending(u => u.Country.FullName); + break; + } + break; + + case SocialSortCriteria.Name: + switch (sortDirection) + { + case SortDirection.Ascending: + sortedUsers = newUsers.OrderBy(u => u.Username); + break; + + case SortDirection.Descending: + sortedUsers = newUsers.OrderByDescending(u => u.Username); + break; + } + break; + + case SocialSortCriteria.Rank: + if (newUsers.FirstOrDefault().Statistics != null) + { + switch (sortDirection) + { + case SortDirection.Ascending: + sortedUsers = newUsers.OrderBy(u => u.Statistics?.Ranks.Global); + break; + + case SortDirection.Descending: + sortedUsers = newUsers.OrderByDescending(u => u.Statistics?.Ranks.Global); + break; + } + } + break; + } + + Users = sortedUsers; loading.Hide(); recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); } + private void onDropdownChanged() + { + if (Users == null) + { + queueUpdate(); + return; + } + + updateUsers(Users); + } + private void clearPanels() { if (panels != null) From cb81d1dd2fea0a174777044e7fdd8fa451f977f6 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 27 Aug 2019 03:53:16 +0300 Subject: [PATCH 02/17] Better use of loading animation --- osu.Game/Overlays/SocialOverlay.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index dc63b0ab9a..2202c473f6 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -103,7 +103,6 @@ namespace osu.Game.Overlays Users = null; clearPanels(); - loading.Hide(); getUsersRequest?.Cancel(); if (API?.IsLoggedIn != true) @@ -131,8 +130,13 @@ namespace osu.Game.Overlays { clearPanels(); + loading.Show(); + if (Users == null) + { + loading.Hide(); return; + } var newPanels = new FillFlowContainer { @@ -167,15 +171,15 @@ namespace osu.Game.Overlays LoadComponentAsync(newPanels, f => { - if (panels != null) - ScrollFlow.Remove(panels); - + loading.Hide(); ScrollFlow.Add(panels = newPanels); }); } private void updateUsers(IEnumerable newUsers) { + loading.Show(); + var sortDirection = Filter.DisplayStyleControl.Dropdown.Current.Value; IEnumerable sortedUsers = newUsers; @@ -226,7 +230,6 @@ namespace osu.Game.Overlays } Users = sortedUsers; - loading.Hide(); recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); } From 7cc6494482c7ba413012c5aa527da25b1c66eb41 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 27 Aug 2019 03:54:49 +0300 Subject: [PATCH 03/17] Remove sorting by rank Since it isn't working for any case currently --- osu.Game/Overlays/SocialOverlay.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 2202c473f6..8353e2d683 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -211,22 +211,6 @@ namespace osu.Game.Overlays break; } break; - - case SocialSortCriteria.Rank: - if (newUsers.FirstOrDefault().Statistics != null) - { - switch (sortDirection) - { - case SortDirection.Ascending: - sortedUsers = newUsers.OrderBy(u => u.Statistics?.Ranks.Global); - break; - - case SortDirection.Descending: - sortedUsers = newUsers.OrderByDescending(u => u.Statistics?.Ranks.Global); - break; - } - } - break; } Users = sortedUsers; From 66b27875e06dedb156b76caacdedc213d6affb87 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 27 Aug 2019 04:00:22 +0300 Subject: [PATCH 04/17] Fix possible null exception --- osu.Game/Overlays/SocialOverlay.cs | 49 ++++++++++++++++-------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 8353e2d683..22d1471229 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -184,33 +184,36 @@ namespace osu.Game.Overlays IEnumerable sortedUsers = newUsers; - switch (Filter.Tabs.Current.Value) + if (sortedUsers.Any()) { - case SocialSortCriteria.Location: - switch (sortDirection) - { - case SortDirection.Ascending: - sortedUsers = newUsers.OrderBy(u => u.Country.FullName); - break; + switch (Filter.Tabs.Current.Value) + { + case SocialSortCriteria.Location: + switch (sortDirection) + { + case SortDirection.Ascending: + sortedUsers = sortedUsers.OrderBy(u => u.Country.FullName); + break; - case SortDirection.Descending: - sortedUsers = newUsers.OrderByDescending(u => u.Country.FullName); - break; - } - break; + case SortDirection.Descending: + sortedUsers = sortedUsers.OrderByDescending(u => u.Country.FullName); + break; + } + break; - case SocialSortCriteria.Name: - switch (sortDirection) - { - case SortDirection.Ascending: - sortedUsers = newUsers.OrderBy(u => u.Username); - break; + case SocialSortCriteria.Name: + switch (sortDirection) + { + case SortDirection.Ascending: + sortedUsers = sortedUsers.OrderBy(u => u.Username); + break; - case SortDirection.Descending: - sortedUsers = newUsers.OrderByDescending(u => u.Username); - break; - } - break; + case SortDirection.Descending: + sortedUsers = sortedUsers.OrderByDescending(u => u.Username); + break; + } + break; + } } Users = sortedUsers; From 385bc6f52988c3f8c9858b8525aeceb11e6b33fa Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 27 Aug 2019 04:11:22 +0300 Subject: [PATCH 05/17] Remove using and add blank lines --- osu.Game/Overlays/SocialOverlay.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 22d1471229..23185ed989 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -16,7 +16,6 @@ using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.Social; using osu.Game.Users; using osu.Framework.Threading; -using System; namespace osu.Game.Overlays { @@ -199,6 +198,7 @@ namespace osu.Game.Overlays sortedUsers = sortedUsers.OrderByDescending(u => u.Country.FullName); break; } + break; case SocialSortCriteria.Name: @@ -212,6 +212,7 @@ namespace osu.Game.Overlays sortedUsers = sortedUsers.OrderByDescending(u => u.Username); break; } + break; } } From 9223a1ba8a4ff25c82e719374e37a3f3f3a90f81 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 27 Aug 2019 05:03:47 +0300 Subject: [PATCH 06/17] Simplify sorting logic --- osu.Game/Overlays/SocialOverlay.cs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 23185ed989..e2179361b1 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -16,6 +16,7 @@ using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.Social; using osu.Game.Users; using osu.Framework.Threading; +using System; namespace osu.Game.Overlays { @@ -188,31 +189,11 @@ namespace osu.Game.Overlays switch (Filter.Tabs.Current.Value) { case SocialSortCriteria.Location: - switch (sortDirection) - { - case SortDirection.Ascending: - sortedUsers = sortedUsers.OrderBy(u => u.Country.FullName); - break; - - case SortDirection.Descending: - sortedUsers = sortedUsers.OrderByDescending(u => u.Country.FullName); - break; - } - + sortedUsers = sortBy(sortedUsers, u => u.Country.FullName, sortDirection); break; case SocialSortCriteria.Name: - switch (sortDirection) - { - case SortDirection.Ascending: - sortedUsers = sortedUsers.OrderBy(u => u.Username); - break; - - case SortDirection.Descending: - sortedUsers = sortedUsers.OrderByDescending(u => u.Username); - break; - } - + sortedUsers = sortBy(sortedUsers, u => u.Username, sortDirection); break; } } @@ -221,6 +202,9 @@ namespace osu.Game.Overlays recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); } + private IEnumerable sortBy(IEnumerable users, Func condition, SortDirection sortDirection) => + sortDirection == SortDirection.Ascending ? users.OrderBy(condition) : users.OrderByDescending(condition); + private void onDropdownChanged() { if (Users == null) From 11df8c5576478f920f3c09e3b8c884623a0cb836 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 28 Aug 2019 01:02:26 +0300 Subject: [PATCH 07/17] Remove a lot of loading animation calls --- osu.Game/Overlays/SocialOverlay.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index e2179361b1..a467ae6dfa 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -122,16 +122,12 @@ namespace osu.Game.Overlays API.Queue(getUsersRequest = userRequest); break; } - - loading.Show(); } private void recreatePanels(PanelDisplayStyle displayStyle) { clearPanels(); - loading.Show(); - if (Users == null) { loading.Hide(); @@ -178,8 +174,6 @@ namespace osu.Game.Overlays private void updateUsers(IEnumerable newUsers) { - loading.Show(); - var sortDirection = Filter.DisplayStyleControl.Dropdown.Current.Value; IEnumerable sortedUsers = newUsers; @@ -218,6 +212,8 @@ namespace osu.Game.Overlays private void clearPanels() { + loading.Show(); + if (panels != null) { panels.Expire(); From 9b1e8cf48b701aad40f4a3b34a4d14205bc5bb77 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 28 Aug 2019 01:03:51 +0300 Subject: [PATCH 08/17] Use CancelDelayedTasks instead of private ScheduledDelegate --- osu.Game/Overlays/SocialOverlay.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index a467ae6dfa..5ed6a9a703 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -77,12 +77,12 @@ namespace osu.Game.Overlays currentQuery.BindTo(Filter.Search.Current); currentQuery.ValueChanged += query => { - queryChangedDebounce?.Cancel(); + Scheduler.CancelDelayedTasks(); if (string.IsNullOrEmpty(query.NewValue)) queueUpdate(); else - queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500); + Scheduler.AddDelayed(updateSearch, 500); }; } @@ -90,13 +90,11 @@ namespace osu.Game.Overlays private readonly Bindable currentQuery = new Bindable(); - private ScheduledDelegate queryChangedDebounce; - private void queueUpdate() => Scheduler.AddOnce(updateSearch); private void updateSearch() { - queryChangedDebounce?.Cancel(); + Scheduler.CancelDelayedTasks(); if (!IsLoaded) return; From 2d7024ffd92656a9d3646abc0e87111709e6bfe4 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 28 Aug 2019 01:14:35 +0300 Subject: [PATCH 09/17] Use CancellationTokenSource to avoid unwanted panels creation --- osu.Game/Overlays/SocialOverlay.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 5ed6a9a703..ee3adf65b9 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -17,6 +17,7 @@ using osu.Game.Overlays.Social; using osu.Game.Users; using osu.Framework.Threading; using System; +using System.Threading; namespace osu.Game.Overlays { @@ -92,6 +93,8 @@ namespace osu.Game.Overlays private void queueUpdate() => Scheduler.AddOnce(updateSearch); + private CancellationTokenSource loadCancellation; + private void updateSearch() { Scheduler.CancelDelayedTasks(); @@ -132,6 +135,8 @@ namespace osu.Game.Overlays return; } + loadCancellation = new CancellationTokenSource(); + var newPanels = new FillFlowContainer { RelativeSizeAxes = Axes.X, @@ -167,7 +172,7 @@ namespace osu.Game.Overlays { loading.Hide(); ScrollFlow.Add(panels = newPanels); - }); + }, loadCancellation.Token); } private void updateUsers(IEnumerable newUsers) @@ -212,6 +217,8 @@ namespace osu.Game.Overlays { loading.Show(); + loadCancellation?.Cancel(); + if (panels != null) { panels.Expire(); From 6aef05f5d877dfd29b2035cdcadb5f36aa706e3a Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 28 Aug 2019 01:16:55 +0300 Subject: [PATCH 10/17] Remove useless function --- osu.Game/Overlays/SocialOverlay.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index ee3adf65b9..97e1c2b5a4 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -73,7 +73,7 @@ namespace osu.Game.Overlays Filter.Tabs.Current.ValueChanged += _ => queueUpdate(); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue); - Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => onDropdownChanged(); + Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => updateUsers(Users); currentQuery.BindTo(Filter.Search.Current); currentQuery.ValueChanged += query => @@ -202,17 +202,6 @@ namespace osu.Game.Overlays private IEnumerable sortBy(IEnumerable users, Func condition, SortDirection sortDirection) => sortDirection == SortDirection.Ascending ? users.OrderBy(condition) : users.OrderByDescending(condition); - private void onDropdownChanged() - { - if (Users == null) - { - queueUpdate(); - return; - } - - updateUsers(Users); - } - private void clearPanels() { loading.Show(); From b6b4173a8481987f3afc73f90d3cc712e099f000 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 28 Aug 2019 01:27:16 +0300 Subject: [PATCH 11/17] Remove unused using --- osu.Game/Overlays/SocialOverlay.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 97e1c2b5a4..bf306f9569 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -15,7 +15,6 @@ using osu.Game.Online.API.Requests; using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.Social; using osu.Game.Users; -using osu.Framework.Threading; using System; using System.Threading; From 3227dc87fbac1c47fb505c4e66a66ac80a935678 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 6 Sep 2019 22:56:46 +0300 Subject: [PATCH 12/17] Don't use CancelDelayedTasks to avoid cancelling unwanted tasks --- osu.Game/Overlays/SocialOverlay.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index bf306f9569..1912a2c3e0 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -17,6 +17,7 @@ using osu.Game.Overlays.Social; using osu.Game.Users; using System; using System.Threading; +using osu.Framework.Threading; namespace osu.Game.Overlays { @@ -77,12 +78,12 @@ namespace osu.Game.Overlays currentQuery.BindTo(Filter.Search.Current); currentQuery.ValueChanged += query => { - Scheduler.CancelDelayedTasks(); + queryChangedDebounce?.Cancel(); if (string.IsNullOrEmpty(query.NewValue)) queueUpdate(); else - Scheduler.AddDelayed(updateSearch, 500); + queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500); }; } @@ -90,13 +91,15 @@ namespace osu.Game.Overlays private readonly Bindable currentQuery = new Bindable(); + private ScheduledDelegate queryChangedDebounce; + private void queueUpdate() => Scheduler.AddOnce(updateSearch); private CancellationTokenSource loadCancellation; private void updateSearch() { - Scheduler.CancelDelayedTasks(); + queryChangedDebounce?.Cancel(); if (!IsLoaded) return; @@ -169,6 +172,9 @@ namespace osu.Game.Overlays LoadComponentAsync(newPanels, f => { + if (panels != null) + ScrollFlow.Remove(panels); + loading.Hide(); ScrollFlow.Add(panels = newPanels); }, loadCancellation.Token); From 44412f9ddb0407318c7b9603484f806ef717266e Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 19 Sep 2019 03:35:56 +0300 Subject: [PATCH 13/17] Fix local sorting calls an online request --- osu.Game/Overlays/SocialOverlay.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 1912a2c3e0..7fd9ef153e 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -70,7 +70,7 @@ namespace osu.Game.Overlays Header.Tabs.Current.ValueChanged += _ => queueUpdate(); - Filter.Tabs.Current.ValueChanged += _ => queueUpdate(); + Filter.Tabs.Current.ValueChanged += _ => onFilterUpdate(); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue); Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => updateUsers(Users); @@ -180,6 +180,17 @@ namespace osu.Game.Overlays }, loadCancellation.Token); } + private void onFilterUpdate() + { + if (Users == null || Filter.Tabs.Current.Value == SocialSortCriteria.Rank) + { + queueUpdate(); + return; + } + + updateUsers(Users); + } + private void updateUsers(IEnumerable newUsers) { var sortDirection = Filter.DisplayStyleControl.Dropdown.Current.Value; From 647433a8d1c21187d86f656571d0abe8b5a0423f Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 19 Sep 2019 04:09:14 +0300 Subject: [PATCH 14/17] Don't trigger request if there are no avaliable users --- osu.Game/Overlays/SocialOverlay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 7fd9ef153e..a77172c90c 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -182,7 +182,7 @@ namespace osu.Game.Overlays private void onFilterUpdate() { - if (Users == null || Filter.Tabs.Current.Value == SocialSortCriteria.Rank) + if (Filter.Tabs.Current.Value == SocialSortCriteria.Rank) { queueUpdate(); return; From 007e2e80c1cd193e9e7a1ded3df6191571bed8a3 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 19 Dec 2019 02:02:57 +0900 Subject: [PATCH 15/17] Refactor to fix sorting issues --- osu.Game/Overlays/SocialOverlay.cs | 70 +++++++++++++----------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 5b3acf8e46..01dd1ee635 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; @@ -15,7 +16,6 @@ using osu.Game.Online.API.Requests; using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.Social; using osu.Game.Users; -using System; using System.Threading; using osu.Framework.Threading; @@ -33,17 +33,18 @@ namespace osu.Game.Overlays protected override SearchableListHeader CreateHeader() => new Header(); protected override SearchableListFilterControl CreateFilterControl() => new FilterControl(); - private IEnumerable users; + private User[] users = Array.Empty(); - public IEnumerable Users + public User[] Users { get => users; set { - if (ReferenceEquals(users, value)) + if (users == value) return; - users = value?.ToList(); + users = value ?? Array.Empty(); + recreatePanels(); } } @@ -72,8 +73,8 @@ namespace osu.Game.Overlays Filter.Tabs.Current.ValueChanged += _ => onFilterUpdate(); - Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue); - Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => updateUsers(Users); + Filter.DisplayStyleControl.DisplayStyle.ValueChanged += _ => recreatePanels(); + Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => recreatePanels(); currentQuery.BindTo(Filter.Search.Current); currentQuery.ValueChanged += query => @@ -115,19 +116,19 @@ namespace osu.Game.Overlays { case SocialTab.Friends: var friendRequest = new GetFriendsRequest(); // TODO filter arguments? - friendRequest.Success += updateUsers; + friendRequest.Success += users => Users = users.ToArray(); API.Queue(getUsersRequest = friendRequest); break; default: var userRequest = new GetUsersRequest(); // TODO filter arguments! - userRequest.Success += res => updateUsers(res.Users.Select(r => r.User)); + userRequest.Success += res => Users = res.Users.Select(r => r.User).ToArray(); API.Queue(getUsersRequest = userRequest); break; } } - private void recreatePanels(PanelDisplayStyle displayStyle) + private void recreatePanels() { clearPanels(); @@ -139,17 +140,33 @@ namespace osu.Game.Overlays loadCancellation = new CancellationTokenSource(); + IEnumerable sortedUsers = Users; + + switch (Filter.Tabs.Current.Value) + { + case SocialSortCriteria.Location: + sortedUsers = sortedUsers.OrderBy(u => u.Country.FullName); + break; + + case SocialSortCriteria.Name: + sortedUsers = sortedUsers.OrderBy(u => u.Username); + break; + } + + if (Filter.DisplayStyleControl.Dropdown.Current.Value == SortDirection.Descending) + sortedUsers = sortedUsers.Reverse(); + var newPanels = new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Spacing = new Vector2(10f), Margin = new MarginPadding { Top = 10 }, - ChildrenEnumerable = Users.Select(u => + ChildrenEnumerable = sortedUsers.Select(u => { SocialPanel panel; - switch (displayStyle) + switch (Filter.DisplayStyleControl.DisplayStyle.Value) { case PanelDisplayStyle.Grid: panel = new SocialGridPanel(u) @@ -188,36 +205,9 @@ namespace osu.Game.Overlays return; } - updateUsers(Users); + recreatePanels(); } - private void updateUsers(IEnumerable newUsers) - { - var sortDirection = Filter.DisplayStyleControl.Dropdown.Current.Value; - - IEnumerable sortedUsers = newUsers; - - if (sortedUsers.Any()) - { - switch (Filter.Tabs.Current.Value) - { - case SocialSortCriteria.Location: - sortedUsers = sortBy(sortedUsers, u => u.Country.FullName, sortDirection); - break; - - case SocialSortCriteria.Name: - sortedUsers = sortBy(sortedUsers, u => u.Username, sortDirection); - break; - } - } - - Users = sortedUsers; - recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); - } - - private IEnumerable sortBy(IEnumerable users, Func condition, SortDirection sortDirection) => - sortDirection == SortDirection.Ascending ? users.OrderBy(condition) : users.OrderByDescending(condition); - private void clearPanels() { loading.Show(); From dd68106d909d9deffb321a39536fbb35454bf05d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 19 Dec 2019 02:21:33 +0900 Subject: [PATCH 16/17] Recreate panels only while loading/loaded --- osu.Game/Overlays/SocialOverlay.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 01dd1ee635..7cc3b6e3ce 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -17,6 +17,7 @@ using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.Social; using osu.Game.Users; using System.Threading; +using osu.Framework.Allocation; using osu.Framework.Threading; namespace osu.Game.Overlays @@ -44,7 +45,9 @@ namespace osu.Game.Overlays return; users = value ?? Array.Empty(); - recreatePanels(); + + if (LoadState >= LoadState.Ready) + recreatePanels(); } } @@ -70,7 +73,6 @@ namespace osu.Game.Overlays }; Header.Tabs.Current.ValueChanged += _ => queueUpdate(); - Filter.Tabs.Current.ValueChanged += _ => onFilterUpdate(); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += _ => recreatePanels(); @@ -88,6 +90,12 @@ namespace osu.Game.Overlays }; } + [BackgroundDependencyLoader] + private void load() + { + recreatePanels(); + } + private APIRequest getUsersRequest; private readonly Bindable currentQuery = new Bindable(); From a46602f705c2686ad45a58ea2997bb715bb8265e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 19 Dec 2019 11:26:22 +0900 Subject: [PATCH 17/17] Move cancellation token construction closer to usage --- osu.Game/Overlays/SocialOverlay.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 7cc3b6e3ce..0c99962def 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -146,8 +146,6 @@ namespace osu.Game.Overlays return; } - loadCancellation = new CancellationTokenSource(); - IEnumerable sortedUsers = Users; switch (Filter.Tabs.Current.Value) @@ -202,7 +200,7 @@ namespace osu.Game.Overlays loading.Hide(); ScrollFlow.Add(panels = newPanels); - }, loadCancellation.Token); + }, (loadCancellation = new CancellationTokenSource()).Token); } private void onFilterUpdate()