| | 1 | | using SocialFeaturesAnalytics; |
| | 2 | | using System; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Social.Friends |
| | 7 | | { |
| | 8 | | public class FriendsHUDComponentView : BaseComponentView, IFriendsHUDComponentView |
| | 9 | | { |
| | 10 | | private const int FRIENDS_LIST_TAB_INDEX = 0; |
| | 11 | | private const int FRIENDS_REQUEST_TAB_INDEX = 1; |
| | 12 | |
|
| | 13 | | [SerializeField] internal GameObject loadingSpinner; |
| | 14 | | [SerializeField] internal Button closeButton; |
| | 15 | | [SerializeField] internal Button friendsTabFocusButton; |
| | 16 | | [SerializeField] internal Button friendRequestsTabFocusButton; |
| | 17 | | [SerializeField] internal FriendsTabComponentView friendsTab; |
| | 18 | | [SerializeField] internal FriendRequestsTabComponentView friendRequestsTab; |
| | 19 | | [SerializeField] private Model model; |
| | 20 | |
|
| | 21 | | public event Action<FriendRequestEntryModel> OnFriendRequestApproved |
| | 22 | | { |
| 1 | 23 | | add => friendRequestsTab.OnFriendRequestApproved += value; |
| 1 | 24 | | remove => friendRequestsTab.OnFriendRequestApproved -= value; |
| | 25 | | } |
| | 26 | |
|
| | 27 | | public event Action<FriendRequestEntryModel> OnCancelConfirmation |
| | 28 | | { |
| 1 | 29 | | add => friendRequestsTab.OnCancelConfirmation += value; |
| 1 | 30 | | remove => friendRequestsTab.OnCancelConfirmation -= value; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public event Action<FriendRequestEntryModel> OnRejectConfirmation |
| | 34 | | { |
| 1 | 35 | | add => friendRequestsTab.OnRejectConfirmation += value; |
| 1 | 36 | | remove => friendRequestsTab.OnRejectConfirmation -= value; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | public event Action<string> OnFriendRequestSent |
| | 40 | | { |
| 1 | 41 | | add => friendRequestsTab.OnFriendRequestSent += value; |
| 1 | 42 | | remove => friendRequestsTab.OnFriendRequestSent -= value; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | public event Action<string> OnFriendRequestOpened |
| | 46 | | { |
| 1 | 47 | | add => friendRequestsTab.OnFriendRequestOpened += value; |
| 1 | 48 | | remove => friendRequestsTab.OnFriendRequestOpened -= value; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public event Action<FriendEntryModel> OnWhisper |
| | 52 | | { |
| 1 | 53 | | add => friendsTab.OnWhisper += value; |
| 1 | 54 | | remove => friendsTab.OnWhisper -= value; |
| | 55 | | } |
| | 56 | |
|
| | 57 | | public event Action OnRequireMoreFriends |
| | 58 | | { |
| 1 | 59 | | add => friendsTab.OnRequireMoreEntries += value; |
| 1 | 60 | | remove => friendsTab.OnRequireMoreEntries -= value; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | public event Action OnRequireMoreFriendRequests |
| | 64 | | { |
| 1 | 65 | | add => friendRequestsTab.OnRequireMoreEntries += value; |
| 1 | 66 | | remove => friendRequestsTab.OnRequireMoreEntries -= value; |
| | 67 | | } |
| | 68 | |
|
| | 69 | | public event Action<string> OnSearchFriendsRequested |
| | 70 | | { |
| 1 | 71 | | add => friendsTab.OnSearchRequested += value; |
| 1 | 72 | | remove => friendsTab.OnSearchRequested -= value; |
| | 73 | | } |
| | 74 | |
|
| | 75 | | public event Action OnFriendListDisplayed; |
| | 76 | | public event Action OnRequestListDisplayed; |
| | 77 | |
|
| | 78 | | public event Action OnClose; |
| | 79 | |
|
| 2 | 80 | | public RectTransform Transform => transform as RectTransform; |
| | 81 | |
|
| 1 | 82 | | public int FriendCount => friendsTab.Count; |
| 0 | 83 | | public int FriendRequestCount => friendRequestsTab.Count; |
| 0 | 84 | | public int FriendRequestSentCount => friendRequestsTab.SentCount; |
| 0 | 85 | | public int FriendRequestReceivedCount => friendRequestsTab.ReceivedCount; |
| 1 | 86 | | public bool IsFriendListActive => friendsTab.gameObject.activeInHierarchy; |
| 0 | 87 | | public bool IsRequestListActive => friendRequestsTab.gameObject.activeInHierarchy; |
| | 88 | |
|
| | 89 | | public void Initialize(IChatController chatController, |
| | 90 | | IFriendsController friendsController, |
| | 91 | | ISocialAnalytics socialAnalytics) |
| | 92 | | { |
| 1 | 93 | | friendsTab.Initialize(chatController, friendsController, socialAnalytics); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | public void RefreshFriendsTab() |
| | 97 | | { |
| 1 | 98 | | friendsTab.RefreshControl(); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | public override void Awake() |
| | 102 | | { |
| 1 | 103 | | base.Awake(); |
| | 104 | |
|
| 1 | 105 | | friendsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_LIST_TAB_INDEX)); |
| 1 | 106 | | friendRequestsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_REQUEST_TAB_INDEX)); |
| 1 | 107 | | closeButton.onClick.AddListener(() => |
| | 108 | | { |
| 0 | 109 | | OnClose?.Invoke(); |
| 0 | 110 | | Hide(); |
| 0 | 111 | | }); |
| | 112 | |
|
| 1 | 113 | | friendRequestsTab.Expand(); |
| 1 | 114 | | } |
| | 115 | |
|
| | 116 | | public void HideLoadingSpinner() |
| | 117 | | { |
| 0 | 118 | | loadingSpinner.SetActive(false); |
| 0 | 119 | | model.isLoadingSpinnerActive = false; |
| 0 | 120 | | } |
| | 121 | |
|
| | 122 | | public void ShowLoadingSpinner() |
| | 123 | | { |
| 1 | 124 | | loadingSpinner.SetActive(true); |
| 1 | 125 | | model.isLoadingSpinnerActive = true; |
| 1 | 126 | | } |
| | 127 | |
|
| | 128 | | public FriendEntryBase GetEntry(string userId) |
| | 129 | | { |
| 0 | 130 | | return (FriendEntryBase) friendsTab.Get(userId) ?? friendRequestsTab.Get(userId); |
| | 131 | | } |
| | 132 | |
|
| 0 | 133 | | public void DisplayFriendUserNotFound() => friendRequestsTab.ShowUserNotFoundNotification(); |
| | 134 | |
|
| | 135 | | public void Show() |
| | 136 | | { |
| 1 | 137 | | model.visible = true; |
| 1 | 138 | | gameObject.SetActive(true); |
| 1 | 139 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 1 | 140 | | } |
| | 141 | |
|
| | 142 | | public void Hide() |
| | 143 | | { |
| 0 | 144 | | model.visible = false; |
| 0 | 145 | | gameObject.SetActive(false); |
| 0 | 146 | | AudioScriptableObjects.dialogClose.Play(true); |
| 0 | 147 | | } |
| | 148 | |
|
| | 149 | | public void Set(string userId, FriendEntryModel model) |
| | 150 | | { |
| 0 | 151 | | friendRequestsTab.Remove(userId); |
| 0 | 152 | | friendsTab.Enqueue(userId, model); |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | public void Remove(string userId) |
| | 156 | | { |
| 0 | 157 | | friendRequestsTab.Remove(userId); |
| 0 | 158 | | friendsTab.Remove(userId); |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | public void Set(string userId, FriendRequestEntryModel model) |
| | 162 | | { |
| 0 | 163 | | friendRequestsTab.Enqueue(userId, model); |
| 0 | 164 | | friendsTab.Remove(userId); |
| 0 | 165 | | } |
| | 166 | |
|
| 1 | 167 | | public bool IsActive() => gameObject.activeInHierarchy; |
| | 168 | |
|
| | 169 | | public void ShowRequestSendError(FriendRequestError error) |
| | 170 | | { |
| | 171 | | switch (error) |
| | 172 | | { |
| | 173 | | case FriendRequestError.AlreadyFriends: |
| 0 | 174 | | friendRequestsTab.ShowAlreadyFriendsNotification(); |
| 0 | 175 | | break; |
| | 176 | | case FriendRequestError.UserNotFound: |
| 0 | 177 | | friendRequestsTab.ShowUserNotFoundNotification(); |
| | 178 | | break; |
| | 179 | | } |
| 0 | 180 | | } |
| | 181 | |
|
| | 182 | | public void ShowRequestSendSuccess() |
| | 183 | | { |
| 0 | 184 | | friendRequestsTab.ShowRequestSuccessfullySentNotification(); |
| 0 | 185 | | } |
| | 186 | |
|
| 0 | 187 | | public void ShowMoreFriendsToLoadHint(int hiddenCount) => friendsTab.ShowMoreFriendsToLoadHint(hiddenCount); |
| | 188 | |
|
| 1 | 189 | | public void HideMoreFriendsToLoadHint() => friendsTab.HideMoreFriendsToLoadHint(); |
| | 190 | |
|
| | 191 | | public void ShowMoreRequestsToLoadHint(int hiddenCount) => |
| 0 | 192 | | friendRequestsTab.ShowMoreEntriesToLoadHint(hiddenCount); |
| | 193 | |
|
| 1 | 194 | | public void HideMoreRequestsToLoadHint() => friendRequestsTab.HideMoreFriendsToLoadHint(); |
| | 195 | |
|
| 0 | 196 | | public bool ContainsFriend(string userId) => friendsTab.Get(userId) != null; |
| | 197 | |
|
| 0 | 198 | | public bool ContainsFriendRequest(string userId) => friendRequestsTab.Get(userId) != null; |
| | 199 | |
|
| 0 | 200 | | public void EnableSearchMode() => friendsTab.EnableSearchMode(); |
| | 201 | |
|
| 0 | 202 | | public void DisableSearchMode() => friendsTab.DisableSearchMode(); |
| | 203 | |
|
| | 204 | | public void UpdateBlockStatus(string userId, bool blocked) |
| | 205 | | { |
| 0 | 206 | | UpdateBlockStatus(blocked, friendsTab.Get(userId)); |
| 0 | 207 | | UpdateBlockStatus(blocked, friendRequestsTab.Get(userId)); |
| 0 | 208 | | } |
| | 209 | |
|
| | 210 | | public void ClearAll() |
| | 211 | | { |
| 1 | 212 | | friendsTab.Clear(); |
| 1 | 213 | | friendRequestsTab.Clear(); |
| 1 | 214 | | } |
| | 215 | |
|
| | 216 | | public override void RefreshControl() |
| | 217 | | { |
| 0 | 218 | | if (model.isLoadingSpinnerActive) |
| 0 | 219 | | ShowLoadingSpinner(); |
| | 220 | | else |
| 0 | 221 | | HideLoadingSpinner(); |
| | 222 | |
|
| 0 | 223 | | if (model.visible) |
| 0 | 224 | | Show(); |
| | 225 | | else |
| 0 | 226 | | Hide(); |
| | 227 | |
|
| 0 | 228 | | FocusTab(model.focusedTabIndex); |
| 0 | 229 | | } |
| | 230 | |
|
| | 231 | | internal void FocusTab(int index) |
| | 232 | | { |
| 0 | 233 | | model.focusedTabIndex = index; |
| | 234 | |
|
| 0 | 235 | | if (index == FRIENDS_LIST_TAB_INDEX) |
| | 236 | | { |
| 0 | 237 | | friendsTab.Show(); |
| 0 | 238 | | friendRequestsTab.Hide(); |
| 0 | 239 | | OnFriendListDisplayed?.Invoke(); |
| | 240 | | } |
| 0 | 241 | | else if (index == FRIENDS_REQUEST_TAB_INDEX) |
| | 242 | | { |
| 0 | 243 | | friendsTab.Hide(); |
| 0 | 244 | | friendRequestsTab.Show(); |
| 0 | 245 | | OnRequestListDisplayed?.Invoke(); |
| | 246 | | } |
| | 247 | | else |
| 0 | 248 | | throw new IndexOutOfRangeException(); |
| | 249 | | } |
| | 250 | |
|
| | 251 | | private void UpdateBlockStatus(bool blocked, FriendEntryBase friendEntry) |
| | 252 | | { |
| 0 | 253 | | if (friendEntry == null) return; |
| 0 | 254 | | var friendModel = friendEntry.Model; |
| 0 | 255 | | friendModel.blocked = blocked; |
| 0 | 256 | | friendEntry.RefreshControl(); |
| 0 | 257 | | } |
| | 258 | |
|
| | 259 | | [Serializable] |
| | 260 | | private struct Model |
| | 261 | | { |
| | 262 | | public int focusedTabIndex; |
| | 263 | | public bool isLoadingSpinnerActive; |
| | 264 | | public bool visible; |
| | 265 | | } |
| | 266 | | } |
| | 267 | | } |