| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Social.Chat.Channels |
| | 7 | | { |
| | 8 | | public class JoinChannelComponentView : BaseComponentView, IJoinChannelComponentView, IComponentModelConfig<JoinChan |
| | 9 | | { |
| | 10 | | internal const string MODAL_TITLE = "Do you want to join the channel {0}?"; |
| | 11 | |
|
| | 12 | | [Header("Prefab References")] |
| | 13 | | [SerializeField] internal Button backgroundButton; |
| | 14 | | [SerializeField] internal Button closeButton; |
| | 15 | | [SerializeField] internal TMP_Text titleText; |
| | 16 | | [SerializeField] internal ButtonComponentView cancelButton; |
| | 17 | | [SerializeField] internal ButtonComponentView confirmButton; |
| | 18 | | [SerializeField] internal GameObject loadingSpinnerContainer; |
| | 19 | |
|
| | 20 | | [Header("Configuration")] |
| | 21 | | [SerializeField] internal JoinChannelComponentModel model; |
| | 22 | |
|
| | 23 | | public event Action OnCancelJoin; |
| | 24 | | public event Action<string> OnConfirmJoin; |
| | 25 | |
|
| | 26 | | public override void Awake() |
| | 27 | | { |
| 4 | 28 | | base.Awake(); |
| | 29 | |
|
| 4 | 30 | | backgroundButton.onClick.AddListener(() => OnCancelJoin?.Invoke()); |
| 4 | 31 | | closeButton.onClick.AddListener(() => OnCancelJoin?.Invoke()); |
| 4 | 32 | | cancelButton.onClick.AddListener(() => OnCancelJoin?.Invoke()); |
| 4 | 33 | | confirmButton.onClick.AddListener(() => OnConfirmJoin?.Invoke(model.channelId)); |
| 4 | 34 | | } |
| | 35 | |
|
| | 36 | | public override void Dispose() |
| | 37 | | { |
| 8 | 38 | | backgroundButton.onClick.RemoveAllListeners(); |
| 8 | 39 | | closeButton.onClick.RemoveAllListeners(); |
| 8 | 40 | | cancelButton.onClick.RemoveAllListeners(); |
| 8 | 41 | | confirmButton.onClick.RemoveAllListeners(); |
| | 42 | |
|
| 8 | 43 | | base.Dispose(); |
| 8 | 44 | | } |
| | 45 | |
|
| | 46 | | public void Configure(JoinChannelComponentModel newModel) |
| | 47 | | { |
| 1 | 48 | | model = newModel; |
| 1 | 49 | | RefreshControl(); |
| 1 | 50 | | } |
| | 51 | |
|
| | 52 | | public override void RefreshControl() |
| | 53 | | { |
| 1 | 54 | | if (model == null) |
| 0 | 55 | | return; |
| | 56 | |
|
| 1 | 57 | | SetChannel(model.channelId); |
| | 58 | |
|
| 1 | 59 | | if (model.isLoading) |
| 0 | 60 | | ShowLoading(); |
| | 61 | | else |
| 1 | 62 | | HideLoading(); |
| 1 | 63 | | } |
| | 64 | |
|
| | 65 | | public void SetChannel(string channelName) |
| | 66 | | { |
| 2 | 67 | | model.channelId = channelName; |
| | 68 | |
|
| 2 | 69 | | if (titleText == null) |
| 0 | 70 | | return; |
| | 71 | |
|
| 2 | 72 | | titleText.text = string.Format(MODAL_TITLE, channelName); |
| 2 | 73 | | } |
| | 74 | |
|
| | 75 | | public void ShowLoading() |
| | 76 | | { |
| 1 | 77 | | model.isLoading = true; |
| 1 | 78 | | cancelButton.SetInteractable(false); |
| 1 | 79 | | confirmButton.SetInteractable(false); |
| 1 | 80 | | loadingSpinnerContainer.SetActive(true); |
| 1 | 81 | | } |
| | 82 | |
|
| | 83 | | public void HideLoading() |
| | 84 | | { |
| 2 | 85 | | model.isLoading = false; |
| 2 | 86 | | cancelButton.SetInteractable(true); |
| 2 | 87 | | confirmButton.SetInteractable(true); |
| 2 | 88 | | loadingSpinnerContainer.SetActive(false); |
| 2 | 89 | | } |
| | 90 | |
|
| | 91 | | internal static JoinChannelComponentView Create() |
| | 92 | | { |
| 4 | 93 | | JoinChannelComponentView joinChannelComponenView = Instantiate(Resources.Load<GameObject>("JoinChannelHUD")) |
| 4 | 94 | | joinChannelComponenView.name = "_JoinChannelHUD"; |
| | 95 | |
|
| 4 | 96 | | return joinChannelComponenView; |
| | 97 | | } |
| | 98 | | } |
| | 99 | | } |