| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Text.RegularExpressions; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Social.Chat; |
| | 5 | | using DCL.Social.Chat; |
| | 6 | | using UIComponents.CollapsableSortedList; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | public class CollapsableChannelMemberListComponentView : CollapsableSortedListComponentView<string, ChannelMemberEntry> |
| | 10 | | { |
| | 11 | | private const string POOL_NAME_PREFIX = "ChannelMembersPool_"; |
| | 12 | |
|
| | 13 | | [SerializeField] private ChannelMemberEntry entryPrefab; |
| | 14 | | [SerializeField] private UserContextMenu userContextMenu; |
| | 15 | |
|
| 28 | 16 | | private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>(); |
| | 17 | | private Pool entryPool; |
| | 18 | |
|
| | 19 | | public void Filter(string search) |
| | 20 | | { |
| 0 | 21 | | if (!gameObject.activeInHierarchy) return; |
| 0 | 22 | | var regex = new Regex(search, RegexOptions.IgnoreCase); |
| 0 | 23 | | Filter(entry => regex.IsMatch(entry.Model.userName)); |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public void Clear() |
| | 27 | | { |
| 7 | 28 | | base.Clear(); |
| 7 | 29 | | pooleableEntries.Clear(); |
| 7 | 30 | | } |
| | 31 | |
|
| | 32 | | public override ChannelMemberEntry Remove(string key) |
| | 33 | | { |
| 2 | 34 | | if (pooleableEntries.ContainsKey(key)) |
| 2 | 35 | | pooleableEntries[key].Release(); |
| 2 | 36 | | pooleableEntries.Remove(key); |
| | 37 | |
|
| 2 | 38 | | return base.Remove(key); |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public void Set(string userId, ChannelMemberEntryModel entryModel) |
| | 42 | | { |
| 3 | 43 | | if (!Contains(entryModel.userId)) |
| 3 | 44 | | CreateEntry(userId); |
| | 45 | |
|
| 3 | 46 | | var entry = Get(userId); |
| 3 | 47 | | entry.Configure(entryModel); |
| 3 | 48 | | } |
| | 49 | |
|
| | 50 | | private void CreateEntry(string userId) |
| | 51 | | { |
| 3 | 52 | | entryPool = GetEntryPool(); |
| 3 | 53 | | var newFriendEntry = entryPool.Get(); |
| 3 | 54 | | pooleableEntries.Add(userId, newFriendEntry); |
| 3 | 55 | | var entry = newFriendEntry.gameObject.GetComponent<ChannelMemberEntry>(); |
| 3 | 56 | | entry.SetUserContextMenu(userContextMenu); |
| 3 | 57 | | Add(userId, entry); |
| 3 | 58 | | } |
| | 59 | |
|
| | 60 | | private Pool GetEntryPool() |
| | 61 | | { |
| 3 | 62 | | var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID()); |
| 3 | 63 | | if (entryPool != null) return entryPool; |
| | 64 | |
|
| 3 | 65 | | entryPool = PoolManager.i.AddPool( |
| | 66 | | POOL_NAME_PREFIX + name + GetInstanceID(), |
| | 67 | | Instantiate(entryPrefab).gameObject, |
| | 68 | | maxPrewarmCount: 20, |
| | 69 | | isPersistent: true); |
| 3 | 70 | | entryPool.ForcePrewarm(); |
| | 71 | |
|
| 3 | 72 | | return entryPool; |
| | 73 | | } |
| | 74 | | } |