| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace DCL.Chat.Notifications |
| | 8 | | { |
| | 9 | | public class FriendRequestNotificationComponentView : |
| | 10 | | BaseComponentView, |
| | 11 | | IComponentModelConfig<FriendRequestNotificationComponentModel>, |
| | 12 | | IShowableNotificationView |
| | 13 | | { |
| | 14 | | [Header("Prefab References")] |
| | 15 | | [SerializeField] internal Button button; |
| | 16 | | [SerializeField] internal TMP_Text notificationMessage; |
| | 17 | | [SerializeField] internal TMP_Text notificationHeader; |
| | 18 | | [SerializeField] internal TMP_Text notificationSender; |
| | 19 | | [SerializeField] internal TMP_Text notificationTimestamp; |
| | 20 | | [SerializeField] internal RectTransform backgroundTransform; |
| | 21 | | [SerializeField] internal RectTransform messageContainerTransform; |
| | 22 | | [SerializeField] internal GameObject receivedRequestMark; |
| | 23 | | [SerializeField] internal GameObject acceptedRequestMark; |
| 9 | 24 | | [SerializeField] internal bool shouldAnimateFocus = true; |
| | 25 | | [SerializeField] internal RectTransform header; |
| | 26 | | [SerializeField] internal RectTransform content; |
| | 27 | |
|
| | 28 | | [Header("Configuration")] |
| | 29 | | [SerializeField] internal FriendRequestNotificationComponentModel model; |
| | 30 | |
|
| | 31 | | public delegate void ClickedNotificationDelegate(string friendRequestId, string userId, bool isAccepted); |
| | 32 | | public event ClickedNotificationDelegate OnClickedNotification; |
| | 33 | | private float startingXPosition; |
| | 34 | |
|
| | 35 | | public void Configure(FriendRequestNotificationComponentModel newModel) |
| | 36 | | { |
| 1 | 37 | | model = newModel; |
| 1 | 38 | | RefreshControl(); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void Awake() |
| | 42 | | { |
| 8 | 43 | | base.Awake(); |
| 9 | 44 | | button?.onClick.AddListener(() => OnClickedNotification?.Invoke(model.FriendRequestId, model.UserId, model.I |
| | 45 | |
|
| 8 | 46 | | startingXPosition = messageContainerTransform.anchoredPosition.x; |
| 8 | 47 | | RefreshControl(); |
| 8 | 48 | | } |
| | 49 | |
|
| | 50 | | public override void Show(bool instant = false) |
| | 51 | | { |
| 0 | 52 | | if (showHideAnimator != null) |
| 0 | 53 | | showHideAnimator.animSpeedFactor = 0.7f; |
| | 54 | |
|
| 0 | 55 | | base.Show(instant); |
| 0 | 56 | | ForceUIRefresh(); |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | public override void Hide(bool instant = false) |
| | 60 | | { |
| 0 | 61 | | if (showHideAnimator != null) |
| 0 | 62 | | showHideAnimator.animSpeedFactor = 0.05f; |
| | 63 | |
|
| 0 | 64 | | base.Hide(instant); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | public override void OnFocus() |
| | 68 | | { |
| 0 | 69 | | base.OnFocus(); |
| 0 | 70 | | if (shouldAnimateFocus) |
| 0 | 71 | | messageContainerTransform.anchoredPosition = new Vector2(startingXPosition + 5, messageContainerTransfor |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public override void OnLoseFocus() |
| | 75 | | { |
| 8 | 76 | | base.OnLoseFocus(); |
| 8 | 77 | | if (shouldAnimateFocus) |
| 8 | 78 | | messageContainerTransform.anchoredPosition = new Vector2(startingXPosition, messageContainerTransform.an |
| 8 | 79 | | } |
| | 80 | |
|
| | 81 | | public override void RefreshControl() |
| | 82 | | { |
| 9 | 83 | | if (model == null) |
| 0 | 84 | | return; |
| | 85 | |
|
| 9 | 86 | | SetFriendRequestId(model.FriendRequestId); |
| 9 | 87 | | SetUser(model.UserId, model.UserName); |
| 9 | 88 | | SetMessage(model.Message); |
| 9 | 89 | | SetTimestamp(model.Time); |
| 9 | 90 | | SetHeader(model.Header); |
| 9 | 91 | | SetIsAccepted(model.IsAccepted); |
| 9 | 92 | | } |
| | 93 | |
|
| | 94 | | public void SetFriendRequestId(string friendRequestId) => |
| 9 | 95 | | model.FriendRequestId = friendRequestId; |
| | 96 | |
|
| | 97 | | public void SetUser(string userId, string userName) |
| | 98 | | { |
| 10 | 99 | | model.UserId = userId; |
| 10 | 100 | | model.UserName = userName; |
| | 101 | |
|
| 10 | 102 | | notificationSender.text = userName; |
| 10 | 103 | | ForceUIRefresh(); |
| 10 | 104 | | } |
| | 105 | |
|
| | 106 | | public void SetMessage(string message) |
| | 107 | | { |
| 10 | 108 | | model.Message = message; |
| 10 | 109 | | notificationMessage.text = message; |
| 10 | 110 | | ForceUIRefresh(); |
| 10 | 111 | | } |
| | 112 | |
|
| | 113 | | public void SetTimestamp(string timestamp) |
| | 114 | | { |
| 10 | 115 | | model.Time = timestamp; |
| 10 | 116 | | notificationTimestamp.text = timestamp; |
| 10 | 117 | | ForceUIRefresh(); |
| 10 | 118 | | } |
| | 119 | |
|
| | 120 | | public void SetHeader(string header) |
| | 121 | | { |
| 10 | 122 | | model.Header = header; |
| 10 | 123 | | notificationHeader.text = header; |
| 10 | 124 | | ForceUIRefresh(); |
| 10 | 125 | | } |
| | 126 | |
|
| | 127 | | public void SetIsAccepted(bool isAccepted) |
| | 128 | | { |
| 11 | 129 | | model.IsAccepted = isAccepted; |
| | 130 | |
|
| 11 | 131 | | if (receivedRequestMark != null) |
| 11 | 132 | | receivedRequestMark.SetActive(!isAccepted); |
| | 133 | |
|
| 11 | 134 | | if (acceptedRequestMark != null) |
| 11 | 135 | | acceptedRequestMark.SetActive(isAccepted); |
| 11 | 136 | | } |
| | 137 | |
|
| | 138 | | private void ForceUIRefresh() |
| | 139 | | { |
| 40 | 140 | | Utils.ForceRebuildLayoutImmediate(backgroundTransform); |
| 40 | 141 | | } |
| | 142 | | } |
| | 143 | | } |