| | 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 ImageComponentView image; |
| | 21 | | [SerializeField] internal RectTransform backgroundTransform; |
| | 22 | | [SerializeField] internal RectTransform messageContainerTransform; |
| | 23 | | [SerializeField] internal GameObject receivedRequestMark; |
| | 24 | | [SerializeField] internal GameObject acceptedRequestMark; |
| 9 | 25 | | [SerializeField] internal bool shouldAnimateFocus = true; |
| | 26 | | [SerializeField] internal RectTransform header; |
| | 27 | | [SerializeField] internal RectTransform content; |
| | 28 | |
|
| | 29 | | [Header("Configuration")] |
| | 30 | | [SerializeField] internal FriendRequestNotificationComponentModel model; |
| | 31 | |
|
| | 32 | | public event Action<string> 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.UserId)); |
| 8 | 45 | | startingXPosition = messageContainerTransform.anchoredPosition.x; |
| 8 | 46 | | RefreshControl(); |
| 8 | 47 | | } |
| | 48 | |
|
| | 49 | | public override void Show(bool Instant = false) |
| | 50 | | { |
| 0 | 51 | | if (showHideAnimator != null) |
| 0 | 52 | | showHideAnimator.animSpeedFactor = 0.7f; |
| | 53 | |
|
| 0 | 54 | | base.Show(Instant); |
| 0 | 55 | | ForceUIRefresh(); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | public override void Hide(bool Instant = false) |
| | 59 | | { |
| 0 | 60 | | if (showHideAnimator != null) |
| 0 | 61 | | showHideAnimator.animSpeedFactor = 0.05f; |
| | 62 | |
|
| 0 | 63 | | base.Hide(Instant); |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | public override void OnFocus() |
| | 67 | | { |
| 0 | 68 | | base.OnFocus(); |
| 0 | 69 | | if (shouldAnimateFocus) |
| 0 | 70 | | messageContainerTransform.anchoredPosition = new Vector2(startingXPosition + 5, messageContainerTransfor |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | public override void OnLoseFocus() |
| | 74 | | { |
| 8 | 75 | | base.OnLoseFocus(); |
| 8 | 76 | | if (shouldAnimateFocus) |
| 8 | 77 | | messageContainerTransform.anchoredPosition = new Vector2(startingXPosition, messageContainerTransform.an |
| 8 | 78 | | } |
| | 79 | |
|
| | 80 | | public override void RefreshControl() |
| | 81 | | { |
| 9 | 82 | | if (model == null) |
| 0 | 83 | | return; |
| | 84 | |
|
| 9 | 85 | | SetUser(model.UserId, model.UserName); |
| 9 | 86 | | SetMessage(model.Message); |
| 9 | 87 | | SetTimestamp(model.Time); |
| 9 | 88 | | SetHeader(model.Header); |
| 9 | 89 | | SetImage(model.ImageUri); |
| 9 | 90 | | SetIsAccepted(model.IsAccepted); |
| 9 | 91 | | } |
| | 92 | |
|
| | 93 | | public void SetUser(string UserId, string UserName) |
| | 94 | | { |
| 10 | 95 | | model.UserId = UserId; |
| 10 | 96 | | model.UserName = UserName; |
| | 97 | |
|
| 10 | 98 | | notificationSender.text = UserName; |
| 10 | 99 | | ForceUIRefresh(); |
| 10 | 100 | | } |
| | 101 | |
|
| | 102 | | public void SetMessage(string Message) |
| | 103 | | { |
| 10 | 104 | | model.Message = Message; |
| 10 | 105 | | notificationMessage.text = Message; |
| 10 | 106 | | ForceUIRefresh(); |
| 10 | 107 | | } |
| | 108 | |
|
| | 109 | | public void SetTimestamp(string Timestamp) |
| | 110 | | { |
| 10 | 111 | | model.Time = Timestamp; |
| 10 | 112 | | notificationTimestamp.text = Timestamp; |
| 10 | 113 | | ForceUIRefresh(); |
| 10 | 114 | | } |
| | 115 | |
|
| | 116 | | public void SetHeader(string Header) |
| | 117 | | { |
| 10 | 118 | | model.Header = Header; |
| 10 | 119 | | notificationHeader.text = Header; |
| 10 | 120 | | ForceUIRefresh(); |
| 10 | 121 | | } |
| | 122 | |
|
| | 123 | | public void SetImage(string ImageUri) |
| | 124 | | { |
| 9 | 125 | | model.ImageUri = ImageUri; |
| 9 | 126 | | image.SetImage(ImageUri); |
| 9 | 127 | | } |
| | 128 | |
|
| | 129 | | public void SetIsAccepted(bool IsAccepted) |
| | 130 | | { |
| 11 | 131 | | model.IsAccepted = IsAccepted; |
| | 132 | |
|
| 11 | 133 | | if (receivedRequestMark != null) |
| 0 | 134 | | receivedRequestMark.SetActive(!IsAccepted); |
| | 135 | |
|
| 11 | 136 | | if (acceptedRequestMark != null) |
| 0 | 137 | | acceptedRequestMark.SetActive(IsAccepted); |
| 11 | 138 | | } |
| | 139 | |
|
| | 140 | | private void ForceUIRefresh() |
| | 141 | | { |
| 40 | 142 | | Utils.ForceRebuildLayoutImmediate(backgroundTransform); |
| 40 | 143 | | } |
| | 144 | | } |
| | 145 | | } |