| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using System.Globalization; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | public class FriendRequestEntry : FriendEntryBase |
| | 9 | | { |
| | 10 | | [SerializeField] internal TMP_Text bodyMessage; |
| | 11 | | [SerializeField] internal TMP_Text requestDate; |
| | 12 | | [SerializeField] internal GameObject shortcutButtonsContainer; |
| | 13 | | [SerializeField] internal Button acceptButton; |
| | 14 | | [SerializeField] internal Button rejectButton; |
| | 15 | | [SerializeField] internal Button cancelButton; |
| | 16 | | [SerializeField] internal Button openButton; |
| | 17 | |
|
| 36 | 18 | | public bool isReceived { get; private set; } |
| | 19 | |
|
| | 20 | | public event Action<FriendRequestEntry> OnAccepted; |
| | 21 | | public event Action<FriendRequestEntry> OnRejected; |
| | 22 | | public event Action<FriendRequestEntry> OnCancelled; |
| | 23 | | public event Action<FriendRequestEntry> OnOpened; |
| | 24 | |
|
| | 25 | | public override void Awake() |
| | 26 | | { |
| 17 | 27 | | base.Awake(); |
| | 28 | |
|
| 17 | 29 | | acceptButton.onClick.RemoveAllListeners(); |
| 17 | 30 | | rejectButton.onClick.RemoveAllListeners(); |
| 17 | 31 | | cancelButton.onClick.RemoveAllListeners(); |
| 18 | 32 | | acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this)); |
| 18 | 33 | | rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this)); |
| 18 | 34 | | cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this)); |
| 17 | 35 | | openButton.onClick.AddListener(() => OnOpened?.Invoke(this)); |
| 17 | 36 | | } |
| | 37 | |
|
| | 38 | | public void Populate(FriendRequestEntryModel model) |
| | 39 | | { |
| 12 | 40 | | base.Populate(model); |
| 12 | 41 | | SetBodyMessage(model.bodyMessage); |
| 12 | 42 | | SetRequestDate(model.timestamp); |
| 12 | 43 | | SetReceived(model.isReceived); |
| 12 | 44 | | SetShortcutButtonsActive(model.isShortcutButtonsActive); |
| 12 | 45 | | } |
| | 46 | |
|
| | 47 | | public override void Populate(FriendEntryModel model) |
| | 48 | | { |
| 0 | 49 | | base.Populate(model); |
| | 50 | |
|
| 0 | 51 | | if (model is FriendRequestEntryModel requestModel) |
| | 52 | | { |
| 0 | 53 | | SetBodyMessage(requestModel.bodyMessage); |
| 0 | 54 | | SetRequestDate(requestModel.timestamp); |
| 0 | 55 | | SetReceived(requestModel.isReceived); |
| 0 | 56 | | SetShortcutButtonsActive(requestModel.isShortcutButtonsActive); |
| | 57 | | } |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | private void SetBodyMessage(string value) |
| | 61 | | { |
| 12 | 62 | | if (bodyMessage == null) |
| 0 | 63 | | return; |
| | 64 | |
|
| 12 | 65 | | bodyMessage.text = value; |
| 12 | 66 | | bodyMessage.gameObject.SetActive(!string.IsNullOrEmpty(value)); |
| 12 | 67 | | } |
| | 68 | |
|
| | 69 | | private void SetRequestDate(long value) |
| | 70 | | { |
| 12 | 71 | | if (requestDate == null) |
| 0 | 72 | | return; |
| | 73 | |
|
| 12 | 74 | | requestDate.text = Utils.UnixToDateTimeWithTime((ulong)value).ToString("MMM dd", new CultureInfo("en-US")).ToUpp |
| 12 | 75 | | } |
| | 76 | |
|
| | 77 | | private void SetReceived(bool value) |
| | 78 | | { |
| 12 | 79 | | isReceived = value; |
| | 80 | |
|
| 12 | 81 | | if (isReceived) |
| 5 | 82 | | PopulateReceived(); |
| | 83 | | else |
| 7 | 84 | | PopulateSent(); |
| 7 | 85 | | } |
| | 86 | |
|
| | 87 | | private void PopulateReceived() |
| | 88 | | { |
| 5 | 89 | | isReceived = true; |
| 5 | 90 | | cancelButton.gameObject.SetActive(false); |
| 5 | 91 | | acceptButton.gameObject.SetActive(true); |
| 5 | 92 | | rejectButton.gameObject.SetActive(true); |
| 5 | 93 | | } |
| | 94 | |
|
| | 95 | | private void PopulateSent() |
| | 96 | | { |
| 7 | 97 | | isReceived = false; |
| 7 | 98 | | cancelButton.gameObject.SetActive(true); |
| 7 | 99 | | acceptButton.gameObject.SetActive(false); |
| 7 | 100 | | rejectButton.gameObject.SetActive(false); |
| 7 | 101 | | } |
| | 102 | |
|
| | 103 | | private void SetShortcutButtonsActive(bool isActive) |
| | 104 | | { |
| 12 | 105 | | if (shortcutButtonsContainer != null) |
| 12 | 106 | | shortcutButtonsContainer.SetActive(isActive); |
| | 107 | |
|
| 12 | 108 | | if (requestDate != null) |
| 12 | 109 | | requestDate.gameObject.SetActive(!isActive); |
| 12 | 110 | | } |
| | 111 | | } |