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