| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using DCL; |
| | 6 | | using DCL.Helpers; |
| | 7 | | using DCl.Social.Friends; |
| | 8 | | using DCL.Social.Friends; |
| | 9 | | using SocialFeaturesAnalytics; |
| | 10 | | using TMPro; |
| | 11 | | using UnityEngine; |
| | 12 | | using UnityEngine.UI; |
| | 13 | |
|
| | 14 | | public class FriendsTabComponentView : BaseComponentView |
| | 15 | | { |
| | 16 | | private const int CREATION_AMOUNT_PER_FRAME = 5; |
| | 17 | | private const int AVATAR_SNAPSHOTS_PER_FRAME = 5; |
| | 18 | | private const int PRE_INSTANTIATED_ENTRIES = 25; |
| | 19 | | private const string FRIEND_ENTRIES_POOL_NAME_PREFIX = "FriendEntriesPool_"; |
| | 20 | | private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.005f; |
| | 21 | | private const float MIN_TIME_TO_REQUIRE_MORE_ENTRIES = 2f; |
| | 22 | |
|
| | 23 | | [SerializeField] private GameObject enabledHeader; |
| | 24 | | [SerializeField] private GameObject disabledHeader; |
| | 25 | | [SerializeField] private GameObject emptyStateContainer; |
| | 26 | | [SerializeField] private GameObject filledStateContainer; |
| | 27 | | [SerializeField] private FriendEntry entryPrefab; |
| | 28 | | [SerializeField] private FriendListComponents onlineFriendsList; |
| | 29 | | [SerializeField] private FriendListComponents offlineFriendsList; |
| | 30 | | [SerializeField] private FriendListComponents allFriendsList; |
| | 31 | | [SerializeField] private FriendListComponents searchResultsFriendList; |
| | 32 | | [SerializeField] private SearchBarComponentView searchBar; |
| | 33 | | [SerializeField] private UserContextMenu contextMenuPanel; |
| | 34 | | [SerializeField] private Model model; |
| | 35 | | [SerializeField] private RectTransform viewport; |
| | 36 | | [SerializeField] internal ScrollRect scroll; |
| | 37 | |
|
| | 38 | | [Header("Load More Entries")] [SerializeField] |
| | 39 | | internal GameObject loadMoreEntriesContainer; |
| | 40 | |
|
| | 41 | | [SerializeField] internal TMP_Text loadMoreEntriesLabel; |
| | 42 | | [SerializeField] internal GameObject loadMoreEntriesSpinner; |
| | 43 | |
|
| 2 | 44 | | private readonly Dictionary<string, FriendEntryModel> creationQueue = |
| | 45 | | new Dictionary<string, FriendEntryModel>(); |
| | 46 | |
|
| 2 | 47 | | private readonly Dictionary<string, PoolableObject> pooledEntries = new Dictionary<string, PoolableObject>(); |
| 2 | 48 | | private readonly Dictionary<string, PoolableObject> searchPooledEntries = new Dictionary<string, PoolableObject>(); |
| | 49 | | private Pool entryPool; |
| | 50 | | private bool isLayoutDirty; |
| | 51 | | private IChatController chatController; |
| | 52 | | private IFriendsController friendsController; |
| | 53 | | private ISocialAnalytics socialAnalytics; |
| | 54 | | private bool isSearchMode; |
| 2 | 55 | | private Vector2 lastScrollPosition = Vector2.one; |
| | 56 | | private Coroutine requireMoreEntriesRoutine; |
| | 57 | | private float loadMoreEntriesRestrictionTime; |
| | 58 | |
|
| 1 | 59 | | public int Count => onlineFriendsList.list.Count() |
| | 60 | | + offlineFriendsList.list.Count() |
| | 61 | | + creationQueue.Keys.Count(s => |
| 0 | 62 | | !onlineFriendsList.list.Contains(s) && !offlineFriendsList.list.Contains(s)); |
| | 63 | |
|
| | 64 | | public event Action<string> OnSearchRequested; |
| | 65 | |
|
| | 66 | | public event Action<FriendEntryModel> OnWhisper; |
| | 67 | | public event Action OnRequireMoreEntries; |
| | 68 | |
|
| | 69 | | public void Initialize(IChatController chatController, |
| | 70 | | IFriendsController friendsController, |
| | 71 | | ISocialAnalytics socialAnalytics) |
| | 72 | | { |
| 1 | 73 | | this.chatController = chatController; |
| 1 | 74 | | this.friendsController = friendsController; |
| 1 | 75 | | this.socialAnalytics = socialAnalytics; |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | public override void OnEnable() |
| | 79 | | { |
| 1 | 80 | | base.OnEnable(); |
| | 81 | |
|
| 1 | 82 | | searchBar.Configure(new SearchBarComponentModel {placeHolderText = "Search friend"}); |
| 1 | 83 | | searchBar.OnSearchText += HandleSearchInputChanged; |
| 1 | 84 | | contextMenuPanel.OnBlock += HandleFriendBlockRequest; |
| 1 | 85 | | contextMenuPanel.OnUnfriend += HandleUnfriendRequest; |
| 1 | 86 | | scroll.onValueChanged.AddListener(RequestMoreEntries); |
| | 87 | |
|
| | 88 | | int SortByAlphabeticalOrder(FriendEntryBase u1, FriendEntryBase u2) |
| | 89 | | { |
| 0 | 90 | | return string.Compare(u1.Model.userName, u2.Model.userName, StringComparison.InvariantCultureIgnoreCase); |
| | 91 | | } |
| | 92 | |
|
| 1 | 93 | | onlineFriendsList.list.SortingMethod = SortByAlphabeticalOrder; |
| 1 | 94 | | offlineFriendsList.list.SortingMethod = SortByAlphabeticalOrder; |
| 1 | 95 | | searchResultsFriendList.list.SortingMethod = SortByAlphabeticalOrder; |
| 1 | 96 | | UpdateLayout(); |
| 1 | 97 | | UpdateEmptyOrFilledState(); |
| | 98 | |
|
| | 99 | | //TODO temporary, remove this and allFriendsList gameobjects later |
| 1 | 100 | | allFriendsList.list.gameObject.SetActive(false); |
| 1 | 101 | | allFriendsList.headerContainer.gameObject.SetActive(false); |
| 1 | 102 | | } |
| | 103 | |
|
| | 104 | | public override void OnDisable() |
| | 105 | | { |
| 1 | 106 | | base.OnDisable(); |
| | 107 | |
|
| 1 | 108 | | searchBar.OnSearchText -= HandleSearchInputChanged; |
| 1 | 109 | | contextMenuPanel.OnBlock -= HandleFriendBlockRequest; |
| 1 | 110 | | contextMenuPanel.OnUnfriend -= HandleUnfriendRequest; |
| 1 | 111 | | scroll.onValueChanged.RemoveListener(RequestMoreEntries); |
| 1 | 112 | | } |
| | 113 | |
|
| | 114 | | public void Show() |
| | 115 | | { |
| 0 | 116 | | gameObject.SetActive(true); |
| 0 | 117 | | enabledHeader.SetActive(true); |
| 0 | 118 | | disabledHeader.SetActive(false); |
| 0 | 119 | | searchBar.ClearSearch(); |
| 0 | 120 | | } |
| | 121 | |
|
| | 122 | | public void Hide() |
| | 123 | | { |
| 0 | 124 | | gameObject.SetActive(false); |
| 0 | 125 | | enabledHeader.SetActive(false); |
| 0 | 126 | | disabledHeader.SetActive(true); |
| 0 | 127 | | contextMenuPanel.Hide(); |
| 0 | 128 | | } |
| | 129 | |
|
| | 130 | | public void Update() |
| | 131 | | { |
| 126 | 132 | | if (isLayoutDirty) |
| 1 | 133 | | Utils.ForceRebuildLayoutImmediate((RectTransform) filledStateContainer.transform); |
| 126 | 134 | | isLayoutDirty = false; |
| | 135 | |
|
| 126 | 136 | | SortDirtyLists(); |
| 126 | 137 | | FetchProfilePicturesForVisibleEntries(); |
| 126 | 138 | | SetQueuedEntries(); |
| 126 | 139 | | } |
| | 140 | |
|
| | 141 | | public void Clear() |
| | 142 | | { |
| 1 | 143 | | HideMoreFriendsLoadingSpinner(); |
| 1 | 144 | | loadMoreEntriesRestrictionTime = Time.realtimeSinceStartup; |
| 1 | 145 | | scroll.verticalNormalizedPosition = 1f; |
| 1 | 146 | | creationQueue.Clear(); |
| | 147 | |
|
| 1 | 148 | | searchResultsFriendList.list.Clear(); |
| | 149 | |
|
| 1 | 150 | | ClearSearchResults(); |
| 1 | 151 | | ClearOnlineAndOfflineFriends(); |
| | 152 | |
|
| 1 | 153 | | UpdateEmptyOrFilledState(); |
| 1 | 154 | | UpdateCounterLabel(); |
| 1 | 155 | | } |
| | 156 | |
|
| | 157 | | public void Remove(string userId) |
| | 158 | | { |
| 0 | 159 | | if (creationQueue.ContainsKey(userId)) |
| 0 | 160 | | creationQueue.Remove(userId); |
| | 161 | |
|
| 0 | 162 | | if (pooledEntries.TryGetValue(userId, out var pooledObject)) |
| | 163 | | { |
| 0 | 164 | | entryPool.Release(pooledObject); |
| 0 | 165 | | pooledEntries.Remove(userId); |
| | 166 | | } |
| | 167 | |
|
| 0 | 168 | | if (searchPooledEntries.TryGetValue(userId, out var searchPooledObject)) |
| | 169 | | { |
| 0 | 170 | | entryPool.Release(searchPooledObject); |
| 0 | 171 | | searchPooledEntries.Remove(userId); |
| | 172 | | } |
| | 173 | |
|
| 0 | 174 | | offlineFriendsList.list.Remove(userId); |
| 0 | 175 | | onlineFriendsList.list.Remove(userId); |
| 0 | 176 | | searchResultsFriendList.list.Remove(userId); |
| | 177 | |
|
| 0 | 178 | | UpdateEmptyOrFilledState(); |
| 0 | 179 | | UpdateCounterLabel(); |
| 0 | 180 | | UpdateLayout(); |
| 0 | 181 | | } |
| | 182 | |
|
| | 183 | | public FriendEntry Get(string userId) |
| | 184 | | { |
| 0 | 185 | | return (onlineFriendsList.list.Get(userId) |
| | 186 | | ?? offlineFriendsList.list.Get(userId) |
| | 187 | | ?? searchResultsFriendList.list.Get(userId)) as FriendEntry; |
| | 188 | | } |
| | 189 | |
|
| | 190 | | private void Populate(string userId, FriendEntryModel model, FriendEntryBase entry) |
| | 191 | | { |
| 0 | 192 | | entry.Populate(model); |
| | 193 | |
|
| 0 | 194 | | if (isSearchMode) |
| | 195 | | { |
| 0 | 196 | | searchResultsFriendList.list.Remove(userId); |
| 0 | 197 | | searchResultsFriendList.list.Add(userId, entry); |
| 0 | 198 | | searchResultsFriendList.FlagAsPendingToSort(); |
| 0 | 199 | | searchResultsFriendList.list.Filter(searchBar.Text); |
| | 200 | | } |
| | 201 | | else |
| | 202 | | { |
| 0 | 203 | | if (model.status == PresenceStatus.ONLINE) |
| | 204 | | { |
| 0 | 205 | | offlineFriendsList.list.Remove(userId); |
| 0 | 206 | | onlineFriendsList.list.Add(userId, entry); |
| 0 | 207 | | onlineFriendsList.FlagAsPendingToSort(); |
| | 208 | | } |
| | 209 | | else |
| | 210 | | { |
| 0 | 211 | | onlineFriendsList.list.Remove(userId); |
| 0 | 212 | | offlineFriendsList.list.Add(userId, entry); |
| 0 | 213 | | offlineFriendsList.FlagAsPendingToSort(); |
| | 214 | | } |
| | 215 | | } |
| | 216 | |
|
| 0 | 217 | | UpdateLayout(); |
| 0 | 218 | | UpdateEmptyOrFilledState(); |
| 0 | 219 | | UpdateCounterLabel(); |
| 0 | 220 | | } |
| | 221 | |
|
| | 222 | | private void Set(string userId, FriendEntryModel model) |
| | 223 | | { |
| 0 | 224 | | if (creationQueue.ContainsKey(userId)) |
| | 225 | | { |
| 0 | 226 | | creationQueue[userId] = model; |
| 0 | 227 | | return; |
| | 228 | | } |
| | 229 | |
|
| | 230 | | FriendEntryBase entry; |
| | 231 | |
|
| 0 | 232 | | if (isSearchMode) |
| | 233 | | { |
| 0 | 234 | | if (!searchResultsFriendList.list.Contains(userId)) |
| 0 | 235 | | entry = CreateEntry(userId, searchPooledEntries); |
| | 236 | | else |
| 0 | 237 | | entry = searchResultsFriendList.list.Get(userId); |
| | 238 | | } |
| | 239 | | else |
| | 240 | | { |
| 0 | 241 | | if (!onlineFriendsList.list.Contains(userId) |
| | 242 | | && !offlineFriendsList.list.Contains(userId)) |
| 0 | 243 | | entry = CreateEntry(userId, pooledEntries); |
| | 244 | | else |
| 0 | 245 | | entry = onlineFriendsList.list.Get(userId) ?? offlineFriendsList.list.Get(userId); |
| | 246 | | } |
| | 247 | |
|
| 0 | 248 | | Populate(userId, model, entry); |
| 0 | 249 | | } |
| | 250 | |
|
| | 251 | | public override void RefreshControl() |
| | 252 | | { |
| 1 | 253 | | onlineFriendsList.Show(); |
| 1 | 254 | | offlineFriendsList.Show(); |
| | 255 | |
|
| 1 | 256 | | if (model.isOnlineFriendsExpanded) |
| 1 | 257 | | onlineFriendsList.list.Expand(); |
| | 258 | | else |
| 0 | 259 | | onlineFriendsList.list.Collapse(); |
| | 260 | |
|
| 1 | 261 | | if (model.isOfflineFriendsExpanded) |
| 1 | 262 | | offlineFriendsList.list.Expand(); |
| | 263 | | else |
| 0 | 264 | | offlineFriendsList.list.Collapse(); |
| 0 | 265 | | } |
| | 266 | |
|
| | 267 | | public void DisableSearchMode() |
| | 268 | | { |
| 0 | 269 | | isSearchMode = false; |
| | 270 | |
|
| 0 | 271 | | ClearSearchResults(); |
| | 272 | |
|
| 0 | 273 | | searchBar.ClearSearch(false); |
| 0 | 274 | | searchResultsFriendList.list.Clear(); |
| 0 | 275 | | searchResultsFriendList.Hide(); |
| 0 | 276 | | offlineFriendsList.Show(); |
| 0 | 277 | | onlineFriendsList.Show(); |
| 0 | 278 | | } |
| | 279 | |
|
| | 280 | | public void EnableSearchMode() |
| | 281 | | { |
| 0 | 282 | | isSearchMode = true; |
| | 283 | |
|
| 0 | 284 | | ClearSearchResults(); |
| | 285 | |
|
| 0 | 286 | | offlineFriendsList.Hide(); |
| 0 | 287 | | onlineFriendsList.Hide(); |
| 0 | 288 | | searchResultsFriendList.Show(); |
| | 289 | |
|
| 0 | 290 | | UpdateCounterLabel(); |
| 0 | 291 | | HideMoreFriendsToLoadHint(); |
| 0 | 292 | | UpdateLayout(); |
| 0 | 293 | | } |
| | 294 | |
|
| 0 | 295 | | public void Enqueue(string userId, FriendEntryModel model) => creationQueue[userId] = model; |
| | 296 | |
|
| | 297 | | public void HideMoreFriendsToLoadHint() |
| | 298 | | { |
| 1 | 299 | | loadMoreEntriesContainer.SetActive(false); |
| 1 | 300 | | UpdateLayout(); |
| 1 | 301 | | } |
| | 302 | |
|
| | 303 | | public void ShowMoreFriendsToLoadHint(int hiddenCount) |
| | 304 | | { |
| 0 | 305 | | loadMoreEntriesLabel.text = |
| | 306 | | $"{hiddenCount} friends hidden. Use the search bar to find them or scroll down to show more."; |
| 0 | 307 | | loadMoreEntriesContainer.SetActive(true); |
| 0 | 308 | | UpdateLayout(); |
| 0 | 309 | | } |
| | 310 | |
|
| 0 | 311 | | private void ShowMoreFriendsLoadingSpinner() => loadMoreEntriesSpinner.SetActive(true); |
| | 312 | |
|
| 1 | 313 | | private void HideMoreFriendsLoadingSpinner() => loadMoreEntriesSpinner.SetActive(false); |
| | 314 | |
|
| 0 | 315 | | private void HandleSearchInputChanged(string search) => OnSearchRequested?.Invoke(search); |
| | 316 | |
|
| | 317 | | private void SetQueuedEntries() |
| | 318 | | { |
| 252 | 319 | | if (creationQueue.Count == 0) return; |
| | 320 | |
|
| 0 | 321 | | for (var i = 0; i < CREATION_AMOUNT_PER_FRAME && creationQueue.Count != 0; i++) |
| | 322 | | { |
| 0 | 323 | | var pair = creationQueue.FirstOrDefault(); |
| 0 | 324 | | creationQueue.Remove(pair.Key); |
| 0 | 325 | | Set(pair.Key, pair.Value); |
| | 326 | | } |
| | 327 | |
|
| 0 | 328 | | HideMoreFriendsLoadingSpinner(); |
| 0 | 329 | | } |
| | 330 | |
|
| | 331 | | private void FetchProfilePicturesForVisibleEntries() |
| | 332 | | { |
| 126 | 333 | | FetchProfilePicturesForVisibleEntries(onlineFriendsList); |
| 126 | 334 | | FetchProfilePicturesForVisibleEntries(offlineFriendsList); |
| 126 | 335 | | FetchProfilePicturesForVisibleEntries(searchResultsFriendList); |
| 126 | 336 | | } |
| | 337 | |
|
| | 338 | | private void FetchProfilePicturesForVisibleEntries(FriendListComponents friendListComponents) |
| | 339 | | { |
| 756 | 340 | | foreach (var entry in friendListComponents.list.Entries.Values |
| | 341 | | .Skip(friendListComponents.currentAvatarSnapshotIndex) |
| | 342 | | .Take(AVATAR_SNAPSHOTS_PER_FRAME)) |
| | 343 | | { |
| 0 | 344 | | if (entry.IsVisible(viewport)) |
| 0 | 345 | | entry.EnableAvatarSnapshotFetching(); |
| | 346 | | else |
| 0 | 347 | | entry.DisableAvatarSnapshotFetching(); |
| | 348 | | } |
| | 349 | |
|
| 378 | 350 | | friendListComponents.currentAvatarSnapshotIndex += AVATAR_SNAPSHOTS_PER_FRAME; |
| | 351 | |
|
| 378 | 352 | | if (friendListComponents.currentAvatarSnapshotIndex >= friendListComponents.list.Count()) |
| 378 | 353 | | friendListComponents.currentAvatarSnapshotIndex = 0; |
| 378 | 354 | | } |
| | 355 | |
|
| | 356 | | private void UpdateEmptyOrFilledState() |
| | 357 | | { |
| 2 | 358 | | var totalFriends = onlineFriendsList.list.Count() + offlineFriendsList.list.Count(); |
| 2 | 359 | | emptyStateContainer.SetActive(totalFriends == 0); |
| 2 | 360 | | filledStateContainer.SetActive(totalFriends > 0); |
| 2 | 361 | | } |
| | 362 | |
|
| | 363 | | private FriendEntry CreateEntry(string userId, Dictionary<string, PoolableObject> poolableObjects) |
| | 364 | | { |
| 0 | 365 | | entryPool = GetEntryPool(); |
| 0 | 366 | | var newFriendEntry = entryPool.Get(); |
| 0 | 367 | | poolableObjects.Add(userId, newFriendEntry); |
| 0 | 368 | | var entry = newFriendEntry.gameObject.GetComponent<FriendEntry>(); |
| 0 | 369 | | entry.Initialize(chatController, friendsController, socialAnalytics); |
| | 370 | |
|
| 0 | 371 | | entry.OnMenuToggle -= OnEntryMenuToggle; |
| 0 | 372 | | entry.OnMenuToggle += OnEntryMenuToggle; |
| 0 | 373 | | entry.OnWhisperClick -= OnEntryWhisperClick; |
| 0 | 374 | | entry.OnWhisperClick += OnEntryWhisperClick; |
| | 375 | |
|
| 0 | 376 | | return entry; |
| | 377 | | } |
| | 378 | |
|
| 0 | 379 | | private void OnEntryWhisperClick(FriendEntry friendEntry) => OnWhisper?.Invoke(friendEntry.Model); |
| | 380 | |
|
| | 381 | | private void OnEntryMenuToggle(FriendEntryBase friendEntry) |
| | 382 | | { |
| 0 | 383 | | friendEntry.Dock(contextMenuPanel); |
| 0 | 384 | | contextMenuPanel.Show(friendEntry.Model.userId); |
| 0 | 385 | | } |
| | 386 | |
|
| | 387 | | private Pool GetEntryPool() |
| | 388 | | { |
| 0 | 389 | | var entryPool = PoolManager.i.GetPool(FRIEND_ENTRIES_POOL_NAME_PREFIX + name + GetInstanceID()); |
| 0 | 390 | | if (entryPool != null) return entryPool; |
| | 391 | |
|
| 0 | 392 | | entryPool = PoolManager.i.AddPool( |
| | 393 | | FRIEND_ENTRIES_POOL_NAME_PREFIX + name + GetInstanceID(), |
| | 394 | | Instantiate(entryPrefab).gameObject, |
| | 395 | | maxPrewarmCount: PRE_INSTANTIATED_ENTRIES, |
| | 396 | | isPersistent: true); |
| 0 | 397 | | entryPool.ForcePrewarm(); |
| | 398 | |
|
| 0 | 399 | | return entryPool; |
| | 400 | | } |
| | 401 | |
|
| | 402 | | private void UpdateCounterLabel() |
| | 403 | | { |
| 1 | 404 | | onlineFriendsList.countText.SetText("ONLINE ({0})", onlineFriendsList.list.Count()); |
| 1 | 405 | | offlineFriendsList.countText.SetText("OFFLINE ({0})", offlineFriendsList.list.Count()); |
| 1 | 406 | | searchResultsFriendList.countText.SetText("Results ({0})", searchResultsFriendList.list.Count()); |
| 1 | 407 | | } |
| | 408 | |
|
| | 409 | | private void HandleFriendBlockRequest(string userId, bool blockUser) |
| | 410 | | { |
| 0 | 411 | | var friendEntryToBlock = Get(userId); |
| 0 | 412 | | if (friendEntryToBlock == null) return; |
| | 413 | | // instantly refresh ui |
| 0 | 414 | | friendEntryToBlock.Model.blocked = blockUser; |
| 0 | 415 | | Set(userId, friendEntryToBlock.Model); |
| 0 | 416 | | } |
| | 417 | |
|
| | 418 | | private void HandleUnfriendRequest(string userId) |
| | 419 | | { |
| 0 | 420 | | var entry = Get(userId); |
| 0 | 421 | | if (entry == null) return; |
| 0 | 422 | | Remove(userId); |
| 0 | 423 | | } |
| | 424 | |
|
| 2 | 425 | | private void UpdateLayout() => isLayoutDirty = true; |
| | 426 | |
|
| | 427 | | private void SortDirtyLists() |
| | 428 | | { |
| 126 | 429 | | if (offlineFriendsList.IsSortingDirty) |
| 0 | 430 | | offlineFriendsList.Sort(); |
| 126 | 431 | | if (onlineFriendsList.IsSortingDirty) |
| 0 | 432 | | onlineFriendsList.Sort(); |
| | 433 | |
|
| 126 | 434 | | if (searchResultsFriendList.IsSortingDirty) |
| 0 | 435 | | searchResultsFriendList.Sort(); |
| 126 | 436 | | } |
| | 437 | |
|
| | 438 | | private void RequestMoreEntries(Vector2 position) |
| | 439 | | { |
| 1 | 440 | | if (!loadMoreEntriesContainer.activeInHierarchy || |
| | 441 | | loadMoreEntriesSpinner.activeInHierarchy || |
| 1 | 442 | | Time.realtimeSinceStartup - loadMoreEntriesRestrictionTime < MIN_TIME_TO_REQUIRE_MORE_ENTRIES) return; |
| | 443 | |
|
| 0 | 444 | | if (position.y < REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD && |
| | 445 | | lastScrollPosition.y >= REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD) |
| | 446 | | { |
| 0 | 447 | | if (requireMoreEntriesRoutine != null) |
| 0 | 448 | | StopCoroutine(requireMoreEntriesRoutine); |
| | 449 | |
|
| 0 | 450 | | ShowMoreFriendsLoadingSpinner(); |
| 0 | 451 | | requireMoreEntriesRoutine = StartCoroutine(WaitThenRequireMoreEntries()); |
| | 452 | |
|
| 0 | 453 | | loadMoreEntriesRestrictionTime = Time.realtimeSinceStartup; |
| | 454 | | } |
| | 455 | |
|
| 0 | 456 | | lastScrollPosition = position; |
| 0 | 457 | | } |
| | 458 | |
|
| | 459 | | private void ClearSearchResults() |
| | 460 | | { |
| 2 | 461 | | foreach (var pooledObj in searchPooledEntries.Values) |
| 0 | 462 | | entryPool.Release(pooledObj); |
| 1 | 463 | | searchPooledEntries.Clear(); |
| 1 | 464 | | searchResultsFriendList.list.Clear(); |
| 1 | 465 | | } |
| | 466 | |
|
| | 467 | | private void ClearOnlineAndOfflineFriends() |
| | 468 | | { |
| 2 | 469 | | foreach (var pooledObj in pooledEntries.Values) |
| 0 | 470 | | entryPool.Release(pooledObj); |
| | 471 | |
|
| 1 | 472 | | pooledEntries.Clear(); |
| 1 | 473 | | onlineFriendsList.list.Clear(); |
| 1 | 474 | | offlineFriendsList.list.Clear(); |
| 1 | 475 | | } |
| | 476 | |
|
| | 477 | | private IEnumerator WaitThenRequireMoreEntries() |
| | 478 | | { |
| 0 | 479 | | yield return new WaitForSeconds(1f); |
| 0 | 480 | | OnRequireMoreEntries?.Invoke(); |
| 0 | 481 | | } |
| | 482 | |
|
| | 483 | | [Serializable] |
| | 484 | | private class FriendListComponents |
| | 485 | | { |
| | 486 | | public CollapsableSortedFriendEntryList list; |
| | 487 | | public TMP_Text countText; |
| | 488 | | public GameObject headerContainer; |
| | 489 | | public int currentAvatarSnapshotIndex; |
| | 490 | |
|
| 378 | 491 | | public bool IsSortingDirty { get; private set; } |
| | 492 | |
|
| | 493 | | public void Show() |
| | 494 | | { |
| 2 | 495 | | list.Show(); |
| 2 | 496 | | headerContainer.SetActive(true); |
| 2 | 497 | | } |
| | 498 | |
|
| | 499 | | public void Hide() |
| | 500 | | { |
| 0 | 501 | | list.Hide(); |
| 0 | 502 | | headerContainer.SetActive(false); |
| 0 | 503 | | } |
| | 504 | |
|
| 0 | 505 | | public void FlagAsPendingToSort() => IsSortingDirty = true; |
| | 506 | |
|
| | 507 | | public void Sort() |
| | 508 | | { |
| 0 | 509 | | list.Sort(); |
| 0 | 510 | | IsSortingDirty = false; |
| 0 | 511 | | } |
| | 512 | | } |
| | 513 | |
|
| | 514 | | [Serializable] |
| | 515 | | private class Model |
| | 516 | | { |
| | 517 | | public bool isOnlineFriendsExpanded; |
| | 518 | | public bool isOfflineFriendsExpanded; |
| | 519 | | } |
| | 520 | | } |