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