| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | | using System; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | |
|
| | 8 | | public class ChatNotificationMessageComponentView : BaseComponentView, IChatNotificationMessageComponentView, IComponent |
| | 9 | | { |
| | 10 | | [Header("Prefab References")] |
| | 11 | | [SerializeField] internal Button button; |
| | 12 | | [SerializeField] internal TMP_Text notificationMessage; |
| | 13 | | [SerializeField] internal TMP_Text notificationHeader; |
| | 14 | | [SerializeField] internal TMP_Text notificationTimestamp; |
| | 15 | | [SerializeField] internal ImageComponentView image; |
| | 16 | | [SerializeField] internal bool isPrivate; |
| | 17 | |
|
| | 18 | | [Header("Configuration")] |
| | 19 | | [SerializeField] internal ChatNotificationMessageComponentModel model; |
| | 20 | |
|
| | 21 | | public event Action<string> OnClickedNotification; |
| | 22 | | public string notificationTargetId; |
| | 23 | | private int maxContentCharacters, maxHeaderCharacters; |
| | 24 | |
|
| | 25 | | public void Configure(ChatNotificationMessageComponentModel newModel) |
| | 26 | | { |
| 2 | 27 | | model = newModel; |
| 2 | 28 | | RefreshControl(); |
| 2 | 29 | | } |
| | 30 | |
|
| | 31 | | public override void Awake() |
| | 32 | | { |
| 10 | 33 | | base.Awake(); |
| | 34 | |
|
| 11 | 35 | | button?.onClick.AddListener(()=>OnClickedNotification.Invoke(notificationTargetId)); |
| 10 | 36 | | } |
| | 37 | |
|
| | 38 | | public override void RefreshControl() |
| | 39 | | { |
| 2 | 40 | | if (model == null) |
| 0 | 41 | | return; |
| | 42 | |
|
| 2 | 43 | | SetMaxContentCharacters(model.maxContentCharacters); |
| 2 | 44 | | SetMaxHeaderCharacters(model.maxHeaderCharacters); |
| 2 | 45 | | SetMessage(model.message); |
| 2 | 46 | | SetTimestamp(model.time); |
| 2 | 47 | | SetNotificationHeader(model.messageHeader); |
| 2 | 48 | | SetIsPrivate(model.isPrivate); |
| 2 | 49 | | SetImage(model.imageUri); |
| 2 | 50 | | } |
| | 51 | |
|
| | 52 | | public void SetMessage(string message) |
| | 53 | | { |
| 4 | 54 | | model.message = message; |
| 4 | 55 | | if (message.Length <= maxContentCharacters) |
| 1 | 56 | | notificationMessage.text = message; |
| | 57 | | else |
| 3 | 58 | | notificationMessage.text = $"{message.Substring(0, maxContentCharacters)}..."; |
| 3 | 59 | | } |
| | 60 | |
|
| | 61 | | public void SetTimestamp(string timestamp) |
| | 62 | | { |
| 3 | 63 | | model.time = timestamp; |
| 3 | 64 | | notificationTimestamp.text = timestamp; |
| 3 | 65 | | } |
| | 66 | |
|
| | 67 | | public void SetNotificationHeader(string header) |
| | 68 | | { |
| 4 | 69 | | model.messageHeader = header; |
| 4 | 70 | | if(header.Length <= maxHeaderCharacters) |
| 1 | 71 | | notificationHeader.text = header; |
| | 72 | | else |
| 3 | 73 | | notificationHeader.text = $"{header.Substring(0, maxHeaderCharacters)}..."; |
| 3 | 74 | | } |
| | 75 | |
|
| | 76 | | public void SetIsPrivate(bool isPrivate) |
| | 77 | | { |
| 4 | 78 | | model.isPrivate = isPrivate; |
| 4 | 79 | | this.isPrivate = isPrivate; |
| 4 | 80 | | image.gameObject.SetActive(isPrivate); |
| 4 | 81 | | } |
| | 82 | |
|
| | 83 | | public void SetImage(string uri) |
| | 84 | | { |
| 2 | 85 | | if (!isPrivate) |
| 1 | 86 | | return; |
| | 87 | |
|
| 1 | 88 | | model.imageUri = uri; |
| 1 | 89 | | image.SetImage(uri); |
| 1 | 90 | | } |
| | 91 | |
|
| | 92 | | public void SetMaxContentCharacters(int maxContentCharacters) |
| | 93 | | { |
| 4 | 94 | | model.maxContentCharacters = maxContentCharacters; |
| 4 | 95 | | this.maxContentCharacters = maxContentCharacters; |
| 4 | 96 | | } |
| | 97 | |
|
| | 98 | | public void SetMaxHeaderCharacters(int maxHeaderCharacters) |
| | 99 | | { |
| 4 | 100 | | model.maxHeaderCharacters = maxHeaderCharacters; |
| 4 | 101 | | this.maxHeaderCharacters = maxHeaderCharacters; |
| 4 | 102 | | } |
| | 103 | |
|
| | 104 | | public void SetNotificationTargetId(string notificationTargetId) |
| | 105 | | { |
| 0 | 106 | | model.notificationTargetId = notificationTargetId; |
| 0 | 107 | | this.notificationTargetId = notificationTargetId; |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | } |