| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UIComponents.CollapsableSortedList; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.MyAccount |
| | 7 | | { |
| | 8 | | public class CollapsableSortedBlockedEntryList : CollapsableSortedListComponentView<string, BlockedUserEntry> |
| | 9 | | { |
| | 10 | | private const string POOL_NAME_PREFIX = "BlockedEntryPool_"; |
| | 11 | | [SerializeField] private BlockedUserEntry entryPrefab; |
| | 12 | |
|
| | 13 | | private Pool entryPool; |
| 0 | 14 | | private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>(); |
| | 15 | |
|
| 0 | 16 | | public Action<string> OnUnblockUser { get; set; } |
| | 17 | |
|
| | 18 | | public void Clear() |
| | 19 | | { |
| 0 | 20 | | base.Clear(); |
| 0 | 21 | | pooleableEntries.Clear(); |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | public override BlockedUserEntry Remove(string key) |
| | 25 | | { |
| 0 | 26 | | if (pooleableEntries.ContainsKey(key)) |
| 0 | 27 | | pooleableEntries[key].Release(); |
| 0 | 28 | | pooleableEntries.Remove(key); |
| | 29 | |
|
| 0 | 30 | | return base.Remove(key); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public void Set(string userId, BlockedUserEntryModel entryModel) |
| | 34 | | { |
| 0 | 35 | | if (!Contains(entryModel.userId)) |
| 0 | 36 | | CreateEntry(userId); |
| | 37 | |
|
| 0 | 38 | | var entry = Get(userId); |
| 0 | 39 | | entry.Configure(entryModel); |
| 0 | 40 | | entry.SetButtonAction(OnUnblockUser); |
| 0 | 41 | | } |
| | 42 | |
|
| | 43 | | private void CreateEntry(string userId) |
| | 44 | | { |
| 0 | 45 | | entryPool = GetEntryPool(); |
| 0 | 46 | | var newFriendEntry = entryPool.Get(); |
| 0 | 47 | | pooleableEntries.Add(userId, newFriendEntry); |
| 0 | 48 | | var entry = newFriendEntry.gameObject.GetComponent<BlockedUserEntry>(); |
| 0 | 49 | | Add(userId, entry); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | private Pool GetEntryPool() |
| | 53 | | { |
| 0 | 54 | | var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID()); |
| 0 | 55 | | if (entryPool != null) return entryPool; |
| | 56 | |
|
| 0 | 57 | | entryPool = PoolManager.i.AddPool( |
| | 58 | | POOL_NAME_PREFIX + name + GetInstanceID(), |
| | 59 | | Instantiate(entryPrefab).gameObject, |
| | 60 | | maxPrewarmCount: 20, |
| | 61 | | isPersistent: true); |
| 0 | 62 | | entryPool.ForcePrewarm(); |
| | 63 | |
|
| 0 | 64 | | return entryPool; |
| | 65 | | } |
| | 66 | | } |
| | 67 | | } |